do not retrieve video longer than 600s (10mn)

This commit is contained in:
cquest 2023-04-27 15:29:08 +02:00
parent f54ab85f18
commit 735c495b41

View File

@ -286,23 +286,30 @@ else:
if m is None: if m is None:
c = c.replace(l, redir) c = c.replace(l, redir)
else: else:
print('lien:',l)
c = c.replace(l, '')
video = redir video = redir
print('video:', video) print('video:', video)
subprocess.run('rm -f out.mp4; yt-dlp -N 8 -o out.mp4 --recode-video mp4 --no-playlist %s --max-filesize 100M' % video_json = subprocess.run('yt-dlp -s -j %s' %
(video,), shell=True, capture_output=False) (video,), shell=True, capture_output=True)
print("received") video_info = json.loads(video_json.stdout)
try: if video_info['duration'] < 600:
file = open("out.mp4", "rb") print('lien:', l)
video_data = file.read() c = c.replace(l, '')
file.close() subprocess.run('rm -f out.*; yt-dlp -N 8 -o out.mp4 --recode-video mp4 --no-playlist --max-filesize 100M %s' %
media_posted = mastodon_api.media_post(video_data, mime_type='video/mp4') (video,), shell=True, capture_output=False)
c = c.replace(video, '') print("received")
print("posted") try:
toot_media.append(media_posted['id']) file = open("out.mp4", "rb")
except: video_data = file.read()
pass file.close()
media_posted = mastodon_api.media_post(video_data, mime_type='video/mp4')
c = c.replace(video, '')
print("posted")
toot_media.append(media_posted['id'])
os.remove("out.mp4")
except:
pass
else:
print("video duration > 600s : ", video_info['duration'])
# remove pic.twitter.com links # remove pic.twitter.com links
m = re.search(r"pic.twitter.com[^ \xa0]*", c) m = re.search(r"pic.twitter.com[^ \xa0]*", c)