mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-01-18 15:27:07 +00:00
download video from nitter
This commit is contained in:
parent
b690f83ed9
commit
b1d56e1f96
39
twoot.py
39
twoot.py
|
@ -647,29 +647,32 @@ def process_attachments(nitter_url, attachments_container, status_id, author_acc
|
|||
|
||||
# Download twitter video
|
||||
vid_in_tweet = False
|
||||
vid_class = attachments_container.find('div', class_='video-container')
|
||||
if vid_class is not None:
|
||||
vid_container = attachments_container.find('div', class_='video-container')
|
||||
if vid_container is not None:
|
||||
if TOML['options']['upload_videos']:
|
||||
logging.debug("downloading video from twitter")
|
||||
import youtube_dl
|
||||
|
||||
video_path = f"{author_account}/status/{status_id}"
|
||||
video_file = urljoin('https://twitter.com', 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 = vid_container.video['data-url']
|
||||
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:
|
||||
vid_in_tweet = True
|
||||
|
||||
return pics, vid_in_tweet
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user