13

I want to upload to YouTube without having to use the web interface in order to automate some things. Is there a way to upload from the command line in OSX?

jonsca
  • 1,732
  • 18
  • 23
  • 44
z-buffer
  • 1,489
  • 9
  • 20
  • 26

4 Answers4

12

You could give this open source project a try: https://github.com/tokland/youtube-upload/

Youtube-upload is a command-line script that uploads videos to Youtube.

Youtube-upload should work on any platform (GNU/Linux, BSD, OS X, Windows, ...) that runs Python 2/3.

tokland
  • 105
  • 4
codingbadger
  • 16,837
  • 3
  • 56
  • 91
10

Update

youtube-upload now uses Youtube APIv3 and OAuth2, whereas GoogleCL is broken due to OAuth1 turndown.

https://github.com/vinitkumar/googlecl is a fork of GoogleCL, which claims to have been ported to OAuth2 (it is not available via PyPI though).

Original Answer

Use GoogleCL, the universal Google command line client. It's implemented in Python and therefore cross-platform. Unlike youtube-upload it uses proper OAuth2 authentication, so you're not typing in or sending your Google account password in plain text.

Install via pip:

pip install googlecl

Uploading a video is as simple as:

google youtube post --category Education killer_robots.avi
kynan
  • 590
  • 7
  • 11
5

Use this straightforward tutorial on accessing the standard Youtube Cloud API, takes 10 mins to setup and gets the job done:

http://www.cnx-software.com/2014/02/09/how-to-upload-youtube-videos-with-the-command-line-in-linux/

Google happens to have its own upload_video.py script, and I could make it work with some, or rather a lot of, efforts mainly because of authentication. There’s probably a better way (comments welcome), but here’s what I had to do in Ubuntu 14.04, although I should work as well for 12.04 / 13.10:

Download the script:

mkdir youtube-upload
cd youtube-upload
wget https://github.com/youtube/api-samples/raw/master/python/upload_video.py

Download and extract Google API Python Client, and move relevant directories to the directory where the script is located:

wget https://google-api-python-client.googlecode.com/files/google-api-python-client-1.2.tar.gz
tar xzvf google-api-python-client-1.2.tar.gz
cd google-api-python-client-1.2/
mv apiclient/ oauth2client/ uritemplate/ ..
cd ..

In a computer with a Desktop interface, create a project called “Youtube Upload Script” with Google Cloud Console (the name and id does not matter) using the YouTube credential, and Enable YouTube Data API v3 in APIs & auth->API. In Credentials, click on CREATE NEW CLIENT ID, select Installed application for Application Type, and Other for Installed application type, and click Create Client ID. You should now have a Client ID for native application that looks like:

Youtube_Native_Client_ID

Back to the command line, create a file client_secrets.json vi your preferred editor (e.g. nano, vi, …), with the Client ID, Client secret, and redirect URIs above:

{
  "installed": {
    "client_id": "xxxxxxxxxx-yyyyyyyyyyyyyyy.apps.googleusercontent.com",
    "client_secret":"ABCDXXxxxxxxxxx-CddddddddD",
    "redirect_uris": ["http://locahost", "urn:ietf:wg:oauth:2.0:oob"],
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://accounts.google.com/o/oauth2/token"
  }
}

Now you can upload a video to your YouTube account with the script. There are two cases: You have access to a desktop browser such as Chromium or Firefox on the machine where the script is executed:

python upload_video.py --file=video.webm --title="Video Title" \ 
--description="Video Description" --keywords="keyword1, keyword2" \
--category=22 --privacyStatus="unlisted"
Most options are self-descriptive. Category 22 refers to People and Blog. other categories available are: Comedy “23”, Education “27”,  Entertainment “24”,   Film & Animation “1”,  Gaming “20”,  Howto & Style “26”,  Music “10”, News & Politics  “25”,  Nonprofits & Activism “29”, People & Blogs  “22”,  Pets & Animals “15”,  Science & Technology “28”,  Sports “17”, and   Travel & Events “19”.

privacyStatus lets you choose between unlisted, private or public. The machine where the script is executed does not have access to a desktop browser, and you need to use a browser in another machine, run the following command instead:

python upload_video.py --file=video.webm --title="Video Title" \
--description="Video Description" --keywords="keyword1, keyword2" \
--category=22 --privacyStatus="unlisted" --noauth_local_webserver

It will provide a link to access in your browser, to get a verification code that you can enter in the terminal. This is only requires for the first time, after you can just upload the videos without user intervention for authentication. If you run the command without noauth_local_webserver, and if you only have access to a text based web browser this won’t work, as they don’t usually support JavaScript. That’s it, the video should now upload to your YouTube account.

Authentication successful.
Uploading file...
Video id 'sbRf3O3VCEI' was successfully uploaded.

I’ve tested it myself with with one of our videos and it went pretty quickly, from a VPS.

Read more: http://www.cnx-software.com/2014/02/09/how-to-upload-youtube-videos-with-the-command-line-in-linux/#ixzz3NUKWeuqU

Meetai.com
  • 439
  • 1
  • 5
  • 6
0

The script I posted here previously actually did work for MacOS, but only after I realized the Google account you can use to upload videos to YouTube with on the web interface is not, necessarily, a YouTube account. Using the Gmail account, even after I'd granted my script access in console and even when I could use that same account to log in on the YT web site and upload videos there, had an auth fail. Using an older YT account and adding the YT API there with Oauth worked with just the default scopes. My previous post with script was downvoted, so I deleted it, but the Python script youtube_video_upload worked for me just now in Oct 2020. (https://pypi.org/project/youtube-video-upload/) If you don't need CLI, I might suggest Zapier, which can auto-upload to YouTube on different triggers, such as a new upload to Dropbox. HTH.

Xeno Xeno
  • 1
  • 3