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):
|
async def _check_video(video):
|
||||||
logging.info('Checking video %s', video['yt_videoid'])
|
logging.info('Checking video %s', video['yt_videoid'])
|
||||||
first_try_live = waited = False
|
first_try_live = waited = False
|
||||||
|
tmr_attempts = 1
|
||||||
while True:
|
while True:
|
||||||
video_json = await get_video(video['link'])
|
video_json = await get_video(video['link'])
|
||||||
if isinstance(video_json, dict):
|
if isinstance(video_json, dict):
|
||||||
|
@ -74,7 +75,10 @@ async def _check_video(video):
|
||||||
wait_time = 30
|
wait_time = 30
|
||||||
if isinstance(video_json, str):
|
if isinstance(video_json, str):
|
||||||
error_message = video_json[7:]
|
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]
|
tmp = error_message.split(':', 1)[1].split(' ', 1)[0]
|
||||||
if tmp.isnumeric():
|
if tmp.isnumeric():
|
||||||
new_wait_time = int(tmp) - int(time.time())
|
new_wait_time = int(tmp) - int(time.time())
|
||||||
|
@ -114,16 +118,19 @@ async def _video_worker():
|
||||||
try:
|
try:
|
||||||
tempdir = tempdir_obj.name
|
tempdir = tempdir_obj.name
|
||||||
if late_to_queue:
|
if late_to_queue:
|
||||||
for _ in range(5):
|
for i in range(5):
|
||||||
tmp = await get_video(video_json['id'])
|
tmp = await get_video(video_json['id'])
|
||||||
if isinstance(tmp, dict):
|
if isinstance(tmp, dict):
|
||||||
video_json = tmp
|
video_json = tmp
|
||||||
break
|
break
|
||||||
|
wait_time = 30
|
||||||
if isinstance(tmp, str):
|
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)
|
logging.error('Error on video %s: %s', video_json['id'], tmp)
|
||||||
else:
|
else:
|
||||||
logging.error('Video %s returned status code %s\n%s', video_json['id'], *video_json)
|
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'):
|
if video_json.get('requested_formats'):
|
||||||
for i in video_json['requested_formats']:
|
for i in video_json['requested_formats']:
|
||||||
command.extend(('-i', i['url']))
|
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)
|
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:
|
except BaseException:
|
||||||
logging.exception('Exception encountered when sending message to Telegram about download failure exception')
|
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'])
|
tmp = await get_video(video_json['id'])
|
||||||
if isinstance(tmp, dict):
|
if isinstance(tmp, dict):
|
||||||
video_json = tmp
|
video_json = tmp
|
||||||
break
|
break
|
||||||
if isinstance(tmp, str):
|
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)
|
logging.error('Error on video %s: %s', video_json['id'], tmp)
|
||||||
else:
|
else:
|
||||||
logging.error('Video %s returned status code %s\n%s', video_json['id'], *tmp)
|
logging.error('Video %s returned status code %s\n%s', video_json['id'], *tmp)
|
||||||
|
|
Loading…
Reference in New Issue