| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# This program is free software; you can redistribute it and/or modify |
| 4 |
# it under the terms of the GNU General Public License version 2 as |
| 5 |
# published by the Free Software Foundation. |
| 6 |
|
| 7 |
"""Extractors for https://ww2.mangafreak.me/""" |
| 8 |
|
| 9 |
from .common import ChapterExtractor, MangaExtractor |
| 10 |
from .. import text |
| 11 |
|
| 12 |
BASE_PATTERN = r"(?:https?://)?(?:ww[\dw]\.)?mangafreak\.me" |
| 13 |
|
| 14 |
|
| 15 |
class MangafreakBase(): |
| 16 |
"""Base class for mangafreak extractors""" |
| 17 |
category = "mangafreak" |
| 18 |
root = "https://ww3.mangafreak.me" |
| 19 |
|
| 20 |
|
| 21 |
class MangafreakChapterExtractor(MangafreakBase, ChapterExtractor): |
| 22 |
"""Extractor for mangafreak manga chapters""" |
| 23 |
pattern = BASE_PATTERN + r"(/Read1_([^/?#]+)_((\d+)([a-z])?))" |
| 24 |
example = "https://ww2.mangafreak.me/Read1_Onepunch_Man_1" |
| 25 |
|
| 26 |
def metadata(self, page): |
| 27 |
manga = text.extr(page, "<title>Read ", " Chapter ") |
| 28 |
title = text.extr(page, 'selected="selected">', "<").partition(": ")[2] |
| 29 |
_, manga_slug, chapter_string, chapter, minor = self.groups |
| 30 |
|
| 31 |
return { |
| 32 |
"manga" : text.unescape(manga), |
| 33 |
"manga_slug" : manga_slug, |
| 34 |
"title" : text.unescape(title) if title else "", |
| 35 |
"chapter" : text.parse_int(chapter), |
| 36 |
"chapter_minor": "" if minor is None else minor, |
| 37 |
"chapter_string": chapter_string, |
| 38 |
"lang" : "en", |
| 39 |
"language" : "English", |
| 40 |
} |
| 41 |
|
| 42 |
def images(self, page): |
| 43 |
base = "https://images.mangafreak.me/mangas/" |
| 44 |
return [ |
| 45 |
(base + path, None) |
| 46 |
for path in text.extract_iter(page, 'src="' + base, '"') |
| 47 |
] |
| 48 |
|
| 49 |
|
| 50 |
class MangafreakMangaExtractor(MangafreakBase, MangaExtractor): |
| 51 |
"""Extractor for mangafreak manga series""" |
| 52 |
chapterclass = MangafreakChapterExtractor |
| 53 |
pattern = BASE_PATTERN + r"(/Manga/([^/?#]+))" |
| 54 |
example = "https://ww2.mangafreak.me/Manga/Onepunch_Man" |
| 55 |
reverse = False |
| 56 |
|
| 57 |
def chapters(self, page): |
| 58 |
table = text.extr(page, "<table>", "</table>") |
| 59 |
if not table: |
| 60 |
return () |
| 61 |
|
| 62 |
data = { |
| 63 |
"manga" : text.unescape(text.extr(page, "<title>", " Manga")), |
| 64 |
"manga_slug": self.groups[1], |
| 65 |
"lang" : "en", |
| 66 |
"language" : "English", |
| 67 |
} |
| 68 |
|
| 69 |
results = [] |
| 70 |
chapter_match = text.re(r"(\d+)(\w*)").match |
| 71 |
for row in text.extract_iter(table, "<tr>", "</tr>"): |
| 72 |
href = text.extr(row, ' href="', '"') |
| 73 |
if not href: |
| 74 |
continue |
| 75 |
url = self.root + href |
| 76 |
chapter_string = href.rpartition("_")[2] |
| 77 |
chapter, minor = chapter_match(chapter_string).groups() |
| 78 |
title = text.extr(row, '">', '<').partition(" - ")[2] |
| 79 |
results.append((url, { |
| 80 |
"chapter" : text.parse_int(chapter), |
| 81 |
"chapter_minor" : minor, |
| 82 |
"chapter_string": chapter_string, |
| 83 |
"title" : text.unescape(title) if title else "", |
| 84 |
**data, |
| 85 |
})) |
| 86 |
return results |