fix: still one-shot

This commit is contained in:
Terry Geng 2020-03-08 19:55:41 +08:00
parent f7042db657
commit 091d303729
3 changed files with 16 additions and 19 deletions

View File

@ -275,9 +275,8 @@ help = <h3>Commands</h3>
<li> <b>!<u>li</u>stfile </b> [{pattern}] - display list of available files (that match the regex pattern if {pattern} is given) </li> <li> <b>!<u>li</u>stfile </b> [{pattern}] - display list of available files (that match the regex pattern if {pattern} is given) </li>
<li> <b>!<u>rbq</u>uery </b> {keyword} - query http://www.radio-browser.info for a radio station </li> <li> <b>!<u>rbq</u>uery </b> {keyword} - query http://www.radio-browser.info for a radio station </li>
<li> <b>!<u>rbp</u>lay </b> {id} - play a radio station with {id} (eg. !rbplay 96746) </li> <li> <b>!<u>rbp</u>lay </b> {id} - play a radio station with {id} (eg. !rbplay 96746) </li>
<li> <b>!<u>ys</u>earch </b> {keyword} - query youtube. Use <i>!ytquery -n</i> to turn the page. </li> <li> <b>!<u>ys</u>earch </b> {keywords} - query youtube. Use <i>!ytquery -n</i> to turn the page. </li>
<li> <b>!<u>yp</u>lay </b> {index/keywords} - play an item from the list returned by <i>!ytquery</i>, or add the <li> <b>!<u>yp</u>lay </b> {keywords} - add the first search result of {keywords} into the playlist.</li>
first search result of {keywords} into the playlist.</li>
</ul> </ul>
<b>Music Library</b> <b>Music Library</b>
<ul> <ul>

View File

@ -29,8 +29,9 @@ class MusicCache(dict):
self.log.debug("library: music found in database: %s" % item.format_debug_string()) self.log.debug("library: music found in database: %s" % item.format_debug_string())
return item return item
else: else:
print(id) return None
raise KeyError("Unable to fetch item from the database! Please try to refresh the cache by !recache.") #print(id)
#raise KeyError("Unable to fetch item from the database! Please try to refresh the cache by !recache.")
def get_item(self, bot, **kwargs): def get_item(self, bot, **kwargs):
@ -80,8 +81,8 @@ class MusicCache(dict):
self.db.insert_music(self[id].to_dict()) self.db.insert_music(self[id].to_dict())
def delete(self, id): def delete(self, id):
try: item = self.get_item_by_id(None, id)
item = self.get_item_by_id(None, id) if item:
self.log.debug("library: DELETE item from the database: %s" % item.format_debug_string()) self.log.debug("library: DELETE item from the database: %s" % item.format_debug_string())
if item.type == 'file' and item.path in self.file_id_lookup: if item.type == 'file' and item.path in self.file_id_lookup:
@ -93,8 +94,6 @@ class MusicCache(dict):
if item.id in self: if item.id in self:
del self[item.id] del self[item.id]
self.db.delete_music(id=item.id) self.db.delete_music(id=item.id)
except KeyError:
return
def free(self, id): def free(self, id):
if id in self: if id in self:
@ -113,13 +112,15 @@ class MusicCache(dict):
files = util.get_recursive_file_list_sorted(var.music_folder) files = util.get_recursive_file_list_sorted(var.music_folder)
self.dir = util.Dir(var.music_folder) self.dir = util.Dir(var.music_folder)
for file in files: for file in files:
item = self.get_item(bot, type='file', path=file) item = self.fetch(bot, item_id_generators['file'](path=file))
if item.validate(): if not item:
self.dir.add_file(file) item = item_builders['file'](bot, path=file)
self.files.append(file)
self.log.debug("library: music save into database: %s" % item.format_debug_string()) self.log.debug("library: music save into database: %s" % item.format_debug_string())
self.db.insert_music(item.to_dict()) self.db.insert_music(item.to_dict())
self.file_id_lookup[file] = item.id
self.dir.add_file(file)
self.files.append(file)
self.file_id_lookup[file] = item.id
self.save_dir_cache() self.save_dir_cache()
self.dir_lock.release() self.dir_lock.release()

View File

@ -354,9 +354,6 @@ class OneshotPlaylist(BasePlaylist):
return self return self
def next(self): def next(self):
if len(self) == 0:
return False
self.version += 1 self.version += 1
if len(self) > 0: if len(self) > 0:
@ -366,10 +363,10 @@ class OneshotPlaylist(BasePlaylist):
return False return False
else: else:
self.current_index = 0 self.current_index = 0
return self[0]
return self[0]
else: else:
self.clear() self.current_index = -1
return False return False
def next_index(self): def next_index(self):