aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/twitter.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/extractor/twitter.py')
-rw-r--r--gallery_dl/extractor/twitter.py29
1 files changed, 25 insertions, 4 deletions
diff --git a/gallery_dl/extractor/twitter.py b/gallery_dl/extractor/twitter.py
index ea57d76..d4ec343 100644
--- a/gallery_dl/extractor/twitter.py
+++ b/gallery_dl/extractor/twitter.py
@@ -155,6 +155,7 @@ class TwitterExtractor(Extractor):
if not self.unavailable:
continue
+ mtype = media.get("type")
descr = media.get("ext_alt_text")
width = media["original_info"].get("width", 0)
height = media["original_info"].get("height", 0)
@@ -164,6 +165,7 @@ class TwitterExtractor(Extractor):
files.append({
"url": "ytdl:{}/i/web/status/{}".format(
self.root, tweet["id_str"]),
+ "type" : mtype,
"width" : width,
"height" : height,
"extension" : None,
@@ -177,6 +179,7 @@ class TwitterExtractor(Extractor):
)
files.append({
"url" : variant["url"],
+ "type" : mtype,
"width" : width,
"height" : height,
"bitrate" : variant.get("bitrate", 0),
@@ -193,6 +196,7 @@ class TwitterExtractor(Extractor):
base = url.rpartition("=")[0] + "="
files.append(text.nameext_from_url(url, {
"url" : base + self._size_image,
+ "type" : mtype,
"width" : width,
"height" : height,
"_fallback" : self._image_fallback(base),
@@ -504,7 +508,11 @@ class TwitterExtractor(Extractor):
}
def _init_cursor(self):
- return self.config("cursor") or None
+ cursor = self.config("cursor", True)
+ if not cursor:
+ self._update_cursor = util.identity
+ elif isinstance(cursor, str):
+ return cursor
def _update_cursor(self, cursor):
self.log.debug("Cursor: %s", cursor)
@@ -560,6 +568,7 @@ class TwitterUserExtractor(TwitterExtractor):
def items(self):
base = "{}/{}/".format(self.root, self.user)
return self._dispatch_extractors((
+ (TwitterInfoExtractor , base + "info"),
(TwitterAvatarExtractor , base + "photo"),
(TwitterBackgroundExtractor, base + "header_photo"),
(TwitterTimelineExtractor , base + "timeline"),
@@ -590,9 +599,16 @@ class TwitterTimelineExtractor(TwitterExtractor):
return cursor
def tweets(self):
- self._cursor = cursor = self.config("cursor") or None
reset = False
+ cursor = self.config("cursor", True)
+ if not cursor:
+ self._update_cursor = util.identity
+ elif isinstance(cursor, str):
+ self._cursor = cursor
+ else:
+ cursor = None
+
if cursor:
state = cursor.partition("/")[0]
state, _, tweet_id = state.partition("_")
@@ -1612,6 +1628,9 @@ class TwitterAPI():
entries = instr["entries"]
elif instr_type == "TimelineAddToModule":
entries = instr["moduleItems"]
+ elif instr_type == "TimelinePinEntry":
+ if pinned_tweet:
+ pinned_tweet = instr["entry"]
elif instr_type == "TimelineReplaceEntry":
entry = instr["entry"]
if entry["entryId"].startswith("cursor-bottom-"):
@@ -1650,9 +1669,11 @@ class TwitterAPI():
tweet = None
if pinned_tweet:
- pinned_tweet = False
- if instructions[-1]["type"] == "TimelinePinEntry":
+ if isinstance(pinned_tweet, dict):
+ tweets.append(pinned_tweet)
+ elif instructions[-1]["type"] == "TimelinePinEntry":
tweets.append(instructions[-1]["entry"])
+ pinned_tweet = False
for entry in entries:
esw = entry["entryId"].startswith