| 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://www.mangatown.com/""" |
| 8 |
|
| 9 |
from .common import ChapterExtractor, MangaExtractor |
| 10 |
from .. import text |
| 11 |
|
| 12 |
BASE_PATTERN = r"(?:https?://)?(?:www\.)?mangatown\.com" |
| 13 |
|
| 14 |
|
| 15 |
class MangatownBase(): |
| 16 |
"""Base class for mangatown extractors""" |
| 17 |
category = "mangatown" |
| 18 |
root = "https://www.mangatown.com" |
| 19 |
|
| 20 |
|
| 21 |
class MangatownChapterExtractor(MangatownBase, ChapterExtractor): |
| 22 |
"""Extractor for manga-chapters from mangatown.com""" |
| 23 |
pattern = BASE_PATTERN + r"(/manga/[^/?#]+(?:/v0*(\d+))?/c(\d+[^/?#]*))" |
| 24 |
example = "https://www.mangatown.com/manga/TITLE/c001/1.html" |
| 25 |
|
| 26 |
def __init__(self, match): |
| 27 |
self.part, self.volume, self.chapter = match.groups() |
| 28 |
self.base = f"{self.root}{self.part}/" |
| 29 |
ChapterExtractor.__init__(self, match, self.base + "1.html") |
| 30 |
|
| 31 |
def metadata(self, page): |
| 32 |
manga, pos = text.extract( |
| 33 |
page, 'property="og:title" content="', '"') |
| 34 |
count , pos = text.extract(page, "total_pages = ", ";", pos) |
| 35 |
manga_id , pos = text.extract(page, "series_id=", ";", pos) |
| 36 |
chapter_id, pos = text.extract(page, "chapter_id=", ";", pos) |
| 37 |
|
| 38 |
chapter, dot, minor = self.chapter.partition(".") |
| 39 |
|
| 40 |
return { |
| 41 |
"manga" : text.unescape(manga), |
| 42 |
"manga_id": text.parse_int(manga_id), |
| 43 |
"volume" : text.parse_int(self.volume), |
| 44 |
"chapter" : text.parse_int(chapter), |
| 45 |
"chapter_minor": dot + minor, |
| 46 |
"chapter_id": text.parse_int(chapter_id), |
| 47 |
"count" : text.parse_int(count), |
| 48 |
"lang" : "en", |
| 49 |
"language": "English", |
| 50 |
} |
| 51 |
|
| 52 |
def images(self, page): |
| 53 |
pnum = 1 |
| 54 |
|
| 55 |
while True: |
| 56 |
url = (text.extr(page, 'id="image" src="', '"') or |
| 57 |
text.extr(page, '<img src="', '"')) |
| 58 |
if not url: |
| 59 |
return |
| 60 |
yield text.ensure_http_scheme(url), None |
| 61 |
pnum += 1 |
| 62 |
page = self.request(f"{self.base}{pnum}.html").text |
| 63 |
|
| 64 |
|
| 65 |
class MangatownMangaExtractor(MangatownBase, MangaExtractor): |
| 66 |
"""Extractor for manga from mangatown.com""" |
| 67 |
chapterclass = MangatownChapterExtractor |
| 68 |
pattern = BASE_PATTERN + r"(/manga/[^/?#]+)" |
| 69 |
example = "https://www.mangatown.com/manga/TITLE" |
| 70 |
|
| 71 |
def chapters(self, page): |
| 72 |
results = [] |
| 73 |
|
| 74 |
manga, pos = text.extract(page, '<title>', '</title>') |
| 75 |
manga = manga.partition(" Manga")[0].replace("Read ", "", 1) |
| 76 |
manga = text.unescape(manga) |
| 77 |
|
| 78 |
page = text.extract(page, 'class="chapter_list"', '</ul>', pos)[0] |
| 79 |
for ch in text.extract_iter(page, "<li>", "</li>"): |
| 80 |
path , pos = text.extract(ch, '<a href="', '"') |
| 81 |
title, pos = text.extract(ch, "<span>", "<", pos) |
| 82 |
date , pos = text.extract(ch, 'class="time">', "<", pos) |
| 83 |
|
| 84 |
chapter = text.extr(path, "/c", "/") |
| 85 |
chapter, sep, minor = chapter.partition(".") |
| 86 |
|
| 87 |
results.append((self.root + path, { |
| 88 |
"manga" : manga, |
| 89 |
"chapter" : text.parse_int(chapter), |
| 90 |
"chapter_minor": sep + minor, |
| 91 |
"title" : "" if title is None else text.unescape(title), |
| 92 |
"date" : date, |
| 93 |
"lang" : "en", |
| 94 |
"language": "English", |
| 95 |
})) |
| 96 |
return results |