From 7f1ed909d599cb01170c55045e89c7b80336b2ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 16 May 2024 01:05:53 +0200 Subject: [PATCH] [imgur] match gallery/album/image URLs with title slugs (#5593) --- gallery_dl/extractor/imgur.py | 6 +++--- test/results/imgur.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/gallery_dl/extractor/imgur.py b/gallery_dl/extractor/imgur.py index 86b1edd4..481fb1e3 100644 --- a/gallery_dl/extractor/imgur.py +++ b/gallery_dl/extractor/imgur.py @@ -68,7 +68,7 @@ class ImgurImageExtractor(ImgurExtractor): filename_fmt = "{category}_{id}{title:?_//}.{extension}" archive_fmt = "{id}" pattern = (BASE_PATTERN + r"/(?!gallery|search)" - r"(?:r/\w+/)?(\w{7}|\w{5})[sbtmlh]?") + r"(?:r/\w+/)?(?:[^/?#]+-)?(\w{7}|\w{5})[sbtmlh]?") example = "https://imgur.com/abcdefg" def items(self): @@ -93,7 +93,7 @@ class ImgurAlbumExtractor(ImgurExtractor): directory_fmt = ("{category}", "{album[id]}{album[title]:? - //}") filename_fmt = "{category}_{album[id]}_{num:>03}_{id}.{extension}" archive_fmt = "{album[id]}_{id}" - pattern = BASE_PATTERN + r"/a/(\w{7}|\w{5})" + pattern = BASE_PATTERN + r"/a/(?:[^/?#]+-)?(\w{7}|\w{5})" example = "https://imgur.com/a/abcde" def items(self): @@ -126,7 +126,7 @@ class ImgurAlbumExtractor(ImgurExtractor): class ImgurGalleryExtractor(ImgurExtractor): """Extractor for imgur galleries""" subcategory = "gallery" - pattern = BASE_PATTERN + r"/(?:gallery|t/\w+)/(\w{7}|\w{5})" + pattern = BASE_PATTERN + r"/(?:gallery|t/\w+)/(?:[^/?#]+-)?(\w{7}|\w{5})" example = "https://imgur.com/gallery/abcde" def items(self): diff --git a/test/results/imgur.py b/test/results/imgur.py index 36fb53c4..991cf546 100644 --- a/test/results/imgur.py +++ b/test/results/imgur.py @@ -86,6 +86,13 @@ __tests__ = ( "#exception": exception.HttpError, }, +{ + "#url" : "https://imgur.com/test-21yMxCS", + "#comment" : "slug", + "#category": ("", "imgur", "image"), + "#class" : imgur.ImgurImageExtractor, +}, + { "#url" : "https://m.imgur.com/r/Celebs/iHJ7tsM", "#category": ("", "imgur", "image"), @@ -258,6 +265,13 @@ __tests__ = ( "#exception": exception.HttpError, }, +{ + "#url" : "https://imgur.com/a/138-TcBmP", + "#comment" : "slug", + "#category": ("", "imgur", "album"), + "#class" : imgur.ImgurAlbumExtractor, +}, + { "#url" : "https://www.imgur.com/a/TcBmP", "#comment" : "www", @@ -294,6 +308,13 @@ __tests__ = ( "#exception": exception.HttpError, }, +{ + "#url" : "https://imgur.com/gallery/guy-gets-out-of-car-during-long-traffic-jam-to-pet-dog-zf2fIms", + "#comment" : "slug", + "#category": ("", "imgur", "gallery"), + "#class" : imgur.ImgurGalleryExtractor, +}, + { "#url" : "https://imgur.com/t/unmuted/26sEhNr", "#category": ("", "imgur", "gallery"),