diff --git a/configuration.default.ini b/configuration.default.ini index 2feaef3..532e73a 100644 --- a/configuration.default.ini +++ b/configuration.default.ini @@ -201,8 +201,8 @@ url_from_playlist_item = {title} from playlist url_item = {title} added by {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 = {song} is too long, removed from playlist! +download_in_progress = Download of {item} 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! diff --git a/media/file.py b/media/file.py index 0961857..980256e 100644 --- a/media/file.py +++ b/media/file.py @@ -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 diff --git a/media/playlist.py b/media/playlist.py index fac7856..1cb61dd 100644 --- a/media/playlist.py +++ b/media/playlist.py @@ -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,7 +222,14 @@ class BasePlaylist(list): if self.current_index > index: self.current_index -= 1 - var.library.free(removed.id) + # 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 def remove_by_id(self, id): @@ -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: - for i in range(current_index): - _list.pop() + if current_index > -1: + for i in range(current_index): + _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 diff --git a/media/url.py b/media/url.py index f70c841..ee1a950 100644 --- a/media/url.py +++ b/media/url.py @@ -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): - return constants.strings("url_item", - title=self.title, - url=self.url, - user=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))