mirror of
https://github.com/azlux/botamusique
synced 2024-11-23 22:06:09 +00:00
Compare commits
No commits in common. "3200c83fd0e9415c3aa4c7cd1d7cd5036f6ca2bd" and "33a9e75ba9d0a382f7a76d23a0ceb626924a8b49" have entirely different histories.
3200c83fd0
...
33a9e75ba9
@ -46,7 +46,6 @@ class BasePlaylist(list):
|
||||
self.pending_items = []
|
||||
self.log = logging.getLogger("bot")
|
||||
self.validating_thread_lock = threading.Lock()
|
||||
self.playlist_lock = threading.RLock()
|
||||
|
||||
def is_empty(self):
|
||||
return True if len(self) == 0 else False
|
||||
@ -60,18 +59,16 @@ class BasePlaylist(list):
|
||||
return self
|
||||
|
||||
def append(self, item: CachedItemWrapper):
|
||||
with self.playlist_lock:
|
||||
self.version += 1
|
||||
super().append(item)
|
||||
self.pending_items.append(item)
|
||||
|
||||
self.async_validate()
|
||||
|
||||
return item
|
||||
|
||||
def insert(self, index, item):
|
||||
with self.playlist_lock:
|
||||
self.version += 1
|
||||
|
||||
if index == -1:
|
||||
index = self.current_index
|
||||
|
||||
@ -81,26 +78,18 @@ class BasePlaylist(list):
|
||||
self.current_index += 1
|
||||
|
||||
self.pending_items.append(item)
|
||||
|
||||
self.async_validate()
|
||||
|
||||
return item
|
||||
|
||||
def extend(self, items):
|
||||
print("extend to-enter")
|
||||
with self.playlist_lock:
|
||||
print("extend enter")
|
||||
self.version += 1
|
||||
super().extend(items)
|
||||
self.pending_items.extend(items)
|
||||
|
||||
print("extend leave")
|
||||
|
||||
self.async_validate()
|
||||
return items
|
||||
|
||||
def next(self):
|
||||
with self.playlist_lock:
|
||||
if len(self) == 0:
|
||||
return False
|
||||
|
||||
@ -111,12 +100,10 @@ class BasePlaylist(list):
|
||||
return False
|
||||
|
||||
def point_to(self, index):
|
||||
with self.playlist_lock:
|
||||
if -1 <= index < len(self):
|
||||
self.current_index = index
|
||||
|
||||
def find(self, id):
|
||||
with self.playlist_lock:
|
||||
for index, wrapper in enumerate(self):
|
||||
if wrapper.item.id == id:
|
||||
return index
|
||||
@ -126,7 +113,6 @@ class BasePlaylist(list):
|
||||
return self.remove(key)
|
||||
|
||||
def remove(self, index):
|
||||
with self.playlist_lock:
|
||||
self.version += 1
|
||||
if index > len(self) - 1:
|
||||
return False
|
||||
@ -160,28 +146,24 @@ class BasePlaylist(list):
|
||||
self.remove(index)
|
||||
|
||||
def current_item(self):
|
||||
with self.playlist_lock:
|
||||
if len(self) == 0:
|
||||
return False
|
||||
|
||||
return self[self.current_index]
|
||||
|
||||
def next_index(self):
|
||||
with self.playlist_lock:
|
||||
if self.current_index < len(self) - 1:
|
||||
return self.current_index + 1
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
def next_item(self):
|
||||
with self.playlist_lock:
|
||||
if self.current_index < len(self) - 1:
|
||||
return self[self.current_index + 1]
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
def randomize(self):
|
||||
with self.playlist_lock:
|
||||
# current_index will lose track after shuffling, thus we take current music out before shuffling
|
||||
# current = self.current_item()
|
||||
# del self[self.current_index]
|
||||
@ -193,15 +175,12 @@ class BasePlaylist(list):
|
||||
self.version += 1
|
||||
|
||||
def clear(self):
|
||||
with self.playlist_lock:
|
||||
self.version += 1
|
||||
self.current_index = -1
|
||||
var.cache.free_all()
|
||||
super().clear()
|
||||
|
||||
var.cache.free_all()
|
||||
|
||||
def save(self):
|
||||
with self.playlist_lock:
|
||||
var.db.remove_section("playlist_item")
|
||||
assert self.current_index is not None
|
||||
var.db.set("playlist", "current_index", self.current_index)
|
||||
@ -264,8 +243,8 @@ class BasePlaylist(list):
|
||||
self.log.debug("playlist: validating failed.")
|
||||
if var.bot:
|
||||
var.bot.send_channel_msg(e.msg)
|
||||
self.remove_by_id(item.id)
|
||||
var.cache.free_and_delete(item.id)
|
||||
self.remove_by_id(item.id)
|
||||
continue
|
||||
|
||||
if item.version > ver:
|
||||
@ -282,18 +261,12 @@ class OneshotPlaylist(BasePlaylist):
|
||||
self.current_index = -1
|
||||
|
||||
def current_item(self):
|
||||
with self.playlist_lock:
|
||||
if len(self) == 0:
|
||||
self.current_index = -1
|
||||
return False
|
||||
|
||||
if self.current_index == -1:
|
||||
self.current_index = 0
|
||||
|
||||
return self[self.current_index]
|
||||
|
||||
def from_list(self, _list, current_index):
|
||||
with self.playlist_lock:
|
||||
if len(_list) > 0:
|
||||
if current_index > -1:
|
||||
for i in range(current_index):
|
||||
@ -303,7 +276,6 @@ class OneshotPlaylist(BasePlaylist):
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
with self.playlist_lock:
|
||||
if len(self) > 0:
|
||||
self.version += 1
|
||||
|
||||
@ -332,7 +304,6 @@ class OneshotPlaylist(BasePlaylist):
|
||||
return False
|
||||
|
||||
def point_to(self, index):
|
||||
with self.playlist_lock:
|
||||
self.version += 1
|
||||
self.current_index = -1
|
||||
for i in range(index):
|
||||
@ -345,7 +316,6 @@ class RepeatPlaylist(BasePlaylist):
|
||||
self.mode = "repeat"
|
||||
|
||||
def next(self):
|
||||
with self.playlist_lock:
|
||||
if len(self) == 0:
|
||||
return False
|
||||
|
||||
@ -357,15 +327,12 @@ class RepeatPlaylist(BasePlaylist):
|
||||
return self[0]
|
||||
|
||||
def next_index(self):
|
||||
with self.playlist_lock:
|
||||
if self.current_index < len(self) - 1:
|
||||
return self.current_index + 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def next_item(self):
|
||||
if len(self) == 0:
|
||||
return False
|
||||
return self[self.next_index()]
|
||||
|
||||
|
||||
@ -380,7 +347,6 @@ class RandomPlaylist(BasePlaylist):
|
||||
return super().from_list(_list, -1)
|
||||
|
||||
def next(self):
|
||||
with self.playlist_lock:
|
||||
if len(self) == 0:
|
||||
return False
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user