Unsanitized file names in db but sanitized on disk fixed.
Mimetype fixed.
This commit is contained in:
36
backend.py
36
backend.py
@@ -85,6 +85,8 @@ def process_download(url, ext, parent, query, current_thread):
|
||||
if video is None:
|
||||
continue
|
||||
|
||||
video['title'] = sanitize_filename(video['title'])
|
||||
|
||||
if check_already_exists(video['id']):
|
||||
add_new_video_to_collection(parent, video['id'])
|
||||
continue
|
||||
@@ -94,14 +96,14 @@ def process_download(url, ext, parent, query, current_thread):
|
||||
download=False)
|
||||
|
||||
# replace url with name of playlist
|
||||
queued_downloads[0][0] = parent.replace('/', '⧸')
|
||||
queued_downloads[0][0] = sanitize_filename(parent)
|
||||
|
||||
if max_video_length and video['duration'] > max_video_length:
|
||||
continue
|
||||
|
||||
# add new entry to file_cache
|
||||
ids.append(video['id'])
|
||||
titles.append(video['title'].replace('/', '⧸'))
|
||||
titles.append(video['title'])
|
||||
urls.append('https://www.youtube.com/watch?v=' + video['id'])
|
||||
|
||||
# start download
|
||||
@@ -122,12 +124,14 @@ def process_download(url, ext, parent, query, current_thread):
|
||||
if video is None:
|
||||
continue
|
||||
|
||||
video['title'] = sanitize_filename(video['title'])
|
||||
|
||||
if check_already_exists(video['id']):
|
||||
add_new_video_to_collection(parent, video['id'])
|
||||
continue
|
||||
|
||||
# replace url with name of channel
|
||||
queued_downloads[0][0] = parent.replace('/', '⧸')
|
||||
queued_downloads[0][0] = sanitize_filename(parent)
|
||||
|
||||
if max_video_length and video['duration'] > max_video_length:
|
||||
continue
|
||||
@@ -136,7 +140,7 @@ def process_download(url, ext, parent, query, current_thread):
|
||||
# but no consistency has been observed
|
||||
# still works though so will not be checked for now
|
||||
ids.append(video['id'])
|
||||
titles.append(video['title'].replace('/', '⧸'))
|
||||
titles.append(video['title'])
|
||||
urls.append('https://www.youtube.com/watch?v=' + video['id'])
|
||||
|
||||
# start download
|
||||
@@ -153,11 +157,14 @@ def process_download(url, ext, parent, query, current_thread):
|
||||
# when downloading single files that already exist, there's no need for adjustments in db
|
||||
if not check_already_exists(query['id']):
|
||||
ids.append(query['id'])
|
||||
titles.append(query['title'].replace('/', '⧸'))
|
||||
query['title'] = sanitize_filename(query['title'])
|
||||
titles.append(query['title'])
|
||||
urls.append('https://www.youtube.com/watch?v=' + query['id'])
|
||||
else:
|
||||
return
|
||||
|
||||
# replace url with name of video
|
||||
queued_downloads[0][0] = query['title'].replace('/', '⧸')
|
||||
queued_downloads[0][0] = query['title']
|
||||
|
||||
# start download
|
||||
download_all(url, ext=ext)
|
||||
@@ -173,7 +180,7 @@ def process_download(url, ext, parent, query, current_thread):
|
||||
# this is the 'controller' for the update process
|
||||
def process_update(parent, query, current_thread):
|
||||
# replace url with name of playlist
|
||||
queued_downloads[0][0] = parent
|
||||
queued_downloads[0][0] = sanitize_filename(parent)
|
||||
|
||||
# if updating playlist
|
||||
try:
|
||||
@@ -182,6 +189,8 @@ def process_update(parent, query, current_thread):
|
||||
if video is None:
|
||||
continue
|
||||
|
||||
video['title'] = video['title'].replace('/', '⧸').replace('|', '|')
|
||||
|
||||
if check_already_exists(video['id']):
|
||||
add_new_video_to_collection(parent, video['id'])
|
||||
continue
|
||||
@@ -216,6 +225,8 @@ def process_update(parent, query, current_thread):
|
||||
if video is None:
|
||||
continue
|
||||
|
||||
video['title'] = video['title'].replace('/', '⧸').replace('|', '|')
|
||||
|
||||
if check_already_exists(video['id']):
|
||||
add_new_video_to_collection(parent, video['id'])
|
||||
continue
|
||||
@@ -340,7 +351,7 @@ def update_all():
|
||||
True)
|
||||
|
||||
yt_download(downloads_path() + folder, ext[1:])
|
||||
db_add_via_update(folder, ext)
|
||||
db_add_via_update(folder, ext[1:])
|
||||
return
|
||||
|
||||
|
||||
@@ -484,3 +495,12 @@ def delete_file_or_playlist(file_name):
|
||||
def check_file_path(path):
|
||||
downloads = downloads_path()
|
||||
return downloads in os.path.abspath(downloads + path)
|
||||
|
||||
|
||||
def sanitize_filename(file_name: str):
|
||||
return (file_name
|
||||
.replace('\\', '⧹')
|
||||
.replace(':', ':')
|
||||
.replace('*', '*')
|
||||
.replace('?', '?')
|
||||
.replace('"', '"'))
|
||||
|
||||
@@ -162,7 +162,7 @@ def player():
|
||||
|
||||
@frontend.route('/serve', methods=['GET'])
|
||||
def serve():
|
||||
file = request.args.get('file').replace('/', '').replace('\\', '')
|
||||
file = request.args.get('file')
|
||||
if not check_file_path(file):
|
||||
flash('Video not found', 'danger')
|
||||
return render_template('flash-message.html')
|
||||
@@ -176,6 +176,6 @@ def serve():
|
||||
elif 'mp4' in file:
|
||||
return send_file(
|
||||
downloads_path() + file,
|
||||
'video/webm',
|
||||
'video/mp4',
|
||||
True
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
{% if 'mp4' in file %}
|
||||
<div class="section d-flex justify-content-center embed-responsive embed-responsive-16by9" style="padding: 1.5%">
|
||||
<video class="embed-responsive-item" style="width: 100%; height: auto" controls>
|
||||
<source src="serve?file={{ file }}" type="video/webm">
|
||||
<source src="serve?file={{ file }}" type="video/mp4">
|
||||
</video>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user