From c01ff78467aa888dce4d15d2aba853f36d60fa54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 1 Nov 2019 22:06:07 +0100 Subject: [PATCH] [twitter] extend 'videos' option to force extraction with ytdl (closes #459) --- docs/configuration.rst | 10 ++++++++-- gallery_dl/extractor/twitter.py | 25 ++++++++++++++----------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index b85d09b4..3b566067 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1029,9 +1029,15 @@ Description Extract images from retweets. extractor.twitter.videos ------------------------ =========== ===== -Type ``bool`` +Type ``bool`` or ``string`` 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 =========== ===== diff --git a/gallery_dl/extractor/twitter.py b/gallery_dl/extractor/twitter.py index 21b8d3cd..dfafc1fc 100644 --- a/gallery_dl/extractor/twitter.py +++ b/gallery_dl/extractor/twitter.py @@ -54,17 +54,20 @@ class TwitterExtractor(Extractor): yield Message.Urllist, urls, data if self.videos and "-videoContainer" in tweet: - 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"} + if self.videos == "ytdl": + data["extension"] = None + url = "ytdl:{}/{}/status/{}".format( + self.root, data["user"], data["tweet_id"]) 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 - yield Message.Url, url, data def metadata(self): @@ -279,8 +282,8 @@ class TwitterTweetExtractor(TwitterExtractor): }), # Reply to another tweet (#403) ("https://twitter.com/tyson_hesse/status/1103767554424598528", { - "options": (("videos", True),), - "pattern": r"ytdl:https://video.twimg.com/ext_tw_video/.*.m3u8", + "options": (("videos", "ytdl"),), + "pattern": r"ytdl:https://twitter.com/.+/1103767554424598528", }), # /i/web/ URL ("https://twitter.com/i/web/status/1155074198240292865", {