aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex <alexta69@gmail.com>2019-12-13 19:22:44 +0200
committerAlex <alexta69@gmail.com>2019-12-13 19:22:44 +0200
commit34ec89485f01d9e4171ed2cb7291232f42fecbd5 (patch)
treea1ac467719d999273b5d15235824895274787b10 /app
parentupdated dependencies (diff)
downloadmetube-34ec89485f01d9e4171ed2cb7291232f42fecbd5.tar.gz
metube-34ec89485f01d9e4171ed2cb7291232f42fecbd5.tar.bz2
metube-34ec89485f01d9e4171ed2cb7291232f42fecbd5.zip
recursive add (download entire channels)
Diffstat (limited to 'app')
-rw-r--r--app/ytdl.py45
1 files changed, 29 insertions, 16 deletions
diff --git a/app/ytdl.py b/app/ytdl.py
index 2cd7eb2..1543f18 100644
--- a/app/ytdl.py
+++ b/app/ytdl.py
@@ -121,28 +121,41 @@ class DownloadQueue:
'extract_flat': True,
}).extract_info(url, download=False)
- async def add(self, url):
- log.info(f'adding {url}')
- try:
- info = await asyncio.get_running_loop().run_in_executor(None, self.__extract_info, url)
- except youtube_dl.utils.YoutubeDLError as exc:
- return {'status': 'error', 'msg': str(exc)}
- etype = info.get('_type') or 'video'
+ async def __add_entry(self, entry, already):
+ etype = entry.get('_type') or 'video'
if etype == 'playlist':
- entries = info['entries']
+ entries = entry['entries']
log.info(f'playlist detected with {len(entries)} entries')
- elif etype == 'video':
- entries = [info]
- log.info('single video detected')
- else:
- return {'status': 'error', 'msg': f'Unsupported resource requested: {etype}, please enter video or playlist URLs only'}
- for entry in entries:
+ results = []
+ for etr in entries:
+ results.append(await self.__add_entry(etr, already))
+ if any(res['status'] == 'error' for res in results):
+ return {'status': 'error', 'msg': ', '.join(res['msg'] for res in results if res['status'] == 'error' and 'msg' in res)}
+ return {'status': 'ok'}
+ elif etype == 'video' or etype == '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'])
self.queue[entry['id']] = Download(self.config.DOWNLOAD_DIR, dl)
+ self.event.set()
await self.notifier.added(dl)
- self.event.set()
- return {'status': 'ok'}
+ return {'status': 'ok'}
+ elif etype == 'url':
+ return await self.add(entry['url'], already)
+ return {'status': 'error', 'msg': f'Unsupported resource "{etype}"'}
+
+ async def add(self, url, already=None):
+ log.info(f'adding {url}')
+ already = set() if already is None else already
+ if url in already:
+ log.info('recursion detected, skipping')
+ return {'status': 'ok'}
+ else:
+ already.add(url)
+ try:
+ entry = await asyncio.get_running_loop().run_in_executor(None, self.__extract_info, url)
+ except youtube_dl.utils.YoutubeDLError as exc:
+ return {'status': 'error', 'msg': str(exc)}
+ return await self.__add_entry(entry, already)
async def cancel(self, ids):
for id in ids:
bgstack15