[twitter] add extractor for direct image links (closes #1417)
This commit is contained in:
@@ -676,7 +676,7 @@ Consider all sites to be NSFW unless otherwise known.
|
||||
<tr>
|
||||
<td>Twitter</td>
|
||||
<td>https://twitter.com/</td>
|
||||
<td>Bookmarks, Likes, Lists, List Members, Media Timelines, Search Results, Timelines, Tweets</td>
|
||||
<td>Bookmarks, individual Images, Likes, Lists, List Members, Media Timelines, Search Results, Timelines, Tweets</td>
|
||||
<td>Supported</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@@ -499,6 +499,34 @@ class TwitterTweetExtractor(TwitterExtractor):
|
||||
return TwitterAPI(self).tweet(self.tweet_id)
|
||||
|
||||
|
||||
class TwitterImageExtractor(Extractor):
|
||||
category = "twitter"
|
||||
subcategory = "image"
|
||||
pattern = r"https?://pbs\.twimg\.com/media/([\w-]+)(?:\?format=|\.)(\w+)"
|
||||
test = (
|
||||
("https://pbs.twimg.com/media/EqcpviCVoAAG-QG?format=jpg%name=orig"),
|
||||
("https://pbs.twimg.com/media/EqcpviCVoAAG-QG.jpg:orig"),
|
||||
)
|
||||
|
||||
def __init__(self, match):
|
||||
Extractor.__init__(self, match)
|
||||
self.id, self.fmt = match.groups()
|
||||
|
||||
def items(self):
|
||||
base = "https://pbs.twimg.com/media/" + self.id
|
||||
url = base + "." + self.fmt
|
||||
base += "?format=" + self.fmt + "&name="
|
||||
|
||||
data = {
|
||||
"filename": self.id,
|
||||
"extension": self.fmt,
|
||||
"_fallback": TwitterExtractor._image_fallback(base, url),
|
||||
}
|
||||
|
||||
yield Message.Directory, data
|
||||
yield Message.Url, base + "orig", data
|
||||
|
||||
|
||||
class TwitterAPI():
|
||||
|
||||
def __init__(self, extractor):
|
||||
|
||||
Reference in New Issue
Block a user