Handle 429
This commit is contained in:
parent
771d4fb29f
commit
1fd5ccaeb5
|
@ -65,6 +65,7 @@ async def check_video(video):
|
|||
async def _check_video(video):
|
||||
logging.info('Checking video %s', video['yt_videoid'])
|
||||
first_try_live = waited = False
|
||||
tmr_attempts = 1
|
||||
while True:
|
||||
video_json = await get_video(video['link'])
|
||||
if isinstance(video_json, dict):
|
||||
|
@ -74,7 +75,10 @@ async def _check_video(video):
|
|||
wait_time = 30
|
||||
if isinstance(video_json, str):
|
||||
error_message = video_json[7:]
|
||||
if error_message.startswith('AUTOYTARCHIVE:'):
|
||||
if 'too many request' in error_message.lower():
|
||||
wait_time = tmr_attempts * 60 * 60
|
||||
tmr_attempts += 1
|
||||
elif error_message.startswith('AUTOYTARCHIVE:'):
|
||||
tmp = error_message.split(':', 1)[1].split(' ', 1)[0]
|
||||
if tmp.isnumeric():
|
||||
new_wait_time = int(tmp) - int(time.time())
|
||||
|
@ -114,16 +118,19 @@ async def _video_worker():
|
|||
try:
|
||||
tempdir = tempdir_obj.name
|
||||
if late_to_queue:
|
||||
for _ in range(5):
|
||||
for i in range(5):
|
||||
tmp = await get_video(video_json['id'])
|
||||
if isinstance(tmp, dict):
|
||||
video_json = tmp
|
||||
break
|
||||
wait_time = 30
|
||||
if isinstance(tmp, str):
|
||||
if 'too many request' in tmp.lower():
|
||||
wait_time = (i + 1) * 60 * 60
|
||||
logging.error('Error on video %s: %s', video_json['id'], tmp)
|
||||
else:
|
||||
logging.error('Video %s returned status code %s\n%s', video_json['id'], *video_json)
|
||||
await asyncio.sleep(30)
|
||||
await asyncio.sleep(wait_time)
|
||||
if video_json.get('requested_formats'):
|
||||
for i in video_json['requested_formats']:
|
||||
command.extend(('-i', i['url']))
|
||||
|
@ -172,12 +179,14 @@ async def _video_worker():
|
|||
await client.send_message(config['config']['storage_chat_id'], f'Failed to download video {video_json["id"]}, please check logs', parse_mode=None)
|
||||
except BaseException:
|
||||
logging.exception('Exception encountered when sending message to Telegram about download failure exception')
|
||||
for _ in range(5):
|
||||
for i in range(5):
|
||||
tmp = await get_video(video_json['id'])
|
||||
if isinstance(tmp, dict):
|
||||
video_json = tmp
|
||||
break
|
||||
if isinstance(tmp, str):
|
||||
if 'too many request' in tmp.lower():
|
||||
wait_time = (i + 1) * 60 * 60
|
||||
logging.error('Error on video %s: %s', video_json['id'], tmp)
|
||||
else:
|
||||
logging.error('Video %s returned status code %s\n%s', video_json['id'], *tmp)
|
||||
|
|
Loading…
Reference in New Issue