From fffba9065acf10f1a2d6a1e2f3bc3aa531b6a8ca Mon Sep 17 00:00:00 2001 From: Rpsl Date: Thu, 29 Jul 2021 11:12:40 +0300 Subject: Added retry button for failed download --- app/ytdl.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/ytdl.py b/app/ytdl.py index d29f108..4475704 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -25,8 +25,9 @@ class DownloadQueueNotifier: raise NotImplementedError class DownloadInfo: - def __init__(self, id, title, url): + def __init__(self, id, title, url, quality): self.id, self.title, self.url = id, title, url + self.quality = quality self.status = self.msg = self.percent = self.speed = self.eta = None class Download: @@ -53,7 +54,7 @@ class Download: self.proc = None self.loop = None self.notifier = None - + def _download(self): try: ret = youtube_dl.YoutubeDL(params={ @@ -69,7 +70,7 @@ class Download: self.status_queue.put({'status': 'finished' if ret == 0 else 'error'}) except youtube_dl.utils.YoutubeDLError as exc: self.status_queue.put({'status': 'error', 'msg': str(exc)}) - + async def start(self, notifier): if Download.manager is None: Download.manager = multiprocessing.Manager() @@ -81,7 +82,7 @@ class Download: self.info.status = 'preparing' await self.notifier.updated(self.info) asyncio.ensure_future(self.update_status()) - return await self.loop.run_in_executor(None, self.proc.join) + return await self.loop.run_in_executor(None, self.proc.join) def cancel(self): if self.running(): @@ -147,7 +148,7 @@ class DownloadQueue: return {'status': 'ok'} elif etype == 'video' or etype.startswith('url') and 'id' in entry: if entry['id'] not in self.queue: - dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url']) + dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url'], quality) dldirectory = self.config.DOWNLOAD_DIR if quality != 'audio' else self.config.AUDIO_DOWNLOAD_DIR self.queue[entry['id']] = Download(dldirectory, self.config.OUTPUT_TEMPLATE, quality, dl) self.event.set() @@ -170,7 +171,7 @@ class DownloadQueue: except youtube_dl.utils.YoutubeDLError as exc: return {'status': 'error', 'msg': str(exc)} return await self.__add_entry(entry, quality, already) - + async def cancel(self, ids): for id in ids: if id not in self.queue: @@ -195,7 +196,7 @@ class DownloadQueue: def get(self): return(list((k, v.info) for k, v in self.queue.items()), list((k, v.info) for k, v in self.done.items())) - + async def __download(self): while True: while not self.queue: -- cgit