[twitter] extend 'videos' option to force extraction with ytdl

(closes #459)
This commit is contained in:
Mike Fährmann 2019-11-01 22:06:07 +01:00
parent f8ac67ce50
commit c01ff78467
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 22 additions and 13 deletions

View File

@ -1029,9 +1029,15 @@ Description Extract images from retweets.
extractor.twitter.videos extractor.twitter.videos
------------------------ ------------------------
=========== ===== =========== =====
Type ``bool`` Type ``bool`` or ``string``
Default ``false`` Default ``false``
Description Use `youtube-dl`_ to download from video tweets. Description Control video download behavior.
* ``true``: Download videos and use `youtube-dl`_ to handle
HLS ``.m3u8`` manifests
* ``"ytdl"``: Download videos and let `youtube-dl`_ handle all of
video extraction and download
* ``false``: Skip video Tweets
=========== ===== =========== =====

View File

@ -54,17 +54,20 @@ class TwitterExtractor(Extractor):
yield Message.Urllist, urls, data yield Message.Urllist, urls, data
if self.videos and "-videoContainer" in tweet: if self.videos and "-videoContainer" in tweet:
url = self._video_from_tweet(data["tweet_id"]) if self.videos == "ytdl":
ext = text.ext_from_url(url) data["extension"] = None
url = "ytdl:{}/{}/status/{}".format(
if ext == "m3u8": self.root, data["user"], data["tweet_id"])
url = "ytdl:" + url
data["extension"] = "mp4"
data["_ytdl_extra"] = {"protocol": "m3u8_native"}
else: else:
data["extension"] = ext url = self._video_from_tweet(data["tweet_id"])
ext = text.ext_from_url(url)
if ext == "m3u8":
url = "ytdl:" + url
data["extension"] = "mp4"
data["_ytdl_extra"] = {"protocol": "m3u8_native"}
else:
data["extension"] = ext
data["num"] = 1 data["num"] = 1
yield Message.Url, url, data yield Message.Url, url, data
def metadata(self): def metadata(self):
@ -279,8 +282,8 @@ class TwitterTweetExtractor(TwitterExtractor):
}), }),
# Reply to another tweet (#403) # Reply to another tweet (#403)
("https://twitter.com/tyson_hesse/status/1103767554424598528", { ("https://twitter.com/tyson_hesse/status/1103767554424598528", {
"options": (("videos", True),), "options": (("videos", "ytdl"),),
"pattern": r"ytdl:https://video.twimg.com/ext_tw_video/.*.m3u8", "pattern": r"ytdl:https://twitter.com/.+/1103767554424598528",
}), }),
# /i/web/ URL # /i/web/ URL
("https://twitter.com/i/web/status/1155074198240292865", { ("https://twitter.com/i/web/status/1155074198240292865", {