feat: add tags, remove tags, play tags, find tags #91
This commit is contained in:
@ -44,6 +44,7 @@ class BaseItem:
|
||||
else:
|
||||
self.id = from_dict['id']
|
||||
self.ready = from_dict['ready']
|
||||
self.tags = from_dict['tags']
|
||||
|
||||
def is_ready(self):
|
||||
return True if self.ready == "yes" else False
|
||||
@ -60,14 +61,21 @@ class BaseItem:
|
||||
def prepare(self):
|
||||
return True
|
||||
|
||||
def add_tag(self, tag):
|
||||
if tag not in self.tags:
|
||||
self.tags.append(tag)
|
||||
self.version += 1
|
||||
def add_tags(self, tags):
|
||||
for tag in tags:
|
||||
if tag not in self.tags:
|
||||
self.tags.append(tag)
|
||||
self.version += 1
|
||||
|
||||
def remove_tag(self, tag):
|
||||
if tag not in self.tags:
|
||||
self.tags.remove(tag)
|
||||
def remove_tags(self, tags):
|
||||
for tag in tags:
|
||||
if tag in self.tags:
|
||||
self.tags.remove(tag)
|
||||
self.version += 1
|
||||
|
||||
def clear_tags(self):
|
||||
if len(self.tags) > 0:
|
||||
self.tags = []
|
||||
self.version += 1
|
||||
|
||||
def format_song_string(self, user):
|
||||
|
@ -51,11 +51,12 @@ class MusicLibrary(dict):
|
||||
def get_items_by_tags(self, bot, tags):
|
||||
music_dicts = self.db.query_music_by_tags(tags)
|
||||
items = []
|
||||
for music_dict in music_dicts:
|
||||
id = music_dicts['id']
|
||||
type = music_dict['type']
|
||||
self[id] = item_loaders[type](bot, music_dict)
|
||||
items.append(self[id])
|
||||
if music_dicts:
|
||||
for music_dict in music_dicts:
|
||||
id = music_dict['id']
|
||||
type = music_dict['type']
|
||||
self[id] = item_loaders[type](bot, music_dict)
|
||||
items.append(self[id])
|
||||
|
||||
return items
|
||||
|
||||
|
@ -55,14 +55,20 @@ class PlaylistItemWrapper:
|
||||
def uri(self):
|
||||
return self.item().uri()
|
||||
|
||||
def add_tag(self, tag):
|
||||
self.item().add_tag(tag)
|
||||
def add_tags(self, tags):
|
||||
self.item().add_tags(tags)
|
||||
if self.item().version > self.version:
|
||||
self.version = self.item().version
|
||||
self.lib.save(self.id)
|
||||
|
||||
def remove_tag(self, tag):
|
||||
self.item().remove_tag(tag)
|
||||
def remove_tags(self, tags):
|
||||
self.item().remove_tags(tags)
|
||||
if self.item().version > self.version:
|
||||
self.version = self.item().version
|
||||
self.lib.save(self.id)
|
||||
|
||||
def clear_tags(self):
|
||||
self.item().clear_tags()
|
||||
if self.item().version > self.version:
|
||||
self.version = self.item().version
|
||||
self.lib.save(self.id)
|
||||
|
Reference in New Issue
Block a user