]> git.0d.be Git - botaradio.git/commitdiff
fix: music not saved after downloading. some tricky oneshot problem #91
authorTerry Geng <gengyanda@gmail.com>
Sun, 8 Mar 2020 02:28:03 +0000 (10:28 +0800)
committerTerry Geng <gengyanda@gmail.com>
Sun, 8 Mar 2020 02:28:03 +0000 (10:28 +0800)
configuration.default.ini
media/file.py
media/playlist.py
media/url.py

index 2feaef356cf696f7917f123f30dd994e64f57f79..532e73a88a958a168867ff0c3da7a80821fc04ab 100644 (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!
index 096185794026f2128adeaa2686dcfa88069e18b2..980256ecfc21849f3d73407dc122112c800c932d 100644 (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
 
index fac78568240eef206041d9292eb8da59ad75af79..1cb61ddd494c3f8ce496eccfe96a37367ac580c8 100644 (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,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
index f70c841783e82ee413facd404fed26f30b89ccd0..ee1a95052e0de93e7ed778c88250945c09feea42 100644 (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):
-        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))