parent
a19fa7097c
commit
d37ed659cd
|
@ -119,7 +119,6 @@ async def _video_worker():
|
|||
video_json, start_time, first_try_live = await video_queue.get()
|
||||
late_to_queue = (Decimal(time.time()) - Decimal(start_time)) > 5
|
||||
is_late = first_try_live or late_to_queue
|
||||
command = ['ffmpeg', '-y']
|
||||
tempdir_obj = tempfile.TemporaryDirectory(dir='.')
|
||||
try:
|
||||
tempdir = tempdir_obj.name
|
||||
|
@ -136,14 +135,37 @@ async def _video_worker():
|
|||
video_json = tmp
|
||||
break
|
||||
await asyncio.sleep(wait_time)
|
||||
if video_json.get('requested_formats'):
|
||||
for i in video_json['requested_formats']:
|
||||
command.extend(('-i', i['url']))
|
||||
else:
|
||||
command.extend(('-i', video_json['url']))
|
||||
async def construct_command():
|
||||
nonlocal video_json
|
||||
command = ['ffmpeg', '-y']
|
||||
is_manifest = False
|
||||
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')
|
||||
command.extend(('-c', 'copy', video_filename))
|
||||
proc = await asyncio.create_subprocess_exec(*command)
|
||||
proc = await asyncio.create_subprocess_exec(*(await construct_command()))
|
||||
text = 'New video'
|
||||
if is_late:
|
||||
text += ' (is late)'
|
||||
|
@ -196,6 +218,7 @@ async def _video_worker():
|
|||
video_json = tmp
|
||||
break
|
||||
await asyncio.sleep(wait_time)
|
||||
proc = await asyncio.create_subprocess_exec(*(await construct_command()))
|
||||
except BaseException:
|
||||
tempdir_obj.cleanup()
|
||||
raise
|
||||
|
|
Loading…
Reference in New Issue