Debian Codegraph @

gallery_dl/extractor/mangafreak.py

raw symbols SCIP
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://ww2.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
56 def chapters(self, page):
57 table = text.extr(page, "<table>", "</table>")
58 if not table:
59 return ()
60
61 data = {
62 "manga" : text.unescape(text.extr(page, "<title>", " Manga")),
63 "manga_slug": self.groups[1],
64 "lang" : "en",
65 "language" : "English",
66 }
67
68 results = []
69 chapter_match = text.re(r"(\d+)(\w*)").match
70 for row in text.extract_iter(table, "<tr>", "</tr>"):
71 href = text.extr(row, '<a href="', '"')
72 if not href:
73 continue
74 url = self.root + href
75 chapter_string = href.rpartition("_")[2]
76 chapter, minor = chapter_match(chapter_string).groups()
77 title = text.extr(row, '">', '<').partition(" - ")[2]
78 results.append((url, {
79 "chapter" : text.parse_int(chapter),
80 "chapter_minor" : minor,
81 "chapter_string": chapter_string,
82 "title" : text.unescape(title) if title else "",
83 **data,
84 }))
85 return results