Fixed downloads erroring out with private videos in playlist

This commit is contained in:
Maximilian Wagner
2023-08-05 10:32:59 +02:00
parent 7d18ab512b
commit f6eb82ed6a
2 changed files with 10 additions and 16 deletions

View File

@@ -40,7 +40,7 @@ def process_general(url, ext, update=False):
hour = str(current_time.hour)
hour = hour if len(hour) > 1 else '0' + hour
minute = str(current_time.minute)
minute = minute if len(minute) > 1 else '0' + hour
minute = minute if len(minute) > 1 else '0' + minute
# add url and time to list of queued downloads
queued_downloads.append([url, hour + ':' + minute])
@@ -56,7 +56,7 @@ def process_general(url, ext, update=False):
urls.clear()
# get basic info for given url
query = ydl.YoutubeDL({'quiet': True}).extract_info(url=url, download=False)
query = ydl.YoutubeDL({'quiet': True, 'ignoreerrors': True}).extract_info(url=url, download=False)
parent = query['title']
if update:
@@ -82,7 +82,7 @@ def process_download(url, ext, parent, query, current_thread):
try:
# this throws KeyError when downloading single file
for video in query['entries']:
if check_already_exists(video['id']):
if video is not None and check_already_exists(video['id']):
add_new_video_to_collection(parent, video['id'])
continue
@@ -113,7 +113,7 @@ def process_download(url, ext, parent, query, current_thread):
for tab in query['entries']:
# for every video in their respective tabs
for video in tab['entries']:
if check_already_exists(video['id']):
if video is not None and check_already_exists(video['id']):
add_new_video_to_collection(parent, video['id'])
continue
@@ -325,6 +325,7 @@ def yt_download(location, ext='mp3'):
# base download options for audio
opts = {
'quiet': True,
'ignoreerrors': True,
'windowsfilenames': True,
'outtmpl': location + '%(title)s.%(ext)s',
'format': 'bestaudio/best',
@@ -342,10 +343,7 @@ def yt_download(location, ext='mp3'):
opts.pop('postprocessors')
# try to download all new files
try:
ydl.YoutubeDL(opts).download(urls)
except ydl.DownloadError:
pass
ydl.YoutubeDL(opts).download(urls)
return

View File

@@ -61,7 +61,7 @@ def downloader():
# show download start confirmation
flash('Download enqueued and will finish in background.', 'primary')
return render_template('flash-message.html')
return redirect('/downloader')
@frontend.route('/library', methods=['GET'])
@@ -104,14 +104,10 @@ def download():
if '.' in file_path:
path, name, ext = dissect_file_name(file_path)
video = query_db('SELECT path, name, ext FROM video '
'WHERE name = :name AND path = :path AND ext = :ext',
{'name': name, 'path': path, 'ext': ext},
True)
# this is flaky for whatever reason; might be because of special chars?
return send_from_directory(
downloads_path() + video['path'],
video['name'] + video['ext']
'downloads\\' + path,
name + ext
)
# else a directory is requested