From 52b3ae07b1a5f502b0a0c26cde19967b63641869 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 1 Sep 2020 01:17:17 +1200 Subject: [PATCH] Detect being rate limited --- extractors/video.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/extractors/video.py b/extractors/video.py index 10eacaf..1417988 100644 --- a/extractors/video.py +++ b/extractors/video.py @@ -5,6 +5,7 @@ import os import re import traceback import youtube_dl +import urllib.error from tools.converters import * from tools.extractors import extract_yt_initial_data from math import floor @@ -169,11 +170,21 @@ def extract_video(id): return result - except youtube_dl.DownloadError: - return { - "error": "Video unavailable", - "identifier": "VIDEO_DOES_NOT_EXIST" - } + except youtube_dl.DownloadError as e: + if isinstance(e.exc_info[1], urllib.error.HTTPError): + if e.exc_info[1].code == 429: + result = { + "error": "Could not extract video info. Instance is likely blocked.", + "identifier": "RATE_LIMITED_BY_YOUTUBE" + } + else: + result = { + "error": "Received unexpected status code {}.".format(e.exc_info[1].code) + } + else: + result = { + "error": "Unknown download error." + } except Exception: traceback.print_exc()