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] + '.*')