From 34a4ddc3996b19cacea8c8c88a432ec9104a068b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 26 Jan 2024 17:56:08 +0100 Subject: [PATCH] [sankaku] add 'id-format' option (#5073) --- docs/configuration.rst | 13 +++++++++++++ gallery_dl/extractor/sankaku.py | 12 ++++++++---- test/results/sankaku.py | 10 +++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 6244437f01..304ddb4f93 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -3009,6 +3009,19 @@ Description restrict it to only one possible format. +extractor.sankaku.id-format +--------------------------- +Type + ``string`` +Default + ``"numeric"`` +Description + Format of ``id`` metadata fields. + + * ``"alphanumeric"`` or ``"alnum"``: 11-character alphanumeric IDs (``y0abGlDOr2o``) + * ``"numeric"`` or ``"legacy"``: numeric IDs (``360451``) + + extractor.sankaku.refresh ------------------------- Type diff --git a/gallery_dl/extractor/sankaku.py b/gallery_dl/extractor/sankaku.py index b3b7a9cc00..caf3e169dd 100644 --- a/gallery_dl/extractor/sankaku.py +++ b/gallery_dl/extractor/sankaku.py @@ -179,12 +179,16 @@ class SankakuAPI(): def __init__(self, extractor): self.extractor = extractor self.headers = { - "Accept" : "application/vnd.sankaku.api+json;v=2", - "Platform": "web-app", - "Origin" : extractor.root, + "Accept" : "application/vnd.sankaku.api+json;v=2", + "Platform" : "web-app", + "Api-Version": None, + "Origin" : extractor.root, } - self.username, self.password = self.extractor._get_auth_info() + if extractor.config("id-format") in ("alnum", "alphanumeric"): + self.headers["Api-Version"] = "2" + + self.username, self.password = extractor._get_auth_info() if not self.username: self.authenticate = util.noop diff --git a/test/results/sankaku.py b/test/results/sankaku.py index 361fd7a28d..cfdea0c4c0 100644 --- a/test/results/sankaku.py +++ b/test/results/sankaku.py @@ -119,11 +119,16 @@ { "#url" : "https://sankaku.app/posts/y0abGlDOr2o", + "#comment" : "extended tag categories; alphanumeric ID (#5073)", "#category": ("booru", "sankaku", "post"), "#class" : sankaku.SankakuPostExtractor, - "#options" : {"tags": True}, + "#options" : { + "tags" : True, + "id-format": "alphanumeric", + }, "#sha1_content": "5e255713cbf0a8e0801dc423563c34d896bb9229", + "id": "y0abGlDOr2o", "tags_artist": [ "bonocho", ], @@ -150,6 +155,8 @@ "#category": ("booru", "sankaku", "post"), "#class" : sankaku.SankakuPostExtractor, "#pattern" : r"https://s\.sankakucomplex\.com/data/ac/8e/ac8e3b92ea328ce9cf7211e69c905bf9\.jpg\?e=.+", + + "id": 360451, }, { @@ -169,6 +176,7 @@ "#options" : {"tags": True}, "#count" : 1, + "id" : 20758561, "tags" : list, "tags_general": [ "key(mangaka)",