mirror of
https://github.com/cquest/tootbot.git
synced 2025-02-17 08:18:07 +00:00
do not retrieve video longer than 600s (10mn)
This commit is contained in:
parent
f54ab85f18
commit
735c495b41
37
tootbot.py
37
tootbot.py
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user