[twitter] add extractor for liked tweets (closes #837)

You need to be logged in to get access to anyone's liked tweets,
it seems.
pull/866/head
Mike Fährmann 4 years ago
parent b94394104c
commit c37a1c06c8
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -160,6 +160,6 @@ Turboimagehost https://www.turboimagehost.com/ individual Images
.. |pixiv-C| replace:: Favorites, Follows, pixiv.me Links, Rankings, Search Results, User Profiles, individual Images .. |pixiv-C| replace:: Favorites, Follows, pixiv.me Links, Rankings, Search Results, User Profiles, individual Images
.. |reddit-C| replace:: individual Images, Submissions, Subreddits, User Profiles .. |reddit-C| replace:: individual Images, Submissions, Subreddits, User Profiles
.. |smugmug-C| replace:: Albums, individual Images, Images from Users and Folders .. |smugmug-C| replace:: Albums, individual Images, Images from Users and Folders
.. |twitter-C| replace:: Bookmarks, Media Timelines, Search Results, Timelines, Tweets .. |twitter-C| replace:: Bookmarks, Likes, Media Timelines, Search Results, Timelines, Tweets
.. |wallhaven-A| replace:: Optional (`API Key <configuration.rst#extractorwallhavenapi-key>`__) .. |wallhaven-A| replace:: Optional (`API Key <configuration.rst#extractorwallhavenapi-key>`__)
.. |yuki-S| replace:: yuki.la 4chan archive .. |yuki-S| replace:: yuki.la 4chan archive

@ -264,6 +264,27 @@ class TwitterMediaExtractor(TwitterExtractor):
return TwitterAPI(self).timeline_media(self.user) return TwitterAPI(self).timeline_media(self.user)
class TwitterLikesExtractor(TwitterExtractor):
"""Extractor for liked tweets"""
subcategory = "likes"
pattern = (r"(?:https?://)?(?:www\.|mobile\.)?twitter\.com"
r"/(?!search)([^/?&#]+)/likes(?!\w)")
test = ("https://twitter.com/supernaturepics/likes",)
def tweets(self):
return TwitterAPI(self).timeline_favorites(self.user)
class TwitterBookmarkExtractor(TwitterExtractor):
"""Extractor for bookmarked tweets"""
subcategory = "bookmark"
pattern = r"(?:https?://)?(?:www\.|mobile\.)?twitter\.com/i/bookmarks()"
test = ("https://twitter.com/i/bookmarks",)
def tweets(self):
return TwitterAPI(self).timeline_bookmark()
class TwitterSearchExtractor(TwitterExtractor): class TwitterSearchExtractor(TwitterExtractor):
"""Extractor for all images from a search timeline""" """Extractor for all images from a search timeline"""
subcategory = "search" subcategory = "search"
@ -344,16 +365,6 @@ class TwitterTweetExtractor(TwitterExtractor):
return TwitterAPI(self).tweet(self.tweet_id) return TwitterAPI(self).tweet(self.tweet_id)
class TwitterBookmarkExtractor(TwitterExtractor):
"""Extractor for bookmarked tweets"""
subcategory = "bookmark"
pattern = r"(?:https?://)?(?:www\.|mobile\.)?twitter\.com/i/bookmarks()"
test = ("https://twitter.com/i/bookmarks",)
def tweets(self):
return TwitterAPI(self).bookmarks()
class TwitterAPI(): class TwitterAPI():
def __init__(self, extractor): def __init__(self, extractor):
@ -430,6 +441,15 @@ class TwitterAPI():
endpoint = "2/timeline/media/{}.json".format(user["rest_id"]) endpoint = "2/timeline/media/{}.json".format(user["rest_id"])
return self._pagination(endpoint) return self._pagination(endpoint)
def timeline_favorites(self, screen_name):
user = self.user_by_screen_name(screen_name)
endpoint = "2/timeline/favorites/{}.json".format(user["rest_id"])
return self._pagination(endpoint)
def timeline_bookmark(self):
endpoint = "2/timeline/bookmark.json"
return self._pagination(endpoint)
def search(self, query): def search(self, query):
endpoint = "2/search/adaptive.json" endpoint = "2/search/adaptive.json"
params = self.params.copy() params = self.params.copy()
@ -437,10 +457,6 @@ class TwitterAPI():
return self._pagination( return self._pagination(
endpoint, params, "sq-I-t-", "sq-cursor-bottom") endpoint, params, "sq-I-t-", "sq-cursor-bottom")
def bookmarks(self):
endpoint = "2/timeline/bookmark.json"
return self._pagination(endpoint)
def user_by_screen_name(self, screen_name): def user_by_screen_name(self, screen_name):
endpoint = "graphql/-xfUfZsnR_zqjFd-IfrN5A/UserByScreenName" endpoint = "graphql/-xfUfZsnR_zqjFd-IfrN5A/UserByScreenName"
params = { params = {

Loading…
Cancel
Save