|
@@ -91,44 +91,54 @@ class db(object):
|
|
self.__version = 2
|
|
self.__version = 2
|
|
if int(self.__version) == 2:
|
|
if int(self.__version) == 2:
|
|
"""Changes between version 2 and 3"""
|
|
"""Changes between version 2 and 3"""
|
|
- self.__ExecuteStatement("ALTER TABLE subscriptions ADD COLUMN disabled \
|
|
|
|
- INTEGER DEFAULT 0;")
|
|
|
|
|
|
+ self.__ExecuteStatement("ALTER TABLE subscriptions ADD COLUMN"
|
|
|
|
+ " disabled INTEGER DEFAULT 0;")
|
|
self.__ExecuteStatement("UPDATE subscriptions SET disabled=0;")
|
|
self.__ExecuteStatement("UPDATE subscriptions SET disabled=0;")
|
|
- self.__version=3
|
|
|
|
|
|
+ self.__version = 3
|
|
|
|
|
|
def GetVersion(self):
|
|
def GetVersion(self):
|
|
"""Simple getter method, returns the DB version"""
|
|
"""Simple getter method, returns the DB version"""
|
|
|
|
|
|
return self.__version
|
|
return self.__version
|
|
|
|
|
|
- def DeleteSubscription(self, id):
|
|
|
|
- """Deletes a subscription and all associated videos from the database"""
|
|
|
|
|
|
+ def DeleteSubscription(self, sub_id):
|
|
|
|
+ """Deletes a subscription and all associated videos from the
|
|
|
|
+ database
|
|
|
|
+
|
|
|
|
+ """
|
|
|
|
|
|
checkquery = "SELECT * FROM subscriptions WHERE id=?"
|
|
checkquery = "SELECT * FROM subscriptions WHERE id=?"
|
|
- checkresult = self.__ExecuteStatement(checkquery, (id,))
|
|
|
|
- if checkresult.fetchall() == []:
|
|
|
|
|
|
+ checkresult = self.__ExecuteStatement(checkquery, (sub_id,))
|
|
|
|
+ if not checkresult.fetchall():
|
|
raise stov_exceptions.SubscriptionNotFoundException()
|
|
raise stov_exceptions.SubscriptionNotFoundException()
|
|
else:
|
|
else:
|
|
deletevideos = "DELETE FROM videos WHERE subscription_id=?"
|
|
deletevideos = "DELETE FROM videos WHERE subscription_id=?"
|
|
- self.__ExecuteStatement(deletevideos, (id,))
|
|
|
|
|
|
+ self.__ExecuteStatement(deletevideos, (sub_id,))
|
|
deletesubscription = "DELETE FROM subscriptions WHERE id=?"
|
|
deletesubscription = "DELETE FROM subscriptions WHERE id=?"
|
|
- self.__ExecuteStatement(deletesubscription, (id,))
|
|
|
|
|
|
+ self.__ExecuteStatement(deletesubscription, (sub_id,))
|
|
message = "Subscription deleted successfully!"
|
|
message = "Subscription deleted successfully!"
|
|
return message
|
|
return message
|
|
|
|
|
|
- def GetVideos(self, id):
|
|
|
|
- """Gets all videos of a given subscription id from the database and returns them"""
|
|
|
|
- video_query = "SELECT id, title, description, ytid, downloaded, failcnt FROM videos WHERE subscription_id=?"
|
|
|
|
- cursor = self.__ExecuteStatement(video_query, (id,))
|
|
|
|
|
|
+ def GetVideos(self, video_id):
|
|
|
|
+ """Gets all videos of a given subscription id from the database and
|
|
|
|
+ returns them
|
|
|
|
+
|
|
|
|
+ """
|
|
|
|
+ video_query = "SELECT id, title, description, ytid, downloaded, " \
|
|
|
|
+ "failcnt FROM videos WHERE subscription_id=?"
|
|
|
|
+ cursor = self.__ExecuteStatement(video_query, (video_id,))
|
|
result = cursor.fetchall()
|
|
result = cursor.fetchall()
|
|
return result
|
|
return result
|
|
|
|
|
|
def VideoInDatabase(self, ytid):
|
|
def VideoInDatabase(self, ytid):
|
|
- """Checks if the video with a given youtube id already exists in the database"""
|
|
|
|
|
|
+ """Checks if the video with a given youtube id already exists in the
|
|
|
|
+ database
|
|
|
|
+
|
|
|
|
+ """
|
|
video_query = "SELECT id FROM videos WHERE ytid=?"
|
|
video_query = "SELECT id FROM videos WHERE ytid=?"
|
|
cursor = self.__ExecuteStatement(video_query, (ytid,))
|
|
cursor = self.__ExecuteStatement(video_query, (ytid,))
|
|
result = cursor.fetchall()
|
|
result = cursor.fetchall()
|
|
- if result == []:
|
|
|
|
|
|
+ if not result:
|
|
return False
|
|
return False
|
|
else:
|
|
else:
|
|
return True
|
|
return True
|
|
@@ -146,8 +156,9 @@ class db(object):
|
|
|
|
|
|
def InsertSubscription(self, data):
|
|
def InsertSubscription(self, data):
|
|
"""Inserts a subscription with the given data into the database"""
|
|
"""Inserts a subscription with the given data into the database"""
|
|
- subscription_insert = "INSERT INTO subscriptions (title, type, searchstring, \
|
|
|
|
- directory, name, disabled) VALUES (?, ?, ?, ?, ?, ?)"
|
|
|
|
|
|
+ subscription_insert = "INSERT INTO subscriptions (title, type, " \
|
|
|
|
+ "searchstring, directory, name, disabled) " \
|
|
|
|
+ "VALUES (?, ?, ?, ?, ?, ?)"
|
|
self.__ExecuteStatement(subscription_insert, data)
|
|
self.__ExecuteStatement(subscription_insert, data)
|
|
subscription_getid = "SELECT id from subscriptions where title=?"
|
|
subscription_getid = "SELECT id from subscriptions where title=?"
|
|
query_cursor = self.__ExecuteStatement(subscription_getid, (data[0],))
|
|
query_cursor = self.__ExecuteStatement(subscription_getid, (data[0],))
|
|
@@ -155,48 +166,49 @@ class db(object):
|
|
message = "Subscription sucessfully inserted into database."
|
|
message = "Subscription sucessfully inserted into database."
|
|
return (message, subscription_id)
|
|
return (message, subscription_id)
|
|
|
|
|
|
- def UpdateVideoDownloadStatus(self, id, status):
|
|
|
|
|
|
+ def UpdateVideoDownloadStatus(self, video_id, status):
|
|
"""Updates the download status of a video in the database"""
|
|
"""Updates the download status of a video in the database"""
|
|
update_statement = "UPDATE videos SET downloaded = ? WHERE id = ?"
|
|
update_statement = "UPDATE videos SET downloaded = ? WHERE id = ?"
|
|
- result = self.__ExecuteStatement(update_statement, (status, id))
|
|
|
|
|
|
+ self.__ExecuteStatement(update_statement, (status, video_id))
|
|
|
|
|
|
- def DisableFailedVideo(self, id):
|
|
|
|
|
|
+ def DisableFailedVideo(self, video_id):
|
|
"""Disables a video in the database"""
|
|
"""Disables a video in the database"""
|
|
update_statement = "UPDATE videos SET downloaded = -1 WHERE id = ?"
|
|
update_statement = "UPDATE videos SET downloaded = -1 WHERE id = ?"
|
|
- self.__ExecuteStatement(update_statement, (id,))
|
|
|
|
|
|
+ self.__ExecuteStatement(update_statement, (video_id,))
|
|
|
|
|
|
- def UpdateVideoFailCount(self,count, id):
|
|
|
|
|
|
+ def UpdateVideoFailCount(self, count, video_id):
|
|
"""Updates the fail count of a video in the database"""
|
|
"""Updates the fail count of a video in the database"""
|
|
update_statement = "UPDATE videos SET failcnt = ? WHERE id = ?"
|
|
update_statement = "UPDATE videos SET failcnt = ? WHERE id = ?"
|
|
- self.__ExecuteStatement(update_statement, (count, id))
|
|
|
|
|
|
+ self.__ExecuteStatement(update_statement, (count, video_id))
|
|
|
|
|
|
- def DeleteVideo(self,id):
|
|
|
|
|
|
+ def DeleteVideo(self, video_id):
|
|
"""Deletes a video from the database"""
|
|
"""Deletes a video from the database"""
|
|
delete_statement = "DELETE FROM videos where id = ?"
|
|
delete_statement = "DELETE FROM videos where id = ?"
|
|
- self.__ExecuteStatement(delete_statement, (id,))
|
|
|
|
|
|
+ self.__ExecuteStatement(delete_statement, (video_id,))
|
|
|
|
|
|
- def GetSubscription(self, id):
|
|
|
|
|
|
+ def GetSubscription(self, sub_id):
|
|
"""Retrieves a specific subscription from the database"""
|
|
"""Retrieves a specific subscription from the database"""
|
|
sub_query = "SELECT id,title,type,name,searchstring, directory," \
|
|
sub_query = "SELECT id,title,type,name,searchstring, directory," \
|
|
"disabled FROM subscriptions where id=?"
|
|
"disabled FROM subscriptions where id=?"
|
|
- result_cursor = self.__ExecuteStatement(sub_query, (id,))
|
|
|
|
|
|
+ result_cursor = self.__ExecuteStatement(sub_query, (sub_id,))
|
|
result = result_cursor.fetchall()
|
|
result = result_cursor.fetchall()
|
|
return result
|
|
return result
|
|
|
|
|
|
- def GetSubscriptionTitle(self, id):
|
|
|
|
|
|
+ def GetSubscriptionTitle(self, sub_id):
|
|
"""Retrieves only the title of a specified subscription from the
|
|
"""Retrieves only the title of a specified subscription from the
|
|
database
|
|
database
|
|
|
|
|
|
"""
|
|
"""
|
|
title_query = "SELECT title from subscriptions where id=?"
|
|
title_query = "SELECT title from subscriptions where id=?"
|
|
- result_cursor = self.__ExecuteStatement(title_query, (id,))
|
|
|
|
|
|
+ result_cursor = self.__ExecuteStatement(title_query, (sub_id,))
|
|
result = result_cursor.fetchall()
|
|
result = result_cursor.fetchall()
|
|
return result
|
|
return result
|
|
|
|
|
|
- def MarkVideosDownloaded(self, id):
|
|
|
|
|
|
+ def MarkVideosDownloaded(self, video_id):
|
|
""" Marks all videos in a specified subscription as downloaded"""
|
|
""" Marks all videos in a specified subscription as downloaded"""
|
|
- update_statement = "UPDATE videos SET downloaded = 1 WHERE subscription_id =?"
|
|
|
|
- self.__ExecuteStatement(update_statement, (id,))
|
|
|
|
|
|
+ update_statement = "UPDATE videos SET downloaded = 1 " \
|
|
|
|
+ "WHERE subscription_id =?"
|
|
|
|
+ self.__ExecuteStatement(update_statement, (video_id,))
|
|
|
|
|
|
def GetSubscriptions(self):
|
|
def GetSubscriptions(self):
|
|
"""Retrieves all subscriptions from the database"""
|
|
"""Retrieves all subscriptions from the database"""
|
|
@@ -210,10 +222,10 @@ class db(object):
|
|
"""Vacuums the database, shrinking it in size"""
|
|
"""Vacuums the database, shrinking it in size"""
|
|
self.__ExecuteStatement("VACUUM")
|
|
self.__ExecuteStatement("VACUUM")
|
|
|
|
|
|
- def ChangeSubscriptionState(self, id, state):
|
|
|
|
|
|
+ def ChangeSubscriptionState(self, sub_id, state):
|
|
"""Enables or disables a subscription depending on the parameter
|
|
"""Enables or disables a subscription depending on the parameter
|
|
state
|
|
state
|
|
|
|
|
|
"""
|
|
"""
|
|
update_statement = "UPDATE subscriptions SET disabled=? WHERE id=?"
|
|
update_statement = "UPDATE subscriptions SET disabled=? WHERE id=?"
|
|
- self.__ExecuteStatement(update_statement, (state,id))
|
|
|
|
|
|
+ self.__ExecuteStatement(update_statement, (state, sub_id))
|