mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[Audio] Don't remove active .part files (#1481)
This commit is contained in:
parent
bd77fedee3
commit
e874e6aa01
@ -360,14 +360,15 @@ class Audio:
|
|||||||
self.queue[server.id][QueueKey.QUEUE].appendleft(queued_song)
|
self.queue[server.id][QueueKey.QUEUE].appendleft(queued_song)
|
||||||
|
|
||||||
def _cache_desired_files(self):
|
def _cache_desired_files(self):
|
||||||
filelist = []
|
filelist = set()
|
||||||
|
|
||||||
for server in self.downloaders:
|
for server in self.downloaders:
|
||||||
song = self.downloaders[server].song
|
song = self.downloaders[server].song
|
||||||
try:
|
try:
|
||||||
filelist.append(song.id)
|
filelist.add(song.id)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
shuffle(filelist)
|
|
||||||
return filelist
|
return filelist
|
||||||
|
|
||||||
def _cache_max(self):
|
def _cache_max(self):
|
||||||
@ -380,13 +381,15 @@ class Audio:
|
|||||||
|
|
||||||
def _cache_required_files(self):
|
def _cache_required_files(self):
|
||||||
queue = copy.deepcopy(self.queue)
|
queue = copy.deepcopy(self.queue)
|
||||||
filelist = []
|
filelist = set()
|
||||||
|
|
||||||
for server in queue:
|
for server in queue:
|
||||||
now_playing = queue[server].get(QueueKey.NOW_PLAYING)
|
now_playing = queue[server].get(QueueKey.NOW_PLAYING)
|
||||||
try:
|
try:
|
||||||
filelist.append(now_playing.id)
|
filelist.add(now_playing.id)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return filelist
|
return filelist
|
||||||
|
|
||||||
def _cache_size(self):
|
def _cache_size(self):
|
||||||
@ -552,16 +555,22 @@ class Audio:
|
|||||||
prev_size = self._cache_size()
|
prev_size = self._cache_size()
|
||||||
|
|
||||||
for file in os.listdir(self.cache_path):
|
for file in os.listdir(self.cache_path):
|
||||||
if file not in reqd:
|
if file in reqd:
|
||||||
if ignore_desired or file not in opt:
|
continue
|
||||||
try:
|
elif not ignore_desired:
|
||||||
os.remove(os.path.join(self.cache_path, file))
|
if file in opt:
|
||||||
except OSError:
|
continue
|
||||||
# A directory got in the cache?
|
elif file.endswith('.part') and file[:-5] in opt:
|
||||||
pass
|
continue
|
||||||
except WindowsError:
|
|
||||||
# Removing a file in use, reqd failed
|
try:
|
||||||
pass
|
os.remove(os.path.join(self.cache_path, file))
|
||||||
|
except OSError:
|
||||||
|
# A directory got in the cache?
|
||||||
|
pass
|
||||||
|
except WindowsError:
|
||||||
|
# Removing a file in use, reqd failed
|
||||||
|
pass
|
||||||
|
|
||||||
post_size = self._cache_size()
|
post_size = self._cache_size()
|
||||||
dumped = prev_size - post_size
|
dumped = prev_size - post_size
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user