[twitter] fix potential 'UnboundLocalError' (#7932)

this happens with Tweets containing both images and video
when 'videos' are disabled.
This commit is contained in:
Mike Fährmann
2025-07-30 16:11:38 +02:00
parent e5c91d33ec
commit 3b93184997
2 changed files with 23 additions and 0 deletions

View File

@@ -217,6 +217,8 @@ class TwitterExtractor(Extractor):
"duration": video_info.get(
"duration_millis", 0) / 1000,
}
else:
continue
elif "media_url_https" in media:
url = media["media_url_https"]
if url[-4] == ".":

View File

@@ -349,6 +349,27 @@ __tests__ = (
"type": "video",
},
{
"#url" : "https://x.com/carrotsprout_/status/1577924293023133696",
"#comment" : "mixed image & video",
"#class" : twitter.TwitterTweetExtractor,
"#results" : (
"https://pbs.twimg.com/media/FeXpxOyaYAA9L88?format=jpg&name=orig",
"https://video.twimg.com/ext_tw_video/1577924276447248386/pu/vid/720x800/kNsjUvJ5knrSx5WM.mp4?tag=12",
),
},
{
"#url" : "https://x.com/gopherfootball/status/1950259395432239395",
"#comment" : "mixed images & video; 'videos' disabled (#7932)",
"#class" : twitter.TwitterTweetExtractor,
"#options" : {"videos": False},
"#results" : (
"https://pbs.twimg.com/media/GxC2eRJWAAAH_NM?format=jpg&name=orig",
"https://pbs.twimg.com/media/GxC2eRAWoAA8gGQ?format=jpg&name=orig",
),
},
{
"#url" : "https://twitter.com/playpokemon/status/1263832915173048321/",
"#comment" : "content with emoji, newlines, hashtags (#338)",