aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex <alexta69@gmail.com>2019-12-06 16:30:07 +0200
committerAlex <alexta69@gmail.com>2019-12-06 16:30:07 +0200
commit3cf7d25f4c54b6de9e1dd88e8d207100fcce8c11 (patch)
tree22286bf9f887905329e0fdca01af415361a26124
parentfix broken PREFIX_URL feature (diff)
downloadmetube-3cf7d25f4c54b6de9e1dd88e8d207100fcce8c11.tar.gz
metube-3cf7d25f4c54b6de9e1dd88e8d207100fcce8c11.tar.bz2
metube-3cf7d25f4c54b6de9e1dd88e8d207100fcce8c11.zip
improved error handling
-rw-r--r--app/ytdl.py36
-rw-r--r--ui/src/app/app.component.html4
-rw-r--r--ui/src/app/downloads.service.ts1
3 files changed, 27 insertions, 14 deletions
diff --git a/app/ytdl.py b/app/ytdl.py
index 9fe4840..1993300 100644
--- a/app/ytdl.py
+++ b/app/ytdl.py
@@ -11,7 +11,7 @@ log = logging.getLogger('ytdl')
class DownloadInfo:
def __init__(self, id, title, url):
self.id, self.title, self.url = id, title, url
- self.status = self.percent = self.speed = self.eta = None
+ self.status = self.msg = self.percent = self.speed = self.eta = None
class Download:
manager = None
@@ -25,14 +25,19 @@ class Download:
self.loop = None
def _download(self):
- youtube_dl.YoutubeDL(params={
- 'quiet': True,
- 'no_color': True,
- #'skip_download': True,
- 'outtmpl': os.path.join(self.download_dir, '%(title)s.%(ext)s'),
- 'socket_timeout': 30,
- 'progress_hooks': [lambda d: self.status_queue.put(d)],
- }).download([self.info.url])
+ try:
+ ret = youtube_dl.YoutubeDL(params={
+ 'quiet': True,
+ 'no_color': True,
+ #'skip_download': True,
+ 'outtmpl': os.path.join(self.download_dir, '%(title)s.%(ext)s'),
+ 'cachedir': False,
+ 'socket_timeout': 30,
+ 'progress_hooks': [lambda d: self.status_queue.put(d)],
+ }).download([self.info.url])
+ 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):
if Download.manager is None:
@@ -53,7 +58,10 @@ class Download:
self.status_queue.put(None)
def running(self):
- return self.proc is not None and self.proc.is_alive()
+ try:
+ return self.proc is not None and self.proc.is_alive()
+ except ValueError:
+ return False
async def update_status(self, updated_cb):
await updated_cb()
@@ -63,6 +71,7 @@ class Download:
return
self.tmpfilename = status.get('tmpfilename')
self.info.status = status['status']
+ self.info.msg = status.get('msg')
if 'downloaded_bytes' in status:
total = status.get('total_bytes') or status.get('total_bytes_estimate')
if total:
@@ -109,12 +118,15 @@ class DownloadQueue:
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)}
- if info.get('_type') == 'playlist':
+ etype = info.get('_type') or 'video'
+ if etype == 'playlist':
entries = info['entries']
log.info(f'playlist detected with {len(entries)} entries')
- else:
+ 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:
if entry['id'] not in self.queue:
dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url'])
diff --git a/ui/src/app/app.component.html b/ui/src/app/app.component.html
index 9e927ed..e0c67cd 100644
--- a/ui/src/app/app.component.html
+++ b/ui/src/app/app.component.html
@@ -81,11 +81,11 @@
<app-slave-checkbox [id]="download.key" [master]="doneMasterCheckbox" [checkable]="download.value"></app-slave-checkbox>
</td>
<td>
- <div style="display: inline-block; width: 1.3rem;">
+ <div style="display: inline-block; width: 1.5rem;">
<fa-icon *ngIf="download.value.status == 'finished'" [icon]="faCheckCircle" style="color: green;"></fa-icon>
<fa-icon *ngIf="download.value.status == 'error'" [icon]="faTimesCircle" style="color: red;"></fa-icon>
</div>
- {{ download.value.title }}
+ <span ngbTooltip="{{download.value.msg}}">{{ download.value.title }}</span>
</td>
<td><button type="button" class="btn btn-link" (click)="delDownload('done', download.key)"><fa-icon [icon]="faTrashAlt"></fa-icon></button></td>
</tr>
diff --git a/ui/src/app/downloads.service.ts b/ui/src/app/downloads.service.ts
index 823aa60..935feba 100644
--- a/ui/src/app/downloads.service.ts
+++ b/ui/src/app/downloads.service.ts
@@ -14,6 +14,7 @@ interface Download {
title: string;
url: string,
status: string;
+ msg: string;
percent: number;
speed: number;
eta: number;
bgstack15