Improve detection of missing video

This commit is contained in:
jeancf 2023-07-22 09:56:54 +02:00
parent e512838a0e
commit b69ac01b3c

View File

@ -674,25 +674,31 @@ def process_attachments(nitter_url, attachments_container, status_id, author_acc
logging.debug("downloading video from twitter") logging.debug("downloading video from twitter")
import youtube_dl import youtube_dl
video_path = vid_container.source['src'] video_path_source = vid_container.source
if video_path is not None: if video_path_source is not None:
video_file = urljoin(nitter_url, video_path) video_path = video_path_source['src']
ydl_opts = { if video_path is not None:
'outtmpl': "output/" + TOML['config']['twitter_account'] + "/" + status_id + "/%(id)s.%(ext)s", video_file = urljoin(nitter_url, video_path)
# 'format': "best[width<=500]", ydl_opts = {
'socket_timeout': 60, 'outtmpl': "output/" + TOML['config']['twitter_account'] + "/" + status_id + "/%(id)s.%(ext)s",
'quiet': True, # 'format': "best[width<=500]",
} 'socket_timeout': 60,
'quiet': True,
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl: with youtube_dl.YoutubeDL(ydl_opts) as ydl:
try: try:
ydl.download([video_file]) ydl.download([video_file])
except Exception as e: except Exception as e:
logging.warning('Error downloading twitter video: ' + str(e)) logging.warning('Error downloading twitter video: ' + str(e))
vid_in_tweet = True vid_in_tweet = True
else: else:
logging.debug('downloaded twitter video from attachments') logging.debug('downloaded twitter video from attachments')
else:
logging.debug("Media is unavailable")
vid_in_tweet = True
else: else:
logging.debug("Media is unavailable")
vid_in_tweet = True vid_in_tweet = True
return pics, vid_in_tweet return pics, vid_in_tweet
@ -1057,7 +1063,7 @@ def main(argv):
status_id, author_account) status_id, author_account)
photos.extend(pics) photos.extend(pics)
if vid_in_tweet: if vid_in_tweet:
tweet_text += '\n\n[Video embedded in original tweet]' tweet_text += '\n\n[Video is unavailable]'
# Add custom footer from config file # Add custom footer from config file
if TOML['options']['footer'] != '': if TOML['options']['footer'] != '':