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