Browse Source

move catchup to program

Helmut Pozimski 6 years ago
parent
commit
1561587f9b
2 changed files with 29 additions and 19 deletions
  1. 27 2
      lib_stov/program.py
  2. 2 17
      stov

+ 27 - 2
lib_stov/program.py

@@ -311,10 +311,10 @@ def list_videos(database, conf, sub_id):
     """
     Lists all videos in a specified subscription
 
+    :param database: database object
+    :type database: lib_stov.database.Db
     :param conf: configuration object
     :type conf: lib_stov.configuration.Conf
-    :param downloaded_videos: number of downloaded videos
-    :type downloaded_videos: int
     :param sub_id: ID of the subscription
     :type sub_id: int
     """
@@ -340,3 +340,28 @@ def list_videos(database, conf, sub_id):
         else:
             LOGGER.error(_("Invalid subscription, please check the list and "
                            "try again."))
+
+
+def catchup(database, sub_id):
+    """
+    Marks all videos in a subscription as downloaded
+
+    :param database: database object
+    :type database: lib_stov.database.Db
+    :param sub_id: ID of the subscription
+    :type sub_id: int
+    """
+    try:
+        sub_data = database.get_subscription_title(sub_id)
+    except stov_exceptions.DBWriteAccessFailedException as error:
+        LOGGER.error(error)
+        sys.exit(1)
+    else:
+        if sub_data != []:
+            try:
+                database.mark_video_downloaded(sub_id)
+            except stov_exceptions.DBWriteAccessFailedException as error:
+                LOGGER.error(error)
+        else:
+            LOGGER.error(_("The subscription could not be updated, "
+                           "please check if the ID given is correct."))

+ 2 - 17
stov

@@ -81,23 +81,8 @@ elif ARGUMENTS.download:
 
 elif ARGUMENTS.subscriptionid:
     program.list_videos(DB, CONF, ARGUMENTS.subscriptionid)
-elif ARGUMENTS.catchup is not None:
-    try:
-        SUB_DATA = DB.get_subscription_title(ARGUMENTS.catchup)
-    except stov_exceptions.DBWriteAccessFailedException as error:
-        LOGGER.error(error)
-        sys.exit(1)
-    else:
-        if SUB_DATA != []:
-            try:
-                DB.mark_video_downloaded(ARGUMENTS.catchup)
-            except stov_exceptions.DBWriteAccessFailedException as error:
-                LOGGER.error(error)
-        else:
-            LOGGER.error(_("The subscription could not be updated, "
-                           "please check if the ID given is correct."))
-
-
+elif ARGUMENTS.catchup:
+    program.catchup(DB, ARGUMENTS.catchup)
 elif ARGUMENTS.cleanup is True:
     SUBSCRIPTION_LIST = DB.get_subscriptions(CONF)
     for element in SUBSCRIPTION_LIST: