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