[zerochan] download webp and gif files, add 'extensions' option (#6576)
This commit is contained in:
@@ -5190,6 +5190,22 @@ Description
|
|||||||
`youtube-dl's docstrings <https://github.com/ytdl-org/youtube-dl/blob/0153b387e57e0bb8e580f1869f85596d2767fb0d/youtube_dl/YoutubeDL.py#L157>`__
|
`youtube-dl's docstrings <https://github.com/ytdl-org/youtube-dl/blob/0153b387e57e0bb8e580f1869f85596d2767fb0d/youtube_dl/YoutubeDL.py#L157>`__
|
||||||
|
|
||||||
|
|
||||||
|
extractor.zerochan.extensions
|
||||||
|
-----------------------------
|
||||||
|
Type
|
||||||
|
* ``string``
|
||||||
|
* ``list`` of ``strings``
|
||||||
|
Default
|
||||||
|
``["jpg", "png", "webp", "gif"]``
|
||||||
|
Example
|
||||||
|
* ``"gif"``
|
||||||
|
* ``["webp", "gif", "jpg"}``
|
||||||
|
Description
|
||||||
|
List of filename extensions to try when dynamically building download URLs
|
||||||
|
(`"pagination": "api" <extractor.zerochan.pagination_>`__ +
|
||||||
|
`"metadata": false <extractor.zerochan.metadata_>`__)
|
||||||
|
|
||||||
|
|
||||||
extractor.zerochan.metadata
|
extractor.zerochan.metadata
|
||||||
---------------------------
|
---------------------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -145,6 +145,14 @@ class ZerochanTagExtractor(ZerochanExtractor):
|
|||||||
self.posts = self.posts_api
|
self.posts = self.posts_api
|
||||||
self.session.headers["User-Agent"] = util.USERAGENT
|
self.session.headers["User-Agent"] = util.USERAGENT
|
||||||
|
|
||||||
|
exts = self.config("extensions")
|
||||||
|
if exts:
|
||||||
|
if isinstance(exts, str):
|
||||||
|
exts = exts.split(",")
|
||||||
|
self.exts = exts
|
||||||
|
else:
|
||||||
|
self.exts = ("jpg", "png", "webp", "gif")
|
||||||
|
|
||||||
def metadata(self):
|
def metadata(self):
|
||||||
return {"search_tags": text.unquote(
|
return {"search_tags": text.unquote(
|
||||||
self.search_tag.replace("+", " "))}
|
self.search_tag.replace("+", " "))}
|
||||||
@@ -194,8 +202,6 @@ class ZerochanTagExtractor(ZerochanExtractor):
|
|||||||
"p" : self.page_start,
|
"p" : self.page_start,
|
||||||
}
|
}
|
||||||
|
|
||||||
static = "https://static.zerochan.net/.full."
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
response = self.request(url, params=params, allow_redirects=False)
|
response = self.request(url, params=params, allow_redirects=False)
|
||||||
|
|
||||||
@@ -221,15 +227,20 @@ class ZerochanTagExtractor(ZerochanExtractor):
|
|||||||
yield post
|
yield post
|
||||||
else:
|
else:
|
||||||
for post in posts:
|
for post in posts:
|
||||||
base = static + str(post["id"])
|
urls = self._urls(post)
|
||||||
post["file_url"] = base + ".jpg"
|
post["file_url"] = next(urls)
|
||||||
post["_fallback"] = (base + ".png",)
|
post["_fallback"] = urls
|
||||||
yield post
|
yield post
|
||||||
|
|
||||||
if not data.get("next"):
|
if not data.get("next"):
|
||||||
return
|
return
|
||||||
params["p"] += 1
|
params["p"] += 1
|
||||||
|
|
||||||
|
def _urls(self, post, static="https://static.zerochan.net/.full."):
|
||||||
|
base = static + str(post["id"]) + "."
|
||||||
|
for ext in self.exts:
|
||||||
|
yield base + ext
|
||||||
|
|
||||||
|
|
||||||
class ZerochanImageExtractor(ZerochanExtractor):
|
class ZerochanImageExtractor(ZerochanExtractor):
|
||||||
subcategory = "image"
|
subcategory = "image"
|
||||||
|
|||||||
Reference in New Issue
Block a user