attempt to handle 403 errors

This commit is contained in:
Tomáš Mládek 2019-05-29 13:50:44 +02:00
parent 12f625a432
commit 558e723948

View file

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