| 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://mangayi.com/""" |
| 8 |
|
| 9 |
from .common import ChapterExtractor, MangaExtractor |
| 10 |
from .. import text, util |
| 11 |
|
| 12 |
BASE_PATTERN = r"(?:https?://)?(?:www\.)?mangayi\.com" |
| 13 |
|
| 14 |
|
| 15 |
class MangayiBase(): |
| 16 |
"""Base class for mangayi.com extractors""" |
| 17 |
category = "mangayi" |
| 18 |
root = "https://mangayi.com" |
| 19 |
|
| 20 |
|
| 21 |
class MangayiChapterExtractor(MangayiBase, ChapterExtractor): |
| 22 |
"""Extractor for manga-chapters from mangayi.com""" |
| 23 |
pattern = BASE_PATTERN + r"(/read/[^/?#]+/(?:v(\d+)/)?chapter/\d+[^/?#]*)" |
| 24 |
example = "https://mangayi.com/read/TITLE/chapter/1/" |
| 25 |
|
| 26 |
def metadata(self, page): |
| 27 |
data = util.json_loads("{" + text.extr( |
| 28 |
page, '","@type":"ComicIssue",', '</script>')) |
| 29 |
chapter, dot, minor = data["issueNumber"].partition(".") |
| 30 |
|
| 31 |
return { |
| 32 |
"manga" : data["isPartOf"]["name"], |
| 33 |
"title" : data["name"].partition(":")[2].strip(), |
| 34 |
"volume" : text.parse_int(self.groups[1]), |
| 35 |
"chapter" : text.parse_int(chapter), |
| 36 |
"chapter_minor": dot + minor, |
| 37 |
"date" : self.parse_datetime_iso(data["datePublished"]), |
| 38 |
"lang" : data["inLanguage"], |
| 39 |
} |
| 40 |
|
| 41 |
def images(self, page): |
| 42 |
data = util.json_loads("{" + text.extr( |
| 43 |
page, '","@type":"MediaGallery",', '</script>')) |
| 44 |
|
| 45 |
return [ |
| 46 |
(text.ensure_http_scheme(image["url"]), None) |
| 47 |
for image in data["associatedMedia"] |
| 48 |
] |
| 49 |
|
| 50 |
|
| 51 |
class MangayiMangaExtractor(MangayiBase, MangaExtractor): |
| 52 |
chapterclass = MangayiChapterExtractor |
| 53 |
pattern = BASE_PATTERN + r"(/read/[^/?#]+)" |
| 54 |
example = "https://mangayi.com/read/TITLE/" |
| 55 |
|
| 56 |
def chapters(self, page): |
| 57 |
manga = util.json_loads("{" + text.extr( |
| 58 |
page, '","@type":"ComicSeries",', '</script>'))["name"] |
| 59 |
data = util.json_loads("{" + text.extr( |
| 60 |
page, '","@type":"ItemList",', '</script>')) |
| 61 |
|
| 62 |
results = [] |
| 63 |
for ch in data["itemListElement"]: |
| 64 |
url = ch["url"] |
| 65 |
chapter = url[url.rfind("/", 0, -2)+1:-1] |
| 66 |
chapter, sep, minor = chapter.partition("-") |
| 67 |
|
| 68 |
results.append((url, { |
| 69 |
"manga" : manga, |
| 70 |
"chapter" : text.parse_int(chapter), |
| 71 |
"chapter_minor": sep + minor, |
| 72 |
"title" : ch["name"].partition(":")[2].strip(), |
| 73 |
"lang" : "en", |
| 74 |
})) |
| 75 |
return results |