parent
a19fa7097c
commit
d37ed659cd
|
@ -119,7 +119,6 @@ async def _video_worker():
|
||||||
video_json, start_time, first_try_live = await video_queue.get()
|
video_json, start_time, first_try_live = await video_queue.get()
|
||||||
late_to_queue = (Decimal(time.time()) - Decimal(start_time)) > 5
|
late_to_queue = (Decimal(time.time()) - Decimal(start_time)) > 5
|
||||||
is_late = first_try_live or late_to_queue
|
is_late = first_try_live or late_to_queue
|
||||||
command = ['ffmpeg', '-y']
|
|
||||||
tempdir_obj = tempfile.TemporaryDirectory(dir='.')
|
tempdir_obj = tempfile.TemporaryDirectory(dir='.')
|
||||||
try:
|
try:
|
||||||
tempdir = tempdir_obj.name
|
tempdir = tempdir_obj.name
|
||||||
|
@ -136,14 +135,37 @@ async def _video_worker():
|
||||||
video_json = tmp
|
video_json = tmp
|
||||||
break
|
break
|
||||||
await asyncio.sleep(wait_time)
|
await asyncio.sleep(wait_time)
|
||||||
if video_json.get('requested_formats'):
|
async def construct_command():
|
||||||
for i in video_json['requested_formats']:
|
nonlocal video_json
|
||||||
command.extend(('-i', i['url']))
|
command = ['ffmpeg', '-y']
|
||||||
else:
|
is_manifest = False
|
||||||
command.extend(('-i', video_json['url']))
|
if video_json.get('requested_formats'):
|
||||||
|
for i in video_json['requested_formats']:
|
||||||
|
if urlparse(i['url']).netloc == 'manifest.googlevideo.com':
|
||||||
|
is_manifest = True
|
||||||
|
command.extend(('-i', i['url']))
|
||||||
|
else:
|
||||||
|
is_manifest = urlparse(video_json['url']).netloc == 'manifest.googlevideo.com'
|
||||||
|
command.extend(('-i', video_json['url']))
|
||||||
|
if is_manifest:
|
||||||
|
await asyncio.sleep(video_json['duration'] + 30)
|
||||||
|
wait_time = 30
|
||||||
|
for i in range(5):
|
||||||
|
try:
|
||||||
|
tmp = await client.loop.run_in_executor(None, ytdl.extract_info, video_json['id'])
|
||||||
|
except BaseException as e:
|
||||||
|
e = str(e)
|
||||||
|
if '429' in e or 'too many request' in e.lower():
|
||||||
|
wait_time = (i + 1) * 60 * 60
|
||||||
|
else:
|
||||||
|
video_json = tmp
|
||||||
|
break
|
||||||
|
await asyncio.sleep(wait_time)
|
||||||
|
return await construct_command()
|
||||||
|
command.extend(('-c', 'copy', video_filename))
|
||||||
|
return command
|
||||||
video_filename = os.path.join(tempdir, video_json['id'] + '.mkv')
|
video_filename = os.path.join(tempdir, video_json['id'] + '.mkv')
|
||||||
command.extend(('-c', 'copy', video_filename))
|
proc = await asyncio.create_subprocess_exec(*(await construct_command()))
|
||||||
proc = await asyncio.create_subprocess_exec(*command)
|
|
||||||
text = 'New video'
|
text = 'New video'
|
||||||
if is_late:
|
if is_late:
|
||||||
text += ' (is late)'
|
text += ' (is late)'
|
||||||
|
@ -196,6 +218,7 @@ async def _video_worker():
|
||||||
video_json = tmp
|
video_json = tmp
|
||||||
break
|
break
|
||||||
await asyncio.sleep(wait_time)
|
await asyncio.sleep(wait_time)
|
||||||
|
proc = await asyncio.create_subprocess_exec(*(await construct_command()))
|
||||||
except BaseException:
|
except BaseException:
|
||||||
tempdir_obj.cleanup()
|
tempdir_obj.cleanup()
|
||||||
raise
|
raise
|
||||||
|
|
Loading…
Reference in New Issue