Browse Source

- Renamed command line option 'publishAt' to 'publish-at' (maintainers wish).
- Modified option checks to ensure '--publish-at' is not used with '--privacy=unlisted'. An 'OptionsError' will be thrown. (partially fullfilling maintainers wish)
- set 'privacy' default to 'public' again (maintainers wish)
- 'OptionsMissing' renamed to 'OptionsError' (maintainers suggestion)

Maintainers wishes not addressed:
- No exception is raised when 'privacy' is set to 'public' and 'publish-at' option is used. I assume an uploader using the 'publish-at' option is aware that the video will remain private until specified date and that at some point he or she will have that video published. That's why he or she is using that option. It might be different though with someone using the '--privacy=unlisted' option. In that case the user might assume the video will be published 'unlisted' at specified date. To deal with this case an exception is raised.

Bene81 9 years ago
parent
commit
bbd184a27e
1 changed files with 21 additions and 9 deletions
  1. 21 9
      youtube_upload/main.py

+ 21 - 9
youtube_upload/main.py

@@ -36,12 +36,12 @@ except ImportError:
     progressbar = None
 
 class InvalidCategory(Exception): pass
-class OptionsMissing(Exception): pass
+class OptionsError(Exception): pass
 class AuthenticationError(Exception): pass
 class RequestError(Exception): pass
 
 EXIT_CODES = {
-    OptionsMissing: 2,
+    OptionsError: 2,
     InvalidCategory: 3,
     RequestError: 3,
     AuthenticationError: 4,
@@ -109,7 +109,7 @@ def upload_youtube_video(youtube, options, video_path, total_videos, index):
         },
         "status": {
             "privacyStatus": options.privacy,
-            "publishAt": options.publishAt,
+            "publishAt": options.publish-at,
 
         },
         "recordingDetails": {
@@ -127,14 +127,26 @@ def upload_youtube_video(youtube, options, video_path, total_videos, index):
         progress.finish()
     return video_id
 
-def run_main(parser, options, args, output=sys.stdout):
-    """Run the main scripts from the parsed options/args."""
+def parse_options_error(parser, options):
     required_options = ["title"]
     missing = [opt for opt in required_options if not getattr(options, opt)]
     if missing:
         parser.print_usage()
         msg = "Some required option are missing: {0}".format(", ".join(missing))
-        raise OptionsMissing(msg)
+        raise OptionsError(msg)
+    scheduled = getattr(options, "publish-at") != None
+    if scheduled:
+        if getattr(options, "privacy") == "listed":
+            parser.print_usage()
+            msg = "The 'publish-at' option will publish your video for all audiences. It can not be used with '--privacy=listed'."
+            raise OptionsError(msg)
+        setattr(options, "privacy", "private")
+        debug("Your video will remain private until specified date.")
+
+def run_main(parser, options, args, output=sys.stdout):
+    """First parse the passed options roughly for validity"""
+    parse_options_error(parser, options)
+    """Run the main scripts from the parsed options/args."""
     home = os.path.expanduser("~")
     default_client_secrets = lib.get_first_existing_filename(
         [sys.prefix, os.path.join(sys.prefix, "local")],
@@ -183,9 +195,9 @@ def main(arguments):
     parser.add_option('', '--tags', dest='tags', type="string",
         help='Video tags (separated by commas: "tag1, tag2,...")')
     parser.add_option('', '--privacy', dest='privacy', metavar="STRING",
-        default="private", help='Privacy status (public | unlisted | private)')
-    parser.add_option('', '--publishAt', dest='publishAt', metavar="datetime",
-       default="", help='Publish Date: YYYY-MM-DDThh:mm:ss.sZ')
+        default="public", help='Privacy status (public | unlisted | private)')
+    parser.add_option('', '--publish-at', dest='publish-at', metavar="datetime",
+       default=None, help='Publish Date: YYYY-MM-DDThh:mm:ss.sZ')
     parser.add_option('', '--location', dest='location', type="string",
         default=None, metavar="latitude=VAL,longitude=VAL[,altitude=VAL]",
         help='Video location"')