[twitter] fix extractor for direct image links (fixes #2030)
This commit is contained in:
parent
2076d40681
commit
ab8eea1a24
@ -41,7 +41,9 @@ class TwitterExtractor(Extractor):
|
|||||||
self.videos = self.config("videos", True)
|
self.videos = self.config("videos", True)
|
||||||
self.cards = self.config("cards", False)
|
self.cards = self.config("cards", False)
|
||||||
self._user_cache = {}
|
self._user_cache = {}
|
||||||
|
self._init_sizes()
|
||||||
|
|
||||||
|
def _init_sizes(self):
|
||||||
size = self.config("size")
|
size = self.config("size")
|
||||||
if size is None:
|
if size is None:
|
||||||
self._size_image = "orig"
|
self._size_image = "orig"
|
||||||
@ -580,13 +582,17 @@ class TwitterImageExtractor(Extractor):
|
|||||||
subcategory = "image"
|
subcategory = "image"
|
||||||
pattern = r"https?://pbs\.twimg\.com/media/([\w-]+)(?:\?format=|\.)(\w+)"
|
pattern = r"https?://pbs\.twimg\.com/media/([\w-]+)(?:\?format=|\.)(\w+)"
|
||||||
test = (
|
test = (
|
||||||
("https://pbs.twimg.com/media/EqcpviCVoAAG-QG?format=jpg%name=orig"),
|
("https://pbs.twimg.com/media/EqcpviCVoAAG-QG?format=jpg&name=orig", {
|
||||||
|
"options": (("size", "4096x4096,orig"),),
|
||||||
|
"url": "cb3042a6f6826923da98f0d2b66c427e9385114c",
|
||||||
|
}),
|
||||||
("https://pbs.twimg.com/media/EqcpviCVoAAG-QG.jpg:orig"),
|
("https://pbs.twimg.com/media/EqcpviCVoAAG-QG.jpg:orig"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
Extractor.__init__(self, match)
|
Extractor.__init__(self, match)
|
||||||
self.id, self.fmt = match.groups()
|
self.id, self.fmt = match.groups()
|
||||||
|
TwitterExtractor._init_sizes(self)
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
base = "https://pbs.twimg.com/media/{}?format={}&name=".format(
|
base = "https://pbs.twimg.com/media/{}?format={}&name=".format(
|
||||||
@ -595,11 +601,11 @@ class TwitterImageExtractor(Extractor):
|
|||||||
data = {
|
data = {
|
||||||
"filename": self.id,
|
"filename": self.id,
|
||||||
"extension": self.fmt,
|
"extension": self.fmt,
|
||||||
"_fallback": TwitterExtractor._image_fallback(base),
|
"_fallback": TwitterExtractor._image_fallback(self, base),
|
||||||
}
|
}
|
||||||
|
|
||||||
yield Message.Directory, data
|
yield Message.Directory, data
|
||||||
yield Message.Url, base + "orig", data
|
yield Message.Url, base + self._size_image, data
|
||||||
|
|
||||||
|
|
||||||
class TwitterAPI():
|
class TwitterAPI():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user