diff --git a/delojza.py b/delojza.py index 4f6a9bf..01854b5 100755 --- a/delojza.py +++ b/delojza.py @@ -14,6 +14,7 @@ from datetime import datetime, timedelta from glob import glob from operator import itemgetter from random import random +from time import sleep import acoustid import filetype @@ -190,13 +191,16 @@ class DelojzaBot: }] filenames = [] with youtube_dl.YoutubeDL(ytdl) as ytdl: + attempts = 0 while True: try: ytdl.download(urls) break except DownloadError as exc: - if '403' in str(exc): + attempts += 1 + if '403' in str(exc) and attempts < 5: self.logger.warning("Received a 403!") + sleep(1.357) if self.markov: message.reply_text(self.markov.make_sentence) else: