|
@@ -365,3 +365,32 @@ def catchup(database, sub_id):
|
|
|
else:
|
|
|
LOGGER.error(_("The subscription could not be updated, "
|
|
|
"please check if the ID given is correct."))
|
|
|
+
|
|
|
+
|
|
|
+def clean_database(database, conf):
|
|
|
+ """
|
|
|
+ Initiates a database cleanup, deleting all videos that are no longer
|
|
|
+ in the scope of the query and vacuuming the database to free up space.
|
|
|
+
|
|
|
+ :param database: database object
|
|
|
+ :type database: lib_stov.database.Db
|
|
|
+ :param conf: configuration object
|
|
|
+ :type conf: lib_stov.configuration.Conf
|
|
|
+ """
|
|
|
+ subscription_list = database.get_subscriptions(conf)
|
|
|
+ for element in subscription_list:
|
|
|
+ videos = database.get_videos(element.get_id(), conf)
|
|
|
+ element.check_and_delete(videos)
|
|
|
+ for delete_video in element.to_delete:
|
|
|
+ LOGGER.debug(_("Deleting video %s from "
|
|
|
+ "database"), delete_video.title)
|
|
|
+ try:
|
|
|
+ database.delete_video(delete_video.get_id())
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as error:
|
|
|
+ LOGGER.error(error)
|
|
|
+ sys.exit(1)
|
|
|
+ try:
|
|
|
+ database.vacuum()
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as error:
|
|
|
+ LOGGER.error(error)
|
|
|
+ sys.exit(1)
|