fix: music not saved after downloading. some tricky oneshot problem #91

This commit is contained in:
Terry Geng 2020-03-08 10:28:03 +08:00
parent e10059a76e
commit 487b5b9616
4 changed files with 27 additions and 11 deletions

View File

@ -201,8 +201,8 @@ url_from_playlist_item = <a href="{url}"><b>{title}</b></a> <i>from playlist</i>
url_item = <a href="{url}"><b>{title}</b></a> <i>added by</i> {user}
not_in_my_channel = You're not in my channel, command refused!
pm_not_allowed = Private message aren't allowed.
too_long = {song} is too long, removed from playlist!
download_in_progress = Download of {item} in progress...
too_long = <b>{song}</b> is too long, removed from playlist!
download_in_progress = Download of <b>{item}</b> in progress...
removing_item = Removed entry {item} from playlist.
user_ban = You are banned, not allowed to do that!
url_ban = This url is banned!

View File

@ -74,7 +74,7 @@ class FileItem(BaseItem):
self.send_client_message(constants.strings('file_missed', file=self.path))
return False
self.version += 1 # 0 -> 1, notify the wrapper to save me when validate() is visited the first time
#self.version += 1 # 0 -> 1, notify the wrapper to save me when validate() is visited the first time
self.ready = "yes"
return True

View File

@ -45,7 +45,7 @@ class PlaylistItemWrapper:
def async_prepare(self):
th = threading.Thread(
target=self.item().prepare, name="Prepare-" + self.id[:7])
target=self.prepare, name="Prepare-" + self.id[:7])
self.log.info(
"%s: start preparing item in thread: " % self.item().type + self.format_debug_string())
th.daemon = True
@ -222,6 +222,13 @@ class BasePlaylist(list):
if self.current_index > index:
self.current_index -= 1
# reference counter
counter = 0
for wrapper in self:
if wrapper.id == removed.id:
counter += 1
if counter == 0:
var.library.free(removed.id)
return removed
@ -272,6 +279,7 @@ class BasePlaylist(list):
def save(self):
var.db.remove_section("playlist_item")
assert self.current_index is not None
var.db.set("playlist", "current_index", self.current_index)
for index, music in enumerate(self):
@ -331,8 +339,10 @@ class OneshotPlaylist(BasePlaylist):
def from_list(self, _list, current_index):
if len(_list) > 0:
if current_index > -1:
for i in range(current_index):
_list.pop()
_list.pop(0)
return super().from_list(_list, 0)
return super().from_list(_list, -1)
return self
@ -450,6 +460,7 @@ class AutoPlaylist(BasePlaylist):
def next(self):
if len(self) == 0:
self.refresh()
return False
self.version += 1

View File

@ -70,12 +70,15 @@ class URLItem(BaseItem):
def validate(self):
self.validating_lock.acquire()
if self.ready in ['yes', 'validated']:
self.validating_lock.release()
return True
if self.ready == 'failed':
self.validating_lock.release()
return False
if os.path.exists(self.path):
self.validating_lock.release()
self.ready = "yes"
return True
@ -219,10 +222,12 @@ class URLItem(BaseItem):
)
def format_song_string(self, user):
if self.ready in ['validated', 'yes']:
return constants.strings("url_item",
title=self.title,
url=self.url,
user=user)
return self.url
def format_current_playing(self, user):
display = constants.strings("now_playing", item=self.format_song_string(user))