mirror of
https://gitlab.com/jeancf/twoot.git
synced 2024-11-23 20:11:11 +00:00
Add video download fix
This commit is contained in:
parent
24e9bd5691
commit
93a945062d
39
twoot.py
39
twoot.py
|
@ -668,29 +668,32 @@ def process_attachments(nitter_url, attachments_container, status_id, author_acc
|
||||||
|
|
||||||
# Download twitter video
|
# Download twitter video
|
||||||
vid_in_tweet = False
|
vid_in_tweet = False
|
||||||
vid_class = attachments_container.find('div', class_='video-container')
|
vid_container = attachments_container.find('div', class_='video-container')
|
||||||
if vid_class is not None:
|
if vid_container is not None:
|
||||||
if TOML['options']['upload_videos']:
|
if TOML['options']['upload_videos']:
|
||||||
logging.debug("downloading video from twitter")
|
logging.debug("downloading video from twitter")
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
|
|
||||||
video_path = f"{author_account}/status/{status_id}"
|
video_path = vid_container.source['src']
|
||||||
video_file = urljoin('https://twitter.com', video_path)
|
if video_path is not None:
|
||||||
ydl_opts = {
|
video_file = urljoin(nitter_url, video_path)
|
||||||
'outtmpl': "output/" + TOML['config']['twitter_account'] + "/" + status_id + "/%(id)s.%(ext)s",
|
ydl_opts = {
|
||||||
'format': "best[width<=500]",
|
'outtmpl': "output/" + TOML['config']['twitter_account'] + "/" + status_id + "/%(id)s.%(ext)s",
|
||||||
'socket_timeout': 60,
|
# 'format': "best[width<=500]",
|
||||||
'quiet': True,
|
'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:
|
||||||
|
vid_in_tweet = True
|
||||||
|
|
||||||
return pics, vid_in_tweet
|
return pics, vid_in_tweet
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user