[arcalive] extend 'gifs' option

use fallback URLs by default
This commit is contained in:
Mike Fährmann
2025-03-26 20:52:52 +01:00
parent 24bbcbcfa3
commit 6894e0bc70
3 changed files with 35 additions and 7 deletions

View File

@@ -1408,12 +1408,22 @@ Description
extractor.arcalive.gifs
-----------------------
Type
``bool``
* ``bool``
* ``string``
Default
``true``
Description
Check if ``.mp4`` videos have a ``.gif`` version
and download those instead.
Try to download ``.gif`` versions of ``.mp4`` videos.
``true`` | ``"fallback``
Use the ``.gif`` version as primary URL
and provide the ``.mp4`` one as
`fallback <extractor.*.fallback_>`__.
``"check"``
Check whether a ``.gif`` version is available
by sending an extra HEAD request.
``false``
Always download the ``.mp4`` version.
extractor.artstation.external

View File

@@ -41,7 +41,9 @@ class ArcalivePostExtractor(ArcaliveExtractor):
def items(self):
self.emoticons = self.config("emoticons", False)
self.gifs = self.config("gifs", True)
self.gifs = gifs = self.config("gifs", True)
if gifs:
self.gifs_fallback = (gifs != "check")
post = self.api.post(self.groups[0])
files = self._extract_files(post)
@@ -90,11 +92,15 @@ class ArcalivePostExtractor(ArcaliveExtractor):
url = path + "." + orig
elif video and self.gifs:
url_gif = url.rpartition(".")[0] + ".gif"
response = self.request(
url_gif + "?type=orig", method="HEAD", fatal=False)
if response.status_code < 400:
if self.gifs_fallback:
fallback = (url + "?type=orig",)
url = url_gif
else:
response = self.request(
url_gif + "?type=orig", method="HEAD", fatal=False)
if response.status_code < 400:
fallback = (url + "?type=orig",)
url = url_gif
files.append({
"url" : url + "?type=orig",

View File

@@ -88,6 +88,7 @@ __tests__ = (
"#url" : "https://arca.live/b/bluearchive/117240135",
"#comment": ".mp4 video",
"#class" : arcalive.ArcalivePostExtractor,
"#options": {"gifs": "check"},
"#urls" : "https://ac.namu.la/20240926sac/16f07778a97f91b935c8a3394ead01a223d96b2a619fdb25c4628ddba88b5fad.mp4?type=orig",
},
@@ -95,7 +96,18 @@ __tests__ = (
"#url" : "https://arca.live/b/bluearchive/111191955",
"#comment": "fake .mp4 GIF",
"#class" : arcalive.ArcalivePostExtractor,
"#options": {"gifs": True},
"#urls" : "https://ac.namu.la/20240714sac/c8fcadeb0b578e5121eb7a7e8fb05984cb87c68e7a6e0481a1c8869bf0ecfd2b.gif?type=orig",
"_fallback": ("https://ac.namu.la/20240714sac/c8fcadeb0b578e5121eb7a7e8fb05984cb87c68e7a6e0481a1c8869bf0ecfd2b.mp4?type=orig",),
},
{
"#url" : "https://arca.live/b/bluearchive/111191955",
"#comment": "fake .mp4 GIF",
"#class" : arcalive.ArcalivePostExtractor,
"#options": {"gifs": False},
"#urls" : "https://ac.namu.la/20240714sac/c8fcadeb0b578e5121eb7a7e8fb05984cb87c68e7a6e0481a1c8869bf0ecfd2b.mp4?type=orig",
},
{