1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-25 04:02:32 +01:00

[sankaku] implement 'refresh' option (#2958)

This commit is contained in:
Mike Fährmann 2022-09-30 19:55:48 +02:00
parent 779e75c6f8
commit 4089bceddd
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 49 additions and 6 deletions

View File

@ -2172,6 +2172,16 @@ Description
restrict it to only one possible format.
extractor.sankaku.refresh
-------------------------
Type
``bool``
Default
``false``
Description
Refresh download URLs before they expire.
extractor.sankakucomplex.embeds
-------------------------------
Type

View File

@ -245,16 +245,17 @@
{
"format": ["hd", "sd", "gif"]
},
"sankaku":
{
"username": null,
"password": null,
"refresh": false
},
"sankakucomplex":
{
"embeds": false,
"videos": true
},
"sankaku":
{
"username": null,
"password": null
},
"skeb":
{
"article": false,

View File

@ -281,9 +281,41 @@ class SankakuAPI():
params["lang"] = "en"
params["limit"] = str(self.extractor.per_page)
refresh = self.extractor.config("refresh", False)
if refresh:
offset = expires = 0
from time import time
while True:
data = self._call(endpoint, params)
yield from data["data"]
if refresh:
posts = data["data"]
if offset:
posts = util.advance(posts, offset)
for post in posts:
if not expires:
url = post["file_url"]
if url:
expires = text.parse_int(
text.extract(url, "e=", "&")[0]) - 60
if 0 < expires <= time():
self.extractor.log.debug("Refreshing download URLs")
expires = None
break
offset += 1
yield post
if expires is None:
expires = 0
continue
offset = expires = 0
else:
yield from data["data"]
params["next"] = data["meta"]["next"]
if not params["next"]: