Jared 3 éve
szülő
commit
4440019218
2 módosított fájl, 77 hozzáadás és 0 törlés
  1. 23 0
      hhh/yt/upload_test.py
  2. 54 0
      hhh/yt/upload_video.py

+ 23 - 0
hhh/yt/upload_test.py

@@ -0,0 +1,23 @@
+# youtube upload api
+from youtube_upload.client import YoutubeUploader
+#uploader = YoutubeUploader()
+uploader = YoutubeUploader(secrets_file_path='c:\\keys\\client_secret_244642730545-m6s4um0g6p3289ig7k92oseusisibnfp.apps.googleusercontent.com.json')
+
+uploader.authenticate(access_token='ya29.A0ARrdaM9829B5NAtYwMqfUBXxuYfD6ldW4ANvPuhB00LoMQlWT9v-kU4V0HXugiLLGKw413iM5gRpU1bwRP0iksATPfJyC9bnjOnnOVKGveRZNcl-y_YSqoOpwcMUYem0DlUiXMX-t6DPmt1WiTO-bZwTh-cb',refresh_token='1//0eDV6kUVBHW_VCgYIARAAGA4SNwF-L9IrFgT567AW0kbn36quvdu5NfQrcY-vYAT2xl1dpwP1KOayUQOcgTQCoYG1X7dYh1ye4Gc')
+#uploader.authenticate(oauth_path='c:\\keys\\storage.json')
+
+# Video options
+options = {
+    "title" : "Example title", # The video title
+    "description" : "Example description", # The video description
+    "tags" : ["tag1", "tag2", "tag3"],
+    "categoryId" : "22",
+    "publishAt":"2015-01-21T11:20:27.751+00:00",
+    "privacyStatus" : "public", # Video privacy. Can either be "public", "private", or "unlisted"
+    "kids" : False # Specifies if the Video if for kids or not. Defaults to False.
+#    "thumbnailLink" : "https://hhh.com.tw/event170427/images/designer/37.png" # Optional. Specifies video thumbnail.
+}
+
+# upload video
+uploader.upload('C:\\data\\demo\\test.mp4', options)
+uploader.close()

+ 54 - 0
hhh/yt/upload_video.py

@@ -0,0 +1,54 @@
+
+from google_auth_oauthlib.flow import Flow
+from colorama import init, Fore
+import codecs
+
+SCOPES = ['https://www.googleapis.com/auth/youtube.upload']
+API_SERVICE_NAME = 'youtube'
+API_VERSION = 'v3'
+
+VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted')
+
+
+def get_credentials(secrets):
+#    flow = Flow.from_client_config(
+#        secrets,
+##        scopes=SCOPES,
+#        redirect_uri='urn:ietf:wg:oauth:2.0:oob')
+
+    flow = Flow.from_client_secrets_file(
+    'c:\\keys\\.client_secrets.json',
+    scopes= ['https://www.googleapis.com/auth/youtube.upload'],
+#    redirect_uri='urn:ietf:wg:oauth:2.0:oob')
+    redirect_uri='http://api.ptt.cx')
+
+
+    # Tell the user to go to the authorization URL.
+    auth_url, _ = flow.authorization_url(prompt='consent')
+
+    init(autoreset=True)
+    print()
+    print(Fore.GREEN + 'Please go to this URL: ' + Fore.CYAN + str(auth_url))
+
+    # The user will get an authorization code. This code is used to get the
+    # access token.
+    print()
+    code = input(Fore.GREEN + 'Enter the authorization code: ')
+    flow.fetch_token(code=code)
+    print()
+
+    return flow.credentials
+
+    # using flow.authorized_session.
+    # session = flow.authorized_session()
+    # print(session.get('https://www.googleapis.com/userinfo/v2/me').json())
+
+tok=get_credentials('c:\\keys\\.client_secrets.json')
+print(tok)
+print(tok.refresh_token)
+print(tok.to_json())
+fw=codecs.open('c:\\keys\\storage.json','w','utf-8')
+fw.write(tok.to_json())
+fw.close()
+
+