Browse Source

Merge pull request #56 from Skylion007/master

Add option to automatically open webpage when video uploads
Arnau Sanchez 9 years ago
parent
commit
fb14111787
2 changed files with 17 additions and 3 deletions
  1. 4 1
      youtube_upload/auth/console.py
  2. 13 2
      youtube_upload/main.py

+ 4 - 1
youtube_upload/auth/console.py

@@ -6,5 +6,8 @@ def get_code(authorize_url):
     message = "Check this link in your browser: {0}".format(authorize_url)
     message = "Check this link in your browser: {0}".format(authorize_url)
     sys.stderr.write(message + "\n")
     sys.stderr.write(message + "\n")
     try: input = raw_input #For Python2 compatability
     try: input = raw_input #For Python2 compatability
-    except NameError: pass
+    except NameError: 
+        #For Python3 on Windows compatability
+        try: from builtins import input as input 
+        except ImportError: pass
     return input("Enter verification code: ")
     return input("Enter verification code: ")

+ 13 - 2
youtube_upload/main.py

@@ -19,6 +19,7 @@ import os
 import sys
 import sys
 import optparse
 import optparse
 import collections
 import collections
+import webbrowser
 
 
 import apiclient.errors
 import apiclient.errors
 import oauth2client
 import oauth2client
@@ -54,6 +55,10 @@ WATCH_VIDEO_URL = "https://www.youtube.com/watch?v={id}"
 debug = lib.debug
 debug = lib.debug
 struct = collections.namedtuple
 struct = collections.namedtuple
 
 
+def open_link(url):
+    """Opens a URL link in the client's browser."""
+    webbrowser.open(url)
+    
 def get_progress_info():
 def get_progress_info():
     """Return a function callback to update the progressbar."""
     """Return a function callback to update the progressbar."""
     progressinfo = struct("ProgressInfo", ["callback", "finish"])
     progressinfo = struct("ProgressInfo", ["callback", "finish"])
@@ -160,7 +165,9 @@ def run_main(parser, options, args, output=sys.stdout):
             video_id = upload_youtube_video(youtube, options, video_path, len(args), index)
             video_id = upload_youtube_video(youtube, options, video_path, len(args), index)
             video_url = WATCH_VIDEO_URL.format(id=video_id)
             video_url = WATCH_VIDEO_URL.format(id=video_id)
             debug("Video URL: {0}".format(video_url))
             debug("Video URL: {0}".format(video_url))
-
+            if options.open_link:
+                open_link(video_url) #Opens the Youtube Video's link in a webbrowser
+                
             if options.thumb:
             if options.thumb:
                 youtube.thumbnails().set(videoId=video_id, media_body=options.thumb).execute()
                 youtube.thumbnails().set(videoId=video_id, media_body=options.thumb).execute()
             if options.playlist:
             if options.playlist:
@@ -204,9 +211,13 @@ def main(arguments):
         type="string", help='Client secrets JSON file')
         type="string", help='Client secrets JSON file')
     parser.add_option('', '--credentials-file', dest='credentials_file',
     parser.add_option('', '--credentials-file', dest='credentials_file',
         type="string", help='Credentials JSON file')
         type="string", help='Credentials JSON file')
-    parser.add_option('', '--auth-browser', dest='auth_browser', action="store_true",
+    parser.add_option('', '--auth-browser', dest='auth_browser', action='store_true',
         help='Open a GUI browser to authenticate if required')
         help='Open a GUI browser to authenticate if required')
 
 
+    #Additional options
+    parser.add_option('', '--open-link', dest='open_link', action='store_true',
+        help='Opens a url in a web browser to display uploaded videos')
+
     options, args = parser.parse_args(arguments)
     options, args = parser.parse_args(arguments)
     run_main(parser, options, args)
     run_main(parser, options, args)