refactor: new database format
This commit is contained in:
@ -51,10 +51,9 @@ class FileItem(BaseItem):
|
||||
if os.path.exists(self.uri()):
|
||||
self._get_info_from_tag()
|
||||
self.ready = "yes"
|
||||
self.keywords = self.title + " " + self.artist
|
||||
else:
|
||||
super().__init__(bot, from_dict)
|
||||
self.path = from_dict['path']
|
||||
self.title = from_dict['title']
|
||||
self.artist = from_dict['artist']
|
||||
self.thumbnail = from_dict['thumbnail']
|
||||
if not self.validate():
|
||||
@ -75,6 +74,10 @@ class FileItem(BaseItem):
|
||||
self.send_client_message(constants.strings('file_missed', file=self.path))
|
||||
return False
|
||||
|
||||
if not self.keywords:
|
||||
self.keywords = self.title + " " + self.artist # migrate from previous version
|
||||
self.version += 1
|
||||
|
||||
# self.version += 1 # 0 -> 1, notify the wrapper to save me when validate() is visited the first time
|
||||
self.ready = "yes"
|
||||
return True
|
||||
|
@ -43,6 +43,7 @@ class BaseItem:
|
||||
self.title = ""
|
||||
self.path = ""
|
||||
self.tags = []
|
||||
self.keywords = ""
|
||||
self.version = 0 # if version increase, wrapper will re-save this item
|
||||
|
||||
if from_dict is None:
|
||||
@ -52,6 +53,9 @@ class BaseItem:
|
||||
self.id = from_dict['id']
|
||||
self.ready = from_dict['ready']
|
||||
self.tags = from_dict['tags']
|
||||
self.title = from_dict['title']
|
||||
self.path = from_dict['path']
|
||||
self.keywords = from_dict['keywords']
|
||||
|
||||
def is_ready(self):
|
||||
return True if self.ready == "yes" else False
|
||||
@ -105,4 +109,10 @@ class BaseItem:
|
||||
self.bot.send_msg(msg)
|
||||
|
||||
def to_dict(self):
|
||||
return {"type": self.type, "id": self.id, "ready": self.ready, "path": self.path, "tags": self.tags}
|
||||
return {"type": self.type,
|
||||
"id": self.id,
|
||||
"ready": self.ready,
|
||||
"title": self.title,
|
||||
"path": self.path,
|
||||
"tags": self.tags,
|
||||
"keywords": self.keywords}
|
||||
|
Reference in New Issue
Block a user