|
@@ -166,7 +166,7 @@ def delete_subscription(database, sub_id):
|
|
|
LOGGER.info(_("Subscription deleted successfully!"))
|
|
|
|
|
|
|
|
|
-def update_subscriptions(database, conf):
|
|
|
+def update_subscriptions(database, conf, subscriptions=None):
|
|
|
"""
|
|
|
Updates data about videos in a subscription.
|
|
|
|
|
@@ -174,8 +174,10 @@ def update_subscriptions(database, conf):
|
|
|
:type conf: lib_stov.configuration.Conf
|
|
|
:param database: database object
|
|
|
:type database: lib_stov.database.Db
|
|
|
+ :param subscriptions: list of subscriptions to update
|
|
|
+ :type subscriptions: list
|
|
|
"""
|
|
|
- subscriptions_list = database.get_subscriptions(conf)
|
|
|
+ subscriptions_list = get_subscriptions(conf, database, subscriptions)
|
|
|
for element in subscriptions_list:
|
|
|
LOGGER.debug(_("Updating subscription %s"), element.get_title())
|
|
|
videos = database.get_videos(element.get_id(), conf)
|
|
@@ -200,7 +202,7 @@ def update_subscriptions(database, conf):
|
|
|
"database."), video.title)
|
|
|
|
|
|
|
|
|
-def download_videos(database, conf):
|
|
|
+def download_videos(database, conf, subscriptions=None):
|
|
|
"""
|
|
|
Downloads videos that haven't been previously downloaded.
|
|
|
|
|
@@ -208,12 +210,14 @@ def download_videos(database, conf):
|
|
|
:type conf: lib_stov.configuration.Conf
|
|
|
:param database: database object
|
|
|
:type database: lib_stov.database.Db
|
|
|
+ :param subscriptions: list of subscriptions to consider for downloading
|
|
|
+ :type subscriptions: list
|
|
|
:return: tuple containing (in that order) downloaded videos, failed \
|
|
|
videos and a list of the videos downloaded
|
|
|
:rtype: tuple
|
|
|
"""
|
|
|
video_titles = []
|
|
|
- subscriptions_list = database.get_subscriptions(conf)
|
|
|
+ subscriptions_list = get_subscriptions(conf, database, subscriptions)
|
|
|
videos_downloaded = 0
|
|
|
videos_failed = 0
|
|
|
for sub in subscriptions_list:
|
|
@@ -467,7 +471,7 @@ def print_license():
|
|
|
along with stov. If not, see <http://www.gnu.org/licenses/>.""")
|
|
|
|
|
|
|
|
|
-def download_notify(database, conf):
|
|
|
+def download_notify(database, conf, subscriptions=None):
|
|
|
"""
|
|
|
starts an update of not yet downloaded videos and notifies the user
|
|
|
|
|
@@ -475,9 +479,11 @@ def download_notify(database, conf):
|
|
|
:type database: lib_stov.database.Db
|
|
|
:param conf: configuration object
|
|
|
:type conf: lib_stov.configuration.Conf
|
|
|
+ :param subscriptions: list of subscriptions to consider for downloading
|
|
|
+ :type subscriptions: list
|
|
|
"""
|
|
|
videos_downloaded, videos_failed, video_titles = \
|
|
|
- download_videos(database, conf)
|
|
|
+ download_videos(database, conf, subscriptions)
|
|
|
if videos_downloaded > 0 and conf.values["notify"] == "yes":
|
|
|
msg = compose_email(conf, videos_downloaded, video_titles)
|
|
|
send_email(conf, msg)
|
|
@@ -525,3 +531,40 @@ def list_sites(database):
|
|
|
LOGGER.info(_("Sites currently supported by stov:"))
|
|
|
for entry in sites:
|
|
|
LOGGER.info(entry[1])
|
|
|
+
|
|
|
+
|
|
|
+def get_subscriptions(conf, database, subscriptions=None):
|
|
|
+ """
|
|
|
+ Retrieves all or only specific subscriptions from the database and
|
|
|
+ returns them as a list of subscription objects.
|
|
|
+
|
|
|
+ :param conf: configuration object
|
|
|
+ :type conf: lib_stov.configuration.Conf
|
|
|
+ :param database: database object
|
|
|
+ :type database: lib_stov.database.Db
|
|
|
+ :param subscriptions: list of subscriptions to retrieve
|
|
|
+ :type subscriptions: list
|
|
|
+ :return: list of subscription objects
|
|
|
+ :rtype: list
|
|
|
+ """
|
|
|
+ if subscriptions:
|
|
|
+ subscriptions_list = []
|
|
|
+ for element in subscriptions:
|
|
|
+ data = database.get_subscription(element)
|
|
|
+ if data:
|
|
|
+ sub = subscription.Sub(subscription_id=data[0][0],
|
|
|
+ title=data[0][1],
|
|
|
+ subscription_type=data[0][2],
|
|
|
+ name=data[0][3],
|
|
|
+ search=data[0][4],
|
|
|
+ directory=data[0][5],
|
|
|
+ disabled=data[0][6],
|
|
|
+ site=data[0][7], conf=conf)
|
|
|
+ subscriptions_list.append(sub)
|
|
|
+ else:
|
|
|
+ LOGGER.error(
|
|
|
+ _("Invalid subscription, please check the list and "
|
|
|
+ "try again."))
|
|
|
+ else:
|
|
|
+ subscriptions_list = database.get_subscriptions(conf)
|
|
|
+ return subscriptions_list
|