diff --git a/resources/lib/contentitem.py b/resources/lib/contentitem.py index b4b8776..700f7e1 100644 --- a/resources/lib/contentitem.py +++ b/resources/lib/contentitem.py @@ -78,7 +78,7 @@ def delete(self): def set_as_staged(self): ''' sets the item status as staged in database ''' - db.DB_Handler().update_content_status(self.path, 'staged') + db.DB_Handler().update_content(self.path, status='staged') def get_title(self): ''' returns title of video as string ''' @@ -118,7 +118,7 @@ def add_to_library(self): fs.rm_strm_in_dir(movie_dir) # add stream file to movie_dir fs.create_stream_file(self.path, filepath) - db.DB_Handler().update_content_status(self.path, 'managed') + db.DB_Handler().update_content(self.path, status='managed') @log_decorator def remove_from_library(self): @@ -211,7 +211,7 @@ def add_to_library(self): fs.softlink_file(landscape_path, managed_thumb_path) elif os.path.exists(fanart_path): fs.softlink_file(fanart_path, managed_thumb_path) - db.DB_Handler().update_content_status(self.path, 'managed') + db.DB_Handler().update_content(self.path, status='managed') @log_decorator def remove_from_library(self): @@ -276,7 +276,7 @@ def create_metadata_item(self): # refresh item in staged file if name changed if new_title != self.title: self.title = new_title - db.DB_Handler().update_content_title(self.path, self.title) + db.DB_Handler().update_content(self.path, title=self.title) @log_decorator def rename(self, name): @@ -294,7 +294,7 @@ def rename(self, name): fs.mv_with_type(title_path, '-thumb.jpg', new_title_path) # rename property and refresh in staged file self.title = name - db.DB_Handler().update_content_title(self.path, self.title) + db.DB_Handler().update_content(self.path, title=self.title) @log_decorator def rename_using_metadata(self): diff --git a/resources/lib/database_handler.py b/resources/lib/database_handler.py index 0e7b127..53b8ce5 100644 --- a/resources/lib/database_handler.py +++ b/resources/lib/database_handler.py @@ -147,22 +147,19 @@ def add_content_item(self, path, title, mediatype, show_title=None): @utf8_decorator @log_decorator - def update_content_status(self, path, status): - ''' Updates Status for item in Content with specified path ''' - # update item - self.c.execute( - "UPDATE Content SET Status=(?) WHERE Directory=?", - (status, path)) - self.db.commit() - - @utf8_decorator - @log_decorator - def update_content_title(self, path, title): - ''' Updates title for item in Content with specified path ''' + def update_content(self, path, **kwargs): + ''' Updates a single field for item in Content with specified path ''' + #TODO: verify there's only one entry in kwargs + sql_comm = "UPDATE Content SET {0}=(?) WHERE Directory=?" + params = (path,) + for k, v in kwargs.iteritems(): + if k == 'status': + sql_comm = sql_comm.format('Status') + elif k == 'title': + sql_comm = sql_comm.format('Title') + params = (v,) + params # update item - self.c.execute( - "UPDATE Content SET Title=(?) WHERE Directory=?", - (title, path)) + self.c.execute(sql_comm, params) self.db.commit() @utf8_decorator diff --git a/resources/lib/update_pkl.py b/resources/lib/update_pkl.py index c52b3f9..83b0bbe 100644 --- a/resources/lib/update_pkl.py +++ b/resources/lib/update_pkl.py @@ -28,7 +28,7 @@ def update_managed(): elif item.get_mediatype() == 'tvshow': dbh.add_content_item(item.get_path(), item.get_title(), 'tvshow', \ item.get_show_title()) - dbh.update_content_status(item.get_path(), 'managed') + dbh.update_content(item.get_path(), status='managed') os.remove(managed_file) @log_decorator