aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/tcbscans.py
blob: b5a730a4bb2083b24a153f42f6d18c8116263a8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: utf-8 -*-

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

"""Extractors for https://tcbscans.com/"""

from .common import ChapterExtractor, MangaExtractor
from .. import text

BASE_PATTERN = r"(?:https?://)?(?:tcbscans|onepiecechapters)\.com"


class TcbscansChapterExtractor(ChapterExtractor):
    category = "tcbscans"
    root = "https://tcbscans.com"
    pattern = BASE_PATTERN + r"(/chapters/\d+/[^/?#]+)"
    test = (
        (("https://tcbscans.com"
          "/chapters/4708/chainsaw-man-chapter-108"), {
            "pattern": (r"https://cdn\.[^/]+"
                        r"/(file|attachments/[^/]+)/[^/]+/[^.]+\.\w+"),
            "count"  : 17,
            "keyword": {
                "manga": "Chainsaw Man",
                "chapter": 108,
                "chapter_minor": "",
                "lang": "en",
                "language": "English",
            },
        }),
        ("https://onepiecechapters.com/chapters/4716/one-piece-chapter-1065", {
            "pattern": (r"https://cdn\.[^/]+"
                        r"/(file|attachments/[^/]+)/[^/]+/[^.]+\.\w+"),
            "count"  : 18,
            "keyword": {
                "manga": "One Piece",
                "chapter": 1065,
                "chapter_minor": "",
                "lang": "en",
                "language": "English",
            },
        }),
        (("https://onepiecechapters.com/"
          "chapters/44/ace-novel-manga-adaptation-chapter-1")),
    )

    def images(self, page):
        return [
            (url, None)
            for url in text.extract_iter(
                page, '<img class="fixed-ratio-content" src="', '"')
        ]

    def metadata(self, page):
        manga, _, chapter = text.extr(
            page, 'font-bold mt-8">', "</h1>").rpartition(" - Chapter ")
        chapter, sep, minor = chapter.partition(".")
        return {
            "manga": text.unescape(manga),
            "chapter": text.parse_int(chapter),
            "chapter_minor": sep + minor,
            "lang": "en", "language": "English",
        }


class TcbscansMangaExtractor(MangaExtractor):
    category = "tcbscans"
    root = "https://tcbscans.com"
    chapterclass = TcbscansChapterExtractor
    pattern = BASE_PATTERN + r"(/mangas/\d+/[^/?#]+)"
    test = (
        ("https://tcbscans.com/mangas/13/chainsaw-man", {
            "pattern": TcbscansChapterExtractor.pattern,
            "range"  : "1-50",
            "count"  : 50,
        }),
        ("https://onepiecechapters.com/mangas/4/jujutsu-kaisen", {
            "pattern": TcbscansChapterExtractor.pattern,
            "range"  : "1-50",
            "count"  : 50,
        }),
        ("https://onepiecechapters.com/mangas/15/hunter-x-hunter"),
    )

    def chapters(self, page):
        data = {
            "manga": text.unescape(text.extr(
                page, 'class="my-3 font-bold text-3xl">', "</h1>")),
            "lang": "en", "language": "English",
        }

        results = []
        page = text.extr(page, 'class="col-span-2"', 'class="order-1')
        for chapter in text.extract_iter(page, "<a", "</a>"):
            url = text.extr(chapter, 'href="', '"')
            data["title"] = text.unescape(text.extr(
                chapter, 'text-gray-500">', "</div>"))
            chapter = text.extr(
                chapter, 'font-bold">', "</div>").rpartition(" Chapter ")[2]
            chapter, sep, minor = chapter.partition(".")
            data["chapter"] = text.parse_int(chapter)
            data["chapter_minor"] = sep + minor
            results.append((self.root + url, data.copy()))
        return results