diff options
author | Steffen Klee <steffen.klee@gmail.com> | 2021-12-13 22:35:19 +0100 |
---|---|---|
committer | Steffen Klee <steffen.klee@gmail.com> | 2021-12-13 22:35:19 +0100 |
commit | fe4993153c168b27969dc0fae500b62504bba52a (patch) | |
tree | 5ad3086b8f9eabeccdaf7ce9602d69cef3b36e86 /app | |
parent | fix sass syntax for dark mode (diff) | |
download | metube-fe4993153c168b27969dc0fae500b62504bba52a.tar.gz metube-fe4993153c168b27969dc0fae500b62504bba52a.tar.bz2 metube-fe4993153c168b27969dc0fae500b62504bba52a.zip |
Add download link to downloaded file
This adds a simple download link that points to the downloaded file.
Note: This makes all files in the download directory (and its
sub-directory) available to any user.
Closes gh-26
Diffstat (limited to 'app')
-rw-r--r-- | app/main.py | 1 | ||||
-rw-r--r-- | app/ytdl.py | 7 |
2 files changed, 8 insertions, 0 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:
|