Clean up parial files created by cancelled YoutubeDL downloads.

YoutubeDL can append an extension to the partial file, creating
additional partial files. Adaptive formats create up to three more
partial files. Cancelling a download will leave behind these extra
partial files, and requires manual removal outside of gPodder.
This commit is contained in:
auouymous 2022-02-01 22:09:00 -07:00
parent a3815cdf05
commit 9d72872c50
2 changed files with 15 additions and 4 deletions

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