From 558e723948bd07223755421e950ee8da50e8f585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Wed, 29 May 2019 13:50:44 +0200 Subject: [PATCH] attempt to handle 403 errors --- delojza.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/delojza.py b/delojza.py index 3a30866..23f4997 100755 --- a/delojza.py +++ b/delojza.py @@ -24,6 +24,7 @@ import requests import telegram import youtube_dl from telegram.ext import Updater, CommandHandler, MessageHandler +from youtube_dl import DownloadError from youtube_dl.version import __version__ as YTDL_VERSION @@ -189,7 +190,17 @@ class DelojzaBot: }] filenames = [] with youtube_dl.YoutubeDL(ytdl) as ytdl: - ytdl.download(urls) + while True: + try: + ytdl.download(urls) + break + except DownloadError as exc: + if '403' in str(exc): + self.logger.warning("Received a 403!") + if self.markov: + message.reply_text(self.markov.make_sentence) + else: + raise exc for info in [ytdl.extract_info(url, download=False) for url in urls]: filename = ytdl.prepare_filename(info) globbeds = glob(os.path.splitext(filename)[0] + '.*')