[twitter] implement 'syndication=extended'
to be able to fetch extended user metadata
This commit is contained in:
@@ -2655,11 +2655,18 @@ Description
|
|||||||
extractor.twitter.syndication
|
extractor.twitter.syndication
|
||||||
-----------------------------
|
-----------------------------
|
||||||
Type
|
Type
|
||||||
``bool``
|
``bool`` or ``string``
|
||||||
Default
|
Default
|
||||||
``false``
|
``false``
|
||||||
Description
|
Description
|
||||||
Retrieve age-restricted content using Twitter's syndication API.
|
Controls how to retrieve age-restricted content when not logged in.
|
||||||
|
|
||||||
|
* ``false``: Skip age-restricted Tweets.
|
||||||
|
* ``true``: Download using Twitter's syndication API.
|
||||||
|
* ``"extended"``: Try to fetch Tweet metadata using the normal API
|
||||||
|
in addition to the syndication API. This requires additional HTTP
|
||||||
|
requests in some cases (e.g. when `retweets <extractor.twitter.retweets_>`_
|
||||||
|
is enabled).
|
||||||
|
|
||||||
|
|
||||||
extractor.twitter.logout
|
extractor.twitter.logout
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ 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.cards_blacklist = self.config("cards-blacklist")
|
self.cards_blacklist = self.config("cards-blacklist")
|
||||||
|
self.syndication = self.config("syndication")
|
||||||
self._user = self._user_obj = None
|
self._user = self._user_obj = None
|
||||||
self._user_cache = {}
|
self._user_cache = {}
|
||||||
self._init_sizes()
|
self._init_sizes()
|
||||||
@@ -297,8 +298,11 @@ class TwitterExtractor(Extractor):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# try to fetch extended user data
|
||||||
if "legacy" in user:
|
if "legacy" in user:
|
||||||
user = user["legacy"]
|
user = user["legacy"]
|
||||||
|
elif "statuses_count" not in user and self.syndication == "extended":
|
||||||
|
user = self.api.user_by_screen_name(user["screen_name"])["legacy"]
|
||||||
|
|
||||||
uget = user.get
|
uget = user.get
|
||||||
entities = user["entities"]
|
entities = user["entities"]
|
||||||
@@ -991,7 +995,6 @@ class TwitterAPI():
|
|||||||
}
|
}
|
||||||
|
|
||||||
self._nsfw_warning = True
|
self._nsfw_warning = True
|
||||||
self._syndication = extractor.config("syndication")
|
|
||||||
self._json_dumps = json.JSONEncoder(separators=(",", ":")).encode
|
self._json_dumps = json.JSONEncoder(separators=(",", ":")).encode
|
||||||
|
|
||||||
cookies = extractor.session.cookies
|
cookies = extractor.session.cookies
|
||||||
@@ -1494,7 +1497,7 @@ class TwitterAPI():
|
|||||||
tweet_id = entry["entryId"].rpartition("-")[2]
|
tweet_id = entry["entryId"].rpartition("-")[2]
|
||||||
|
|
||||||
if text.startswith("Age-restricted"):
|
if text.startswith("Age-restricted"):
|
||||||
if self._syndication:
|
if self.extractor.syndication:
|
||||||
return self._syndication_tweet(tweet_id)
|
return self._syndication_tweet(tweet_id)
|
||||||
elif self._nsfw_warning:
|
elif self._nsfw_warning:
|
||||||
self._nsfw_warning = False
|
self._nsfw_warning = False
|
||||||
|
|||||||
Reference in New Issue
Block a user