mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-23 19:22:32 +01:00
a14b72be21
* [webtoons] Use swebtoon-phinf.pstatic.net instead of webtoon-phinf.pstatic.net This trick to avoid having to set a Referer header comes from Webtoon's RSS feeds. The two URLs below are equivalent in content: https://webtoon-phinf.pstatic.net/20210929_153/1632867980912DmcGK_JPEG/16328679808882705182.jpg?type=q90 https://swebtoon-phinf.pstatic.net/20210929_153/1632867980912DmcGK_JPEG/16328679808882705182.jpg?type=q90 The URL with the domain "webtoon-phinf.pstatic.net" needs a Referer header, and the domain "swebtoon-phinf.pstatic.net" does not. This is because of the environment "swebtoon" images live in, one without explicit network control: RSS feeds on sites such as Feedly. This change should make it easier for gallery-dl developers to embed Webtoon comics without worrying about headers.
161 lines
5.3 KiB
Python
161 lines
5.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright 2020 Leonardo Taccari
|
|
#
|
|
# 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://www.webtoons.com/"""
|
|
|
|
from .common import GalleryExtractor, Extractor, Message
|
|
from .. import exception, text, util
|
|
|
|
BASE_PATTERN = r"(?:https?://)?(?:www\.)?webtoons\.com/(([^/?#]+)"
|
|
|
|
|
|
class WebtoonsBase():
|
|
category = "webtoons"
|
|
root = "https://www.webtoons.com"
|
|
cookiedomain = ".webtoons.com"
|
|
|
|
def setup_agegate_cookies(self):
|
|
self._update_cookies({
|
|
"atGDPR" : "AD_CONSENT",
|
|
"needCCPA" : "false",
|
|
"needCOPPA" : "false",
|
|
"needGDPR" : "false",
|
|
"pagGDPR" : "true",
|
|
"ageGatePass": "true",
|
|
})
|
|
|
|
def request(self, url, **kwargs):
|
|
response = Extractor.request(self, url, **kwargs)
|
|
if response.history and "/ageGate" in response.url:
|
|
raise exception.StopExtraction(
|
|
"HTTP redirect to age gate check ('%s')", response.request.url)
|
|
return response
|
|
|
|
|
|
class WebtoonsEpisodeExtractor(WebtoonsBase, GalleryExtractor):
|
|
"""Extractor for an episode on webtoons.com"""
|
|
subcategory = "episode"
|
|
directory_fmt = ("{category}", "{comic}")
|
|
filename_fmt = "{episode}-{num:>02}.{extension}"
|
|
archive_fmt = "{title_no}_{episode}_{num}"
|
|
pattern = (BASE_PATTERN + r"/([^/?#]+)/([^/?#]+)/(?:[^/?#]+))"
|
|
r"/viewer(?:\?([^#'\"]+))")
|
|
test = (
|
|
(("https://www.webtoons.com/en/comedy/safely-endangered"
|
|
"/ep-572-earth/viewer?title_no=352&episode_no=572"), {
|
|
"url": "55bec5d7c42aba19e3d0d56db25fdf0b0b13be38",
|
|
"content": ("1748c7e82b6db910fa179f6dc7c4281b0f680fa7",
|
|
"42055e44659f6ffc410b3fb6557346dfbb993df3",
|
|
"49e1f2def04c6f7a6a3dacf245a1cd9abe77a6a9"),
|
|
"count": 5,
|
|
}),
|
|
)
|
|
|
|
def __init__(self, match):
|
|
self.path, self.lang, self.genre, self.comic, query = match.groups()
|
|
|
|
url = "{}/{}/viewer?{}".format(self.root, self.path, query)
|
|
GalleryExtractor.__init__(self, match, url)
|
|
self.setup_agegate_cookies()
|
|
|
|
query = text.parse_query(query)
|
|
self.title_no = query.get("title_no")
|
|
self.episode = query.get("episode_no")
|
|
|
|
def metadata(self, page):
|
|
title, pos = text.extract(
|
|
page, '<meta property="og:title" content="', '"')
|
|
descr, pos = text.extract(
|
|
page, '<meta property="og:description" content="', '"', pos)
|
|
|
|
return {
|
|
"genre" : self.genre,
|
|
"comic" : self.comic,
|
|
"title_no" : self.title_no,
|
|
"episode" : self.episode,
|
|
"title" : text.unescape(title),
|
|
"description": text.unescape(descr),
|
|
"lang" : self.lang,
|
|
"language" : util.code_to_language(self.lang),
|
|
}
|
|
|
|
@staticmethod
|
|
def images(page):
|
|
return [
|
|
(url.replace("://webtoon-phinf.", "://swebtoon-phinf."), None)
|
|
for url in text.extract_iter(
|
|
page, 'class="_images" data-url="', '"')
|
|
]
|
|
|
|
|
|
class WebtoonsComicExtractor(WebtoonsBase, Extractor):
|
|
"""Extractor for an entire comic on webtoons.com"""
|
|
subcategory = "comic"
|
|
categorytransfer = True
|
|
pattern = (BASE_PATTERN + r"/([^/?#]+)/([^/?#]+))"
|
|
r"/list(?:\?([^#]+))")
|
|
test = (
|
|
# english
|
|
(("https://www.webtoons.com/en/comedy/live-with-yourself/"
|
|
"list?title_no=919"), {
|
|
"pattern": WebtoonsEpisodeExtractor.pattern,
|
|
"range": "1-15",
|
|
"count": ">= 15",
|
|
}),
|
|
# french
|
|
(("https://www.webtoons.com/fr/romance/subzero/"
|
|
"list?title_no=1845&page=3"), {
|
|
"count": ">= 15",
|
|
}),
|
|
# (#820)
|
|
(("https://www.webtoons.com/en/challenge/scoob-and-shag/"
|
|
"list?title_no=210827&page=9"), {
|
|
"count": ">= 18",
|
|
}),
|
|
# (#1643)
|
|
("https://www.webtoons.com/es/romance/lore-olympus/"
|
|
"list?title_no=1725"),
|
|
)
|
|
|
|
def __init__(self, match):
|
|
Extractor.__init__(self, match)
|
|
self.setup_agegate_cookies()
|
|
|
|
self.path, self.lang, self.genre, self.comic, query = match.groups()
|
|
query = text.parse_query(query)
|
|
self.title_no = query.get("title_no")
|
|
self.page_no = text.parse_int(query.get("page"), 1)
|
|
|
|
def items(self):
|
|
page = None
|
|
data = {"_extractor": WebtoonsEpisodeExtractor}
|
|
|
|
while True:
|
|
path = "/{}/list?title_no={}&page={}".format(
|
|
self.path, self.title_no, self.page_no)
|
|
|
|
if page and path not in page:
|
|
return
|
|
|
|
page = self.request(self.root + path).text
|
|
data["page"] = self.page_no
|
|
|
|
for url in self.get_episode_urls(page):
|
|
yield Message.Queue, url, data
|
|
|
|
self.page_no += 1
|
|
|
|
@staticmethod
|
|
def get_episode_urls(page):
|
|
"""Extract and return all episode urls in 'page'"""
|
|
page = text.extract(page, 'id="_listUl"', '</ul>')[0]
|
|
return [
|
|
match.group(0)
|
|
for match in WebtoonsEpisodeExtractor.pattern.finditer(page)
|
|
]
|