Help="Required ID for video for which the caption track will be uploaded.") # identifies the video for which the caption track will be uploaded. # The "videoid" option specifies the YouTube video ID that uniquely Print "caption track '%s' deleted succesfully" % (caption_id) # Call the API's lete method to delete an existing caption track. Print "First line of caption track: %s" % (subtitle)
# Call the API's captions.download method to download an existing caption track.ĭef download_caption(youtube, caption_id, tfmt): Print "and updated the track with the new uploaded file."
Print "Updated caption track '%s' draft status to be: '%s'" % (name, isDraft)
If a new binary file is present, update the track with the file as well.ĭef update_caption(youtube, caption_id, file): # Call the API's captions.update method to update an existing caption track's draft status Print "Uploaded caption track '%s(%s) in '%s' language, '%s' status." % (name, Insert_result = youtube.captions().insert( # Call the API's captions.insert method to upload a caption track in draft status.ĭef upload_caption(youtube, video_id, language, name, file): Print "Caption track '%s(%s)' in '%s' language." % (name, id, language) # Call the API's captions.list method to list the existing caption tracks. Return build_from_document(doc, http=thorize(httplib2.Http())) With open("youtube-v3-api-captions.json", "r") as f: # and it should be in the same directory with the code. # Trusted testers can download this discovery document from the developers page If credentials is None or credentials.invalid:Ĭredentials = run_flow(flow, storage, args) Storage = Storage("%s-oauth2.json" % sys.argv)
# Authorize the request and store authorization credentials.įlow = flow_from_clientsecrets(CLIENT_SECRETS_FILE, scope=YOUTUBE_READ_WRITE_SSL_SCOPE, """ % os.path.abspath(os.path.join(os.path.dirname(_file_), To make this sample run you will need to populate the client_secrets.json fileįor more information about the client_secrets.json file format, please visit: # This variable defines a message to display if the CLIENT_SECRETS_FILE is # authenticated user's account and requires requests to use an SSL connection.
# This OAuth 2.0 access scope allows for full read/write access to the # For more information about the client_secrets.json file format, see:ĬLIENT_SECRETS_FILE = "client_secrets.json" # For more information about using OAuth2 to access the YouTube Data API, see: # Please ensure that you have enabled the YouTube Data API for your project. You can acquire an OAuth 2.0 client ID and client secret from # the OAuth 2.0 information for this application, including its client_id and # The CLIENT_SECRETS_FILE variable specifies the name of a file that contains # python captions.py -videoid='' -name='' -file='' -language='' -action='action'įrom apiclient.discovery import build_from_documentįrom oauth2client.client import flow_from_clientsecretsįrom oauth2client.tools import argparser, run_flow I don't know why it doesn't recognise the video id of this public video.
I put this code line in cmd : python captions.py -videoid='Txvud7wPbv4' -action='download' I have already stored the client-secrets.json(oauth2 authentification) and youtube-v3-api-captions.json in the same directory (asked in the sample code) I am using the code sample(captions.py) below that i got from this link I am trying to download closed captions for this public youtube video (just for testing)