Merge pull request #1219 from auouymous/ytdl-partial-files

YoutubeDL partial file fixes
This commit is contained in:
auouymous 2022-02-07 23:17:42 -07:00 committed by GitHub
commit 8f9b95bfb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 16 deletions

View File

@ -99,18 +99,16 @@ class YoutubeCustomDownload(download.CustomDownload):
# See #673 when merging multiple formats, the extension is appended to the tempname
# by YoutubeDL resulting in empty .partial file + .partial.mp4 exists
# and #796 .mkv is chosen by ytdl sometimes
tempstat = os.stat(tempname)
if not tempstat.st_size:
for try_ext in (dot_ext, ".mp4", ".m4a", ".webm", ".mkv"):
tempname_with_ext = tempname + try_ext
if os.path.isfile(tempname_with_ext):
logger.debug('Youtubedl downloaded to "%s" instead of "%s", moving',
os.path.basename(tempname_with_ext),
os.path.basename(tempname))
os.remove(tempname)
os.rename(tempname_with_ext, tempname)
dot_ext = try_ext
break
for try_ext in (dot_ext, ".mp4", ".m4a", ".webm", ".mkv"):
tempname_with_ext = tempname + try_ext
if os.path.isfile(tempname_with_ext):
logger.debug('Youtubedl downloaded to "%s" instead of "%s", moving',
os.path.basename(tempname_with_ext),
os.path.basename(tempname))
os.remove(tempname)
os.rename(tempname_with_ext, tempname)
dot_ext = try_ext
break
ext_filetype = mimetype_from_extension(dot_ext)
if ext_filetype:
# Youtube weba formats have a webm extension and get a video/webm mime-type

View File

@ -40,6 +40,8 @@ def clean_up_downloads(delete_partial=False):
if delete_partial:
temporary_files += glob.glob('%s/*/*.partial' % gpodder.downloads)
# YoutubeDL creates .partial.* files for adaptive formats
temporary_files += glob.glob('%s/*/*.partial.*' % gpodder.downloads)
for tempfile in temporary_files:
util.delete_file(tempfile)
@ -53,7 +55,7 @@ def find_partial_downloads(channels, start_progress_callback, progress_callback,
progress_callback - A callback(title, progress) when an episode was found
finish_progress_callback - A callback(resumable_episodes) when finished
"""
# Look for partial file downloads
# Look for partial file downloads, ignoring .partial.* files created by YoutubeDL
partial_files = glob.glob(os.path.join(gpodder.downloads, '*', '*.partial'))
count = len(partial_files)
resumable_episodes = []

View File

@ -27,6 +27,7 @@
import collections
import email
import glob
import logging
import mimetypes
import os
@ -631,9 +632,17 @@ class DownloadTask(object):
elif self.status == self.DOWNLOADING:
self.status = self.CANCELLING
def delete_partial_files(self):
temporary_files = [self.tempname]
# YoutubeDL creates .partial.* files for adaptive formats
temporary_files += glob.glob('%s.*' % self.tempname)
for tempfile in temporary_files:
util.delete_file(tempfile)
def removed_from_list(self):
if self.status != self.DONE:
util.delete_file(self.tempname)
self.delete_partial_files()
def __init__(self, episode, config, downloader=None):
assert episode.download_task is None
@ -791,7 +800,7 @@ class DownloadTask(object):
with self:
if self.status == DownloadTask.CANCELLING:
self.status = DownloadTask.CANCELLED
util.delete_file(self.tempname)
self.delete_partial_files()
self.progress = 0.0
self.speed = 0.0
self.recycle()
@ -892,7 +901,7 @@ class DownloadTask(object):
except DownloadCancelledException:
logger.info('Download has been cancelled/paused: %s', self)
if self.status == DownloadTask.CANCELLING:
util.delete_file(self.tempname)
self.delete_partial_files()
self.progress = 0.0
self.speed = 0.0
result = DownloadTask.CANCELLED