Last active
May 12, 2020 04:09
-
-
Save seanbehan/01d1e4e5839d4634b942e36e1ff4a72d to your computer and use it in GitHub Desktop.
Upload videos to Youtube.com with bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Bash script for uploading videos to Youtube.com | |
# | |
# Usage: | |
# ./youtube.bash path-to-movie-movie.mov | |
# | |
# Setup | |
# Goto https://console.developers.google.com | |
# Create app, enable Youtube Data API and create OAuth credentials, client id and client secret. | |
# Goto https://developers.google.com/oauthplayground/ to authorize yourself and get a refresh token | |
# Plug in client id, client secret and refresh token here | |
client_id="[your client id goes here]" | |
client_secret="[your client secret goes here]" | |
refresh_token="[your refresh token obtained from oauthplayground goes here]" | |
cid_base_url="apps.googleusercontent.com" | |
client_id="$client_id.$cid_base_url" | |
token_url="https://accounts.google.com/o/oauth2/token" | |
api_base_url="https://www.googleapis.com/upload/youtube/v3" | |
api_url="$api_base_url/videos?part=snippet" | |
access_token=$(curl -H "Content-Type: application/x-www-form-urlencoded" -d refresh_token="$refresh_token" -d client_id="$client_id" -d client_secret="$client_secret" -d grant_type="refresh_token" $token_url| awk -F '"' '/access/{print $4}') | |
auth_header="Authorization: Bearer $access_token" | |
curl -v --data-binary "@$1" -H "Content-Type: application/octet-stream" -H "$auth_header" "$api_url" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# ./youtube.bash '{"json goes here as explained below"}' | |
# | |
# Slightly more complicated | |
# | |
# To update a Youtube video you have to PUT a JSON document with the following structure.. | |
# | |
# {"id": "id of youtube video", "snippet": { "title": "goes here", "description": "goes here", "categoryId": "goes here"}, "status":{"privacyStatus":"unlisted"}} | |
json_data="$1" | |
client_id="goes here" | |
client_secret="goes here" | |
refresh_token="goes here" | |
cid_base_url="apps.googleusercontent.com" | |
client_id="$client_id.$cid_base_url" | |
token_url="https://accounts.google.com/o/oauth2/token" | |
api_base_url="https://www.googleapis.com/upload/youtube/v3" | |
api_url="$api_base_url/videos?part=snippet" | |
access_token=$(curl -H "Content-Type: application/x-www-form-urlencoded" -d refresh_token="$refresh_token" -d client_id="$client_id" -d client_secret="$client_secret" -d grant_type="refresh_token" $token_url| awk -F '"' '/access/{print $4}') | |
auth_header="Authorization: Bearer $access_token" | |
curl -v -i -X PUT -d "$json_data" -H "$auth_header" -H "Content-Type: application/json; charset=UTF-8" "https://www.googleapis.com/youtube/v3/videos?part=snippet,status&fields=snippet,status" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment