Skip to content

Commit

Permalink
[twitter] add 'quotes' extractor (mikf#5262)
Browse files Browse the repository at this point in the history
mikf#5262 (comment)

It's implemented as a search for 'quoted_tweet_id:…' on Twitter.
  • Loading branch information
mikf committed Mar 6, 2024
1 parent 790c0ff commit 40c0553
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/supportedsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ Consider all listed sites to potentially be NSFW.
<tr>
<td>Twitter</td>
<td>https://twitter.com/</td>
<td>Avatars, Backgrounds, Bookmarks, Communities, Events, Followed Users, Hashtags, individual Images, Likes, Lists, List Members, Media Timelines, Search Results, Timelines, Tweets, User Profiles</td>
<td>Avatars, Backgrounds, Bookmarks, Communities, Events, Followed Users, Hashtags, individual Images, Likes, Lists, List Members, Media Timelines, Quotes, Search Results, Timelines, Tweets, User Profiles</td>
<td>Supported</td>
</tr>
<tr>
Expand Down
16 changes: 14 additions & 2 deletions gallery_dl/extractor/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,9 +731,9 @@ def tweets(self):


class TwitterTweetExtractor(TwitterExtractor):
"""Extractor for images from individual tweets"""
"""Extractor for individual tweets"""
subcategory = "tweet"
pattern = BASE_PATTERN + r"/([^/?#]+|i/web)/status/(\d+)"
pattern = BASE_PATTERN + r"/([^/?#]+|i/web)/status/(\d+)/?$"
example = "https://twitter.com/USER/status/12345"

def __init__(self, match):
Expand Down Expand Up @@ -810,6 +810,18 @@ def _tweets_conversation(self, tweet_id):
return itertools.chain(buffer, tweets)


class TwitterQuotesExtractor(TwitterExtractor):
"""Extractor for quotes of a Tweet"""
subcategory = "quotes"
pattern = BASE_PATTERN + r"/(?:[^/?#]+|i/web)/status/(\d+)/quotes"
example = "https://twitter.com/USER/status/12345/quotes"

def items(self):
url = "{}/search?q=quoted_tweet_id:{}".format(self.root, self.user)
data = {"_extractor": TwitterSearchExtractor}
yield Message.Queue, url, data


class TwitterAvatarExtractor(TwitterExtractor):
subcategory = "avatar"
filename_fmt = "avatar {date}.{extension}"
Expand Down
10 changes: 9 additions & 1 deletion test/results/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
"#category": ("", "twitter", "hashtag"),
"#class" : twitter.TwitterHashtagExtractor,
"#pattern" : twitter.TwitterSearchExtractor.pattern,
"#sha1_url": "3571c3a53b7647ea35517041fdc17f77ec5b2cb9",
"#urls" : "https://twitter.com/search?q=%23nature",
},

{
Expand Down Expand Up @@ -537,6 +537,14 @@
"The analysis by Texas A&M University seems to contradict statements by state and federal regulators that air near the crash site is completely safe, despite residents complaining about rashes, breathing problems and other health effects." Your reaction.""",
},

{
"#url" : "https://twitter.com/playpokemon/status/1263832915173048321/quotes",
"#category": ("", "twitter", "quotes"),
"#class" : twitter.TwitterQuotesExtractor,
"#pattern" : twitter.TwitterSearchExtractor.pattern,
"#urls" : "https://twitter.com/search?q=quoted_tweet_id:1263832915173048321",
},

{
"#url" : "https://twitter.com/supernaturepics/photo",
"#category": ("", "twitter", "avatar"),
Expand Down

0 comments on commit 40c0553

Please sign in to comment.