Command-line script to upload videos to Youtube using theYoutube APIv3.

Overview

Introduction

Command-line script to upload videos to Youtube using theYoutube APIv3. It should work on any platform (GNU/Linux, BSD, OS X, Windows, ...) that runs Python.

Dependencies

Check if your operating system provides those packages (check also those deb/rpm/mac files), otherwise install them with pip:

$ sudo pip install --upgrade google-api-python-client oauth2client progressbar2

Install

$ wget https://github.com/tokland/youtube-upload/archive/master.zip
$ unzip master.zip
$ cd youtube-upload-master
$ sudo python setup.py install

Or run directly from sources:

$ cd youtube-upload-master
$ PYTHONPATH=. python bin/youtube-upload ...

Setup

You'll see that there is no email/password options. Instead, the Youtube API uses OAuth 2.0 to authenticate the upload. The first time you try to upload a video, you will be asked to follow a URL in your browser to get an authentication token. If you have multiple channels for the logged in user, you will also be asked to pick which one you want to upload the videos to. You can use multiple credentials, just use the option --credentials-file. Also, check the token expiration policies.

The package used to include a default client_secrets.json file. It does not work anymore, Google has revoked it. So you now must create and use your own OAuth 2.0 file, it's a free service. Steps:

  • Go to the Google console.
  • Create project.
  • Side menu: APIs & auth -> APIs
  • Top menu: Enabled API(s): Enable all Youtube APIs.
  • Side menu: APIs & auth -> Credentials.
  • Create a Client ID: Add credentials -> OAuth 2.0 Client ID -> Other -> Name: youtube-upload -> Create -> OK
  • Download JSON: Under the section "OAuth 2.0 client IDs". Save the file to your local system.
  • Use this JSON as your credentials file: --client-secrets=CLIENT_SECRETS or copy it to ~/client_secrets.json.

Note: client_secrets.json is a file you can download from the developer console, the credentials file is something auto generated after the first time the script is run and the google account sign in is followed, the file is stored at ~/.youtube-upload-credentials.json.

Examples

  • Upload a video (a valid ~/.client_secrets.json should exist, check the Setup section):
$ youtube-upload --title="A.S. Mutter" anne_sophie_mutter.flv
pxzZ-fYjeYs
  • Upload a video with extra metadata, with your own client secrets and credentials file, and to a playlist (if not found, it will be created):
$ youtube-upload \
  --title="A.S. Mutter" \
  --description="A.S. Mutter plays Beethoven" \
  --category="Music" \
  --tags="mutter, beethoven" \
  --recording-date="2011-03-10T15:32:17.0Z" \
  --default-language="en" \
  --default-audio-language="en" \
  --client-secrets="my_client_secrets.json" \
  --credentials-file="my_credentials.json" \
  --playlist="My favorite music" \
  --embeddable=True|False \
  anne_sophie_mutter.flv
tx2Zb-145Yz

Other extra medata available :

--privacy (public | unlisted | private)  
--publish-at (YYYY-MM-DDThh:mm:ss.sZ)  
--location (latitude=VAL,longitude=VAL[,altitude=VAL])  
--thumbnail (string)  
  • Upload a video using a browser GUI to authenticate:
$ youtube-upload --title="A.S. Mutter" --auth-browser anne_sophie_mutter.flv
  • Split a video with ffmpeg

If your video is too big or too long for Youtube limits, split it before uploading:

$ bash examples/split_video_for_youtube.sh video.avi
video.part1.avi
video.part2.avi
video.part3.avi
  • Use a HTTP proxy

Set environment variables http_proxy and https_proxy:

$ export http_proxy=http://user:password@host:port
$ export https_proxy=$http_proxy
$ youtube-upload ....

Get available categories

  • Search "youtube categories" -> youtube.videoCategories.list
  • This bring you to youtube.videoCategories.list service
  • part: id,snippet
  • regionCode: es (2 letter code of your country)
  • Authorize and execute

And see the JSON response below. Note that categories with the attribute assignable equal to false cannot be used.

Using shoogle:

$ shoogle execute --client-secret-file client_secret.json \
                  youtube:v3.videoCategories.list <(echo '{"part": "id,snippet", "regionCode": "es"}')  | 
    jq ".items[] | select(.snippet.assignable) | {id: .id, title: .snippet.title}"

Notes for developers

Alternatives

  • shoogle can send requests to any Google API service, so it can be used not only to upload videos, but also to perform any operation regarding the Youtube API.

  • youtubeuploader uploads videos to Youtube from local disk or from the web. It also provides rate-limited uploads.

More

Feedback

  • Donations.
  • If you find a bug, open an issue.
  • If you want a new feature to be added, you'll have to send a pull request (or find a programmer to do it for you), currently I am not adding new features.
Comments
  • "Video not found. youtube.playlistItem" when adding to a playlist

    Describe the bug

    I get the following on a subset of my uploads:

    Adding video to playlist: ....playlistid_shown....
    [RequestError] Server response: {
      "error": {
        "code": 404,
        "message": "Video not found.",
        "errors": [
          {
            "message": "Video not found.",
            "domain": "youtube.playlistItem",
            "reason": "videoNotFound"
          }
        ]
      }
    }
    

    This may be related to having many playlists or many video's in the channel, i.e. some sort of timeout.

    To Reproduce Upload regularly to a channel with many large playlists and many video's

    Expected behavior No such error, as is shown on the other subset of my uploads. Really does like a timeout issue.

    Desktop (please complete the following information):

    • OS: Linux Ubuntu
    • OS Version 20.04
    • Python Version 2.7.17

    Additional context Please check if the timeout can be increased? Perhaps few seconds more? Happy to test any proposed fixes? Thank you

    opened by RoelVdP 36
  • socket.error: [Errno 104] Connection reset by peer

    socket.error: [Errno 104] Connection reset by peer

    100% |###############################################| Time: 0:15:49 987.0 KiB/s Traceback (most recent call last): File "/usr/local/bin/youtube-upload", line 10, in main.run() File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 251, in run sys.exit(lib.catch_exceptions(EXIT_CODES, main, sys.argv[1:])) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/lib.py", line 39, in catch_exceptions fun(_args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 246, in main run_main(parser, options, args) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 178, in run_main video_id = upload_youtube_video(youtube, options, video_path, len(args), index) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 140, in upload_youtube_video request_body, progress_callback=progress.callback) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/upload_video.py", line 40, in upload RETRIABLE_EXCEPTIONS, max_retries=max_retries) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/lib.py", line 75, in retriable_exceptions raise exc socket.error: [Errno 104] Connection reset by peer

    Uploading from Raspberry pi over the night after looking if its finished this error appierd

    opened by MarvinBeym 30
  • Youtube Quota Exceeded Exception when it's actually not

    Youtube Quota Exceeded Exception when it's actually not

    I'm using youtube-upload and have been for quite some time without any problems. Recently, we've been getting this 403 exception:

    Using client secrets: /root/ytb_api/ppx_client_secrets.json Using credentials file: /root/ytb_api/ppx_credentials.json Start upload: ./ppx_video/new.mp4 [RequestError] Server response: { "error": { "errors": [ { "domain": "youtube.quota", "reason": "quotaExceeded", "message": "The request cannot be completed because you have exceeded your \u003ca href="/youtube/v3/getting-started#quota"\u003equota\u003c/a\u003e." } ], "code": 403, "message": "The request cannot be completed because you have exceeded your \u003ca href="/youtube/v3/getting-started#quota"\u003equota\u003c/a\u003e." } }

    In the google developer's console, it says that we are still under the quota (currently it states "units/day 163,817 of 50,000,000"). Am I missing something about how it work?

    opened by Jaqen00 23
  • Retry Option?

    Retry Option?

    Had this output today aswell (more than once):

    100% |################################################################|  10.6 MiB/s
    [RequestError] Server response:
    

    Would be useful to have a retry option!

    Thank you!

    opened by userlip 22
  • Error: AttributeError: 'module' object has no attribute 'file'

    Error: AttributeError: 'module' object has no attribute 'file'

    Python 2.7.12 Linux Ubuntu 16.04

    Error occurs every time I try to upload a video

    Using client secrets: /root/YouTube-Tools/client-secrets.json
    Using credentials file: /root/.youtube-upload-credentials.json
    Traceback (most recent call last):
      File "/usr/local/bin/youtube-upload", line 10, in <module>
        main.run()
      File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 261, in run
        sys.exit(lib.catch_exceptions(EXIT_CODES, main, sys.argv[1:]))
      File "/usr/local/lib/python2.7/dist-packages/youtube_upload/lib.py", line 42, in catch_exceptions
        fun(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 255, in main
        run_main(parser, options, args)
      File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 174, in run_main
        youtube = get_youtube_handler(options)
      File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 160, in get_youtube_handler
        get_code_callback=get_code_callback)
      File "/usr/local/lib/python2.7/dist-packages/youtube_upload/auth/__init__.py", line 38, in get_resource
        storage = oauth2client.file.Storage(credentials_file)
    AttributeError: 'module' object has no attribute 'file'
    
    opened by xDroni 16
  • setup.py not installing client_secrets.json

    setup.py not installing client_secrets.json

    Ran 'sudo python setup.py install'. Script installed but did not create /usr/share/youtube_upload. Manually creating and copy client_secrets.json there fixes error. This is on Ubuntu 14.04 LTS (ami-d05e75b8 in EC2).

    opened by kldavis4 14
  • add --playlist option

    add --playlist option

    pretty simple: --playlist "playlist title" will iterate through the user's playlists looking for playlist title. If found, the video will be added to it. If not found, the playlist will be created using the privacy settings for the currently-uploading video, then the video will be added to it.

    opened by sbma44 13
  • Script does not start

    Script does not start

    Trying to upload video, getting the following error:

    [root@dwarkin youtube]# youtube-upload --title="aa" --credentials-file=/data/yt_secret/client_secret.json Full_House_anons_21_18.05_aysor.mov.mp4 Using client secrets: /usr/share/youtube_upload/client_secrets.json Using credentials file: /data/yt_secret/client_secret.json Traceback (most recent call last): File "/usr/bin/youtube-upload", line 181, in sys.exit(lib.catch_exceptions(EXIT_CODES, main, sys.argv[1:])) File "/usr/lib/python2.6/site-packages/youtube_upload/lib.py", line 37, in catch_exceptions fun(_args, *_kwargs) File "/usr/bin/youtube-upload", line 178, in main run_main(parser, options, args) File "/usr/bin/youtube-upload", line 133, in run_main get_code_callback=get_code_callback) File "/usr/lib/python2.6/site-packages/youtube_upload/auth/init.py", line 39, in get_resource credentials = _get_credentials(flow, storage, get_code_callback) File "/usr/lib/python2.6/site-packages/youtube_upload/auth/init.py", line 28, in _get_credentials existing_credentials = storage.get() File "/usr/lib/python2.6/site-packages/oauth2client/client.py", line 374, in get return self.locked_get() File "/usr/lib/python2.6/site-packages/oauth2client/file.py", line 79, in locked_get credentials = Credentials.new_from_json(content) File "/usr/lib/python2.6/site-packages/oauth2client/client.py", line 281, in new_from_json module = data['_module'] KeyError: '_module' [root@dwarkin youtube]#

    OS: Centos 6.6 Installed according the README.md I think, that I've missed something during the installation.

    Thank you.

    opened by rubenmuradyan 13
  • UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1441: ordinal not in range(128)

    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1441: ordinal not in range(128)

    I get this randomly during upload. Command: youtube-upload --title test1 --description "test" --privacy unlisted /media/usb0/test.mp4

    Output: Using client secrets: /usr/local/share/youtube_upload/client_secrets. Using credentials file: /home/user/.youtube-upload-credentials.json Start upload: /media/usb0/test.mp4 100% |#######################################################################################################################################################| 40.8 MiB/s Traceback (most recent call last): File "/usr/local/bin/youtube-upload", line 10, in <module> main.run() File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 250, in run sys.exit(lib.catch_exceptions(EXIT_CODES, main, sys.argv[1:])) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/lib.py", line 39, in catch_exceptions fun(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 247, in main raise RequestError("Server response: {0}".format(bytes.decode(error.content).strip())) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1441: ordinal not in range(128)

    opened by f3bruary 12
  • Detaching from console, Ctrl+C not working

    Detaching from console, Ctrl+C not working

    I noticed that script is detaching from console while uploading. This may be desired for certain people but normally it should not do it.

    It should not detach from console by default and if possible, detach option can be added as a command line parameter. This will give flexibility to all users.

    opened by sezeryalcin 12
  • httplib2.RedirectMissingLocation: Redirected but the response is missing a Location: header.

    httplib2.RedirectMissingLocation: Redirected but the response is missing a Location: header.

    Using client secrets: /root/.client_secrets.json Using credentials file: /root/.youtube-upload-credentials.json Start upload: 3.mp4 Traceback (most recent call last): File "/usr/local/bin/youtube-upload", line 10, in main.run() File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 268, in run sys.exit(lib.catch_exceptions(EXIT_CODES, main, sys.argv[1:])) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/lib.py", line 44, in catch_exceptions fun(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 262, in main run_main(parser, options, args) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 180, in run_main video_id = upload_youtube_video(youtube, options, video_path, len(args), index) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/main.py", line 146, in upload_youtube_video chunksize=options.chunksize) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/upload_video.py", line 43, in upload RETRIABLE_EXCEPTIONS, max_retries=max_retries) File "/usr/local/lib/python2.7/dist-packages/youtube_upload/lib.py", line 76, in retriable_exceptions raise exc httplib2.RedirectMissingLocation: Redirected but the response is missing a Location: header.

    macos 10.14.1 python 2.7

    opened by xioayangguang 11
  • youtube-upload stop before complete, return code: yPbyCyGjdAU

    youtube-upload stop before complete, return code: yPbyCyGjdAU

    Error when upload big file. app stop when 0% upload and return a code: yPbyCyGjdAU. How to upload to this video again, dont create new video, I dont wanna manual delete this video?

    opened by ptn611 0
  • linebreak not working in youtube description

    linebreak not working in youtube description

    Ive tried everything from
    to \n and "\n" suggested by some but its not working.

    im dumping text in the following way, then using that $description in the command

    printf '%s\n' "${random_text_from_loop}" '\n' >> description.txt description=$(cat description.txt)

    youtube-upload --description="$description"

    opened by pefman 0
  • What quota do you get once the app is verified?

    What quota do you get once the app is verified?

    I set up the program and I haven't verified it yet with google.

    I understand it looks like the the form mentions quotas too. https://support.google.com/youtube/contact/yt_api_audited_developer_requests_form

    Currently it let me upload 5, which is really low (and albeit with the privacy lock message because I haven't verified the application yet)

    What kind of quota do you get once it's verified? And has anybody tried extending the quota, if so, do they tend to extend it to?

    Thanks

    opened by gartha1 0
  • Migrate your OAuth out-of-band flow to an alternative method before Oct. 3, 2022

    Migrate your OAuth out-of-band flow to an alternative method before Oct. 3, 2022

    Got the very confusing email from Google a few months ago but have been dragging my feet on following it. So I tried today to create a new credentials as type "Desktop" in the same project. But when I try and upload the YouTube video, I get this:

    It does not make sense as my .client_secrets.json file does not have any oob in it ( although the old one did ).

    Capture

    opened by feacluster 3
  • Folder creation access denied

    Folder creation access denied

    `creating C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\Lib\site-packages\youtube_upload

    error: could not create 'C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\Lib\site-packages\youtube_upload': Access is denied`

    Describe the bug Folder creation access denied

    To Reproduce install

    Expected behavior not denied

    Desktop (please complete the following information): windows 11

    opened by Glement 0
Owner
Arnau Sanchez
Arnau Sanchez
A command-line tool to upload local files and pastebin pastes to your mega account, without signing in anywhere

A command-line tool to upload local files and pastebin pastes to your mega account, without signing in anywhere

ADI 4 Nov 17, 2022
googler is a power tool to Google (web, news, videos and site search) from the command-line.

googler is a power tool to Google (web, news, videos and site search) from the command-line.

Terminator X 5.9k Jan 4, 2023
Command line tool to keep track of your favorite playlists on YouTube and many other places.

Command line tool to keep track of your favorite playlists on YouTube and many other places.

Wolfgang Popp 144 Jan 5, 2023
PipeCat - A command line Youtube music player written in python.

A command line Youtube music player written in python. It's an app written for Linux. It also supports offline playlists that are stored in a

null 34 Nov 27, 2022
A cd command that learns - easily navigate directories from the command line

NAME autojump - a faster way to navigate your filesystem DESCRIPTION autojump is a faster way to navigate your filesystem. It works by maintaining a d

William Ting 14.5k Jan 3, 2023
AML Command Transfer. A lightweight tool to transfer any command line to Azure Machine Learning Services

AML Command Transfer (ACT) ACT is a lightweight tool to transfer any command from the local machine to AML or ITP, both of which are Azure Machine Lea

Microsoft 11 Aug 10, 2022
Ros command - Unifying the ROS command line tools

Unifying the ROS command line tools One impairment to ROS 2 adoption is that all

null 37 Dec 15, 2022
git-partial-submodule is a command-line script for setting up and working with submodules while enabling them to use git's partial clone and sparse checkout features.

Partial Submodules for Git git-partial-submodule is a command-line script for setting up and working with submodules while enabling them to use git's

Nathan Reed 15 Sep 22, 2022
🌌 A Python script to generate blog banners from command line.

Auto Blog Banner Generator A Python script to generate blog banners. This script is used at RavSam. The following image is an example of the blog bann

RavSam 10 Sep 20, 2022
A CLI tool for searching and watching videos on youtube with no spyware and MPV and yt-dlp

A CLI tool for searching and watching videos on youtube with no spyware and MPV and yt-dlp

TruncatedDinosour 3 Feb 22, 2022
Simple command line tool for text to image generation using OpenAI's CLIP and Siren (Implicit neural representation network)

Simple command line tool for text to image generation using OpenAI's CLIP and Siren (Implicit neural representation network)

Phil Wang 4.4k Jan 9, 2023
Command line interface for testing internet bandwidth using speedtest.net

speedtest-cli Command line interface for testing internet bandwidth using speedtest.net Versions speedtest-cli works with Python 2.4-3.7 Installation

Matt Martz 12.4k Jan 8, 2023
A command-line based, minimal torrent streaming client made using Python and Webtorrent-cli.

ABOUT A command-line based, minimal torrent streaming client made using Python and Webtorrent-cli. Installation pip install -r requirements.txt It use

Janardon Hazarika 17 Dec 11, 2022
A simple command-line tracert implementation in Python 3 using ICMP packets

Traceroute A simple command-line tracert implementation in Python 3 using ICMP packets Details Traceroute is a networking tool designed for tracing th

James 3 Jul 16, 2022
A Python module and command line utility for working with web archive data using the WACZ format specification

py-wacz The py-wacz repository contains a Python module and command line utility for working with web archive data using the WACZ format specification

Webrecorder 14 Oct 24, 2022
This is a command line program to play cricket made using Python.

SimpleCricketPython This is a command line program to play cricket made using Python < How it works First you have the option of selecting whether you

Imira Randeniya 1 Sep 11, 2022
A very simple and lightweight ToDo app using python that can be used from the command line

A very simple and lightweight ToDo app using python that can be used from the command line

Nilesh Sengupta 2 Jul 20, 2022
A mini command line tool to spellcheck text files using tadqeek.alsharekh.org

tadqeek_sakhr A mini command line tool to spellcheck text files using tadqeek.alsharekh.org Usage usage: python tadqeek_sakhr.py [-h] -i INPUT [-o OUT

Youssif Shaaban Alsager 5 Dec 11, 2022
Python Command Line Application (CLI) using Typer, SQLModel, Async-PostgrSQL, and FastAPI

pyflycli is a command-line interface application built with Typer that allows you to view flights above your location.

Kevin Zehnder 14 Oct 1, 2022