aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex <alexta69@gmail.com>2021-12-14 18:30:59 +0200
committerGitHub <noreply@github.com>2021-12-14 18:30:59 +0200
commit6a78c9bf60fa32d48fb4a9181c07f9293c79f2b7 (patch)
tree5ad3086b8f9eabeccdaf7ce9602d69cef3b36e86
parentfix sass syntax for dark mode (diff)
parentAdd download link to downloaded file (diff)
downloadmetube-6a78c9bf60fa32d48fb4a9181c07f9293c79f2b7.tar.gz
metube-6a78c9bf60fa32d48fb4a9181c07f9293c79f2b7.tar.bz2
metube-6a78c9bf60fa32d48fb4a9181c07f9293c79f2b7.zip
Merge pull request #88 from kleest/pr-download-link
Add download link to downloaded file
-rw-r--r--app/main.py1
-rw-r--r--app/ytdl.py7
-rw-r--r--ui/src/app/app.component.html3
-rw-r--r--ui/src/app/downloads.service.ts1
4 files changed, 11 insertions, 1 deletions
diff --git a/app/main.py b/app/main.py
index 368db16..8b2a57f 100644
--- a/app/main.py
+++ b/app/main.py
@@ -108,6 +108,7 @@ if config.URL_PREFIX != '/':
return web.HTTPFound(config.URL_PREFIX)
routes.static(config.URL_PREFIX + 'favicon/', 'favicon')
+routes.static(config.URL_PREFIX + 'download/', config.DOWNLOAD_DIR)
routes.static(config.URL_PREFIX, 'ui/dist/metube')
app.add_routes(routes)
diff --git a/app/ytdl.py b/app/ytdl.py
index e0267d7..4d92e3f 100644
--- a/app/ytdl.py
+++ b/app/ytdl.py
@@ -30,6 +30,7 @@ class DownloadInfo:
self.quality = quality
self.format = format
self.status = self.msg = self.percent = self.speed = self.eta = None
+ self.filename = None
class Download:
manager = None
@@ -60,6 +61,9 @@ class Download:
'speed',
'eta',
)})
+ def put_status_postprocessor(d):
+ if d['postprocessor'] == 'MoveFiles' and d['status'] == 'finished':
+ self.status_queue.put({'status': 'finished', 'filename': d['info_dict']['filepath']})
ret = yt_dlp.YoutubeDL(params={
'quiet': True,
'no_color': True,
@@ -69,6 +73,7 @@ class Download:
'cachedir': False,
'socket_timeout': 30,
'progress_hooks': [put_status],
+ 'postprocessor_hooks': [put_status_postprocessor],
**self.ytdl_opts,
}).download([self.info.url])
self.status_queue.put({'status': 'finished' if ret == 0 else 'error'})
@@ -113,6 +118,8 @@ class Download:
if status is None:
return
self.tmpfilename = status.get('tmpfilename')
+ if 'filename' in status:
+ self.info.filename = os.path.relpath(status.get('filename'))
self.info.status = status['status']
self.info.msg = status.get('msg')
if 'downloaded_bytes' in status:
diff --git a/ui/src/app/app.component.html b/ui/src/app/app.component.html
index 039aab6..1496bde 100644
--- a/ui/src/app/app.component.html
+++ b/ui/src/app/app.component.html
@@ -112,7 +112,8 @@
<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>
- <span ngbTooltip="{{download.value.msg}}">{{ download.value.title }}</span>
+ <span ngbTooltip="{{download.value.msg}}"><a *ngIf="!!download.value.filename; else noDownloadLink" href="download/{{download.value.filename}}" target="_blank">{{ download.value.title }}</a></span>
+ <ng-template #noDownloadLink>{{ download.value.title }}</ng-template>
</td>
<td>
<button *ngIf="download.value.status == 'error'" type="button" class="btn btn-link" (click)="retryDownload(download.key, download.value.quality)"><fa-icon [icon]="faRedoAlt"></fa-icon></button>
diff --git a/ui/src/app/downloads.service.ts b/ui/src/app/downloads.service.ts
index e0db252..25bcccc 100644
--- a/ui/src/app/downloads.service.ts
+++ b/ui/src/app/downloads.service.ts
@@ -15,6 +15,7 @@ interface Download {
url: string,
status: string;
msg: string;
+ filename: string;
quality: string;
percent: number;
speed: number;
bgstack15