aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/urlshortener.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/extractor/urlshortener.py')
-rw-r--r--gallery_dl/extractor/urlshortener.py20
1 files changed, 6 insertions, 14 deletions
diff --git a/gallery_dl/extractor/urlshortener.py b/gallery_dl/extractor/urlshortener.py
index 49a3deb..0478ef0 100644
--- a/gallery_dl/extractor/urlshortener.py
+++ b/gallery_dl/extractor/urlshortener.py
@@ -32,21 +32,13 @@ BASE_PATTERN = UrlshortenerExtractor.update({
class UrlshortenerLinkExtractor(UrlshortenerExtractor):
"""Extractor for general-purpose URL shorteners"""
subcategory = "link"
- pattern = BASE_PATTERN + r"/([^/?#]+)"
+ pattern = BASE_PATTERN + r"(/[^/?#]+)"
example = "https://bit.ly/abcde"
- def __init__(self, match):
- UrlshortenerExtractor.__init__(self, match)
- self.id = match.group(match.lastindex)
-
- def _init(self):
- self.headers = self.config_instance("headers")
-
def items(self):
- response = self.request(
- "{}/{}".format(self.root, self.id), headers=self.headers,
- method="HEAD", allow_redirects=False, notfound="URL")
- try:
- yield Message.Queue, response.headers["location"], {}
- except KeyError:
+ url = self.root + self.groups[-1]
+ location = self.request_location(
+ url, headers=self.config_instance("headers"), notfound="URL")
+ if not location:
raise exception.StopExtraction("Unable to resolve short URL")
+ yield Message.Queue, location, {}