attempt to handle 403 errors
This commit is contained in:
parent
12f625a432
commit
558e723948
1 changed files with 12 additions and 1 deletions
11
delojza.py
11
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:
|
||||
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] + '.*')
|
||||
|
|
Loading…
Reference in a new issue