Home>

Script to upload video to YouTube
https://developers.google.com/youtube/v3/guides/uploading_a_video?hl=ja

About the above sample code.
The code is supposed to be executed on the command line, but I want to specify the arguments in the code.
You must specify "--file" (file path) for uploading.
I want to rewrite it to specify "--file" in advance.

Finally, I'm aiming to have the path entered in a Tkinter textbox and pass the entered value as a "--file".

I don't know how to pass arguments to args other than argparser.add_argument.

Corresponding source code
if __name__ =='__main__':
  argparser.add_argument ("--file", required = True, help = "Video file to upload")
  argparser.add_argument ("--title", help = "Video title", default = "Test Title")
  argparser.add_argument ("--description", help = "Video description",
    default = "Test Description")
  argparser.add_argument ("--category", default = "22",
    help = "Numeric video category." +
      "See https://developers.google.com/youtube/v3/docs/videoCategories/list")
  argparser.add_argument ("--keywords", help = "Video keywords, comma separated",
    default = "")
  argparser.add_argument ("--privacyStatus", choices = VALID_PRIVACY_STATUSES,
    default = VALID_PRIVACY_STATUSES [0], help = "Video privacy status.")
  args = argparser.parse_args ()
  if not os.path.exists (args.file):
    exit ("Please specify a valid file using the --file = parameter.")
  youtube = get_authenticated_service (args)
  try: try:
    initialize_upload (youtube, args)
  except HttpError, e:
    print "An HTTP error% d occurred: \ n% s"% (e.resp.status, e.content)
What I tried

args = {"file": "test.mp4",'title':'test'}
I tried to specify it as a dictionary type like this, but an error occurs.

AttributeError:'dict' object has no attribute'keywords'


If i run it from the command line, the video has been uploaded successfully.