GithubHelp home page GithubHelp logo

youtubeuploader's Introduction

Youtube Uploader

Tests

Scripted uploads to youtube.

  • upload video files from local disk or from the web.
  • ratelimit upload bandwidth

Download

Grab a precompiled binary for Linux, Mac or Windows or build it yourself.

Setup

Youtube API

Talking to the Youtube API requires oauth2 authentication. As such, you must:

  1. Create an account on the Google Developers Console
  2. Create a new project for this app
  3. Enable the Youtube API (APIs & Services -> Enable APIs and Services -> Click 'ENABLE APIS AND SERVICES' top right). Select 'YouTube Data API v3'
  4. Create OAuth consent screen (APIs & Services -> OAuth Consent Screen)
    • Add a test user. This can be any Google User account but it should correspond with the Youtube account where videos will be uploaded.
  5. Create Credentials (APIs & Services -> Credentials -> click 'CREATE CREDENTIALS'), select 'OAuth client ID', select 'Web application'
  6. Download the client secrets JSON file (click download icon next to newly created client ID) and save it as file client_secrets.json in the same directory as the utility e.g.
{
  "web": {
    "client_id": "xxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
    "project_id": "youtubeuploader-yyyyy",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "xxxxxxxxxxxxxxxxxxxx",
    "redirect_uris": [
      "http://localhost:8080/oauth2callback"
    ]
  }
}

NOTE 1 Google will apply 'private' status on videos uploaded to newly created projects - from Google's Announcement:

All videos uploaded via the videos.insert endpoint from unverified API projects created after 28 July 2020 will be restricted to private viewing mode. To lift this restriction, each project must undergo an audit to verify compliance with the Terms of Service.

See Issue #86 for more information.

NOTE 2 By default you will only be able to upload ~6 videos every 24 hours due to quota restrictions set by Google. See Issue #119 for more information.

Usage

At a minimum, just specify a filename:

./youtubeuploader -filename blob.mp4

If it is the first time you've run the utility, a browser window should popup and prompt you to provide Youtube credentials. A token will be created and stored in request.token file in the local directory for subsequent use. To run the utility on a headless-server, generate the token file locally first, then simply copy the token file along with youtubeuploader and client_secrets.json to the remote host.

Full list of options:

  -cache string
    	token cache file (default "request.token")
  -caption string
    	caption filename. Can be a URL
  -categoryId string
    	video category Id
  -chunksize int
    	size (in bytes) of each upload chunk. A zero value will cause all data to be uploaded in a single request (default 16777216)
  -debug
    	turn on verbose log output
  -description string
    	video description (default "uploaded by youtubeuploader")
  -filename string
    	video filename. Can be a URL. Read from stdin with '-'
  -language string
    	video language (default "en")
  -limitBetween string
    	only rate limit between these times e.g. 10:00-14:00 (local time zone)
  -metaJSON string
    	JSON file containing title,description,tags etc (optional)
  -metaJSONout string
    	filename to write uploaded video metadata into (optional)
  -notify
    	notify channel subscribers of new video. Specify '-notify=false' to disable. (default true)
  -oAuthPort int
    	TCP port to listen on when requesting an oAuth token (default 8080)
  -privacy string
    	video privacy status (default "private")
  -quiet
    	suppress progress indicator
  -ratelimit int
    	rate limit upload in Kbps. No limit by default
  -secrets string
    	Client Secrets configuration (default "client_secrets.json")
  -tags string
    	comma separated list of video tags
  -thumbnail string
    	thumbnail filename. Can be a URL
  -title string
    	video title
  -version
    	show version

NOTE: When specifying a URL as the filename, the data will be streamed through the localhost (download from remote host, then upload to Youtube)

If -quiet is specified, no upload progress will be displayed. Current progress can be output by sending signal USR1 to the process e.g. kill -USR1 <pid> (Linux/Unix only).

Metadata

Video title, description etc can specified via the command line flags or via a JSON file using the -metaJSON flag. An example JSON file would be:

{
  "title": "my test title",
  "description": "my test description",
  "tags": ["test tag1", "test tag2"],
  "privacyStatus": "private",
  "madeForKids": false,
  "embeddable": true,
  "license": "creativeCommon",
  "publicStatsViewable": true,
  "publishAt": "2017-06-01T12:05:00+02:00",
  "categoryId": "10",
  "recordingdate": "2017-05-21",
  "playlistIds":  ["xxxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyy"],
  "playlistTitles":  ["my test playlist"],
  "language":  "fr"
}
  • all fields are optional
  • use \n in the description to insert newlines
  • times can be provided in one of two formats: yyyy-mm-dd (UTC) or yyyy-mm-ddThh:mm:ss+zz:zz
  • any values supplied via command line will take precedence

Releases

Releases are built with Goreleaser:

# Signed tag
git tag -s <tag>
git push --tags
GITHUB_TOKEN=xxxxyyy goreleaser release

Credit

Based on Go Youtube API Sample code

Thanks to github.com/tokland/youtube-upload for insight into how to update playlists.

youtubeuploader's People

Contributors

benlubar avatar jamesramsay avatar jorisrobijn avatar nobonobo avatar porjo avatar slavko-p avatar valleybell avatar wernight avatar wolfram77 avatar zennii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

youtubeuploader's Issues

Video Quality is drop

i tried to upload 1080p video and it becomes 360p max in youtube.

sorry my mistake youtube need time to process video before it appear as HD 1080p for 1 hours more video length

No progress indication

Command:
youtubeuploader -cache request.token -filename "xxxxxx/output.mkv" -metaJSON meta.json -secrets client_secrets.json -chunksize 0

Output:
Uploading file 'xxxxxx/output.mkv'... Upload successful! Video ID: [properVideoID] 2018/03/27 19:38:11 Error adding video to playlist: error retrieving playlists: googleapi: Error 403: Insufficient Permission, insufficientPermissions

Even though -quiet is not set I still get no current progress. This is using Youtubeuploader version: 18.07.

PS
I wouldn't worry with the error adding to playlist - I'll will fix permissions later.

how can i upload subtitles (cc) for a video?

i am using youtubeuploader to automatically upload wikipedia text-to-speech videos. one person asked me to upload such videos with subtitles. youtube has such a feature where i can add the text, and it will automatically align the time for the text. how can i upload such a text file through youtubeuploader? please help.

Error adding video to playlist

metajson

{
  "title": "my test title",
  "description": "my test description",
  "tags": ["test tag1", "test tag2"],
  "privacyStatus": "public",
  "embeddable": true,
  "license": "creativeCommon",
  "publicStatsViewable": true,
  "publishAt": "2017-06-01T12:00:00.000+02:00",
  "categoryId": "10",
  "recordingdate": "2017-05-21",
  "location": {
    "latitude": 48.8584,
    "longitude": 2.2945
  },
  "locationDescription":  "Eiffel Tower",
  "playlistId":  "PLhXu26RzZZTw2k4uFyuhhR9x7hCjYsyLM"
}
youtubeuploader_windows_amd64.exe -filename m.mp4 -metaJSON meta.json
Uploading file 'm.mp4'...
Progress:     2.56 Mbps, 24494960 / 24494960 (100.000%) ETA       0s
Upload successful! Video ID: bsruO7vI8zI
2018/03/03 20:32:02 Error adding video to playlist: error retrieving playlists: googleapi: Error 403: Insufficient Permission, insufficientPermissions

Error building OAuth client: expecting state 'st1538925745826976579', received state ''

$ ./youtubeuploader_linux_amd64 -filename video.mp4
Your browser has been opened to an authorization URL.  This program will resume once authorization has been provided.
2018/10/07 17:24:02 Error building OAuth client: expecting state 'st1538925842172918412', received state ''

Browser is opened with authorization url, but youtubeuploader immediately closes with above error

version 18.3

Activate monetization

Hi,
is there a way to pass an argument to activate monetization for uploaded video?
Thanks,
Francesco

release on pypi

This is an awesome tool. It would be cool to make it more accessible by publishing in on pypi.

Can't get "publishAt" working...

I'm having difficulty getting the "publishAt" setting in the metadata JSON file to do anything using version 18.08; every time I upload a video, it's just showing in my channel as "private", and not as "scheduled".

The command line I'm using is:

youtubeuploader_linux_armv7 -filename test.mp4 -metaJSON videoMetadata.json -ratelimit 10000 -secrets client_secrets.json

The contents of videoMetadata.json is taken almost verbatim from your example in the readme:

{
  "title": "my test title",
  "description": "my test description",
  "tags": ["test tag1", "test tag2"],
  "privacyStatus": "private",
  "embeddable": true,
  "license": "creativeCommon",
  "publicStatsViewable": true,
  "publishAt": "2018-04-20T09:30:00.000+01:00",
  "categoryId": "10",
  "recordingdate": "2017-05-21",
  "location": {
    "latitude": 48.8584,
    "longitude": 2.2945
  },
  "locationDescription":  "Eiffel Tower",
  "language":  "fr"
}

The only differences are that I've set the publishAt date to a date that is (currently) in the near future, and I've also removed the playlistIds value.

how to get video ID after upload

Thanks for this awesome software.

As @Cinerar said at #28, would be great if -quiet option return only the video ID with exit code 0 (zero) on success and 1 on error, redirecting the error message to stderr and the video ID to stdout.

Not a bug or something important, as today we can achieve this using sed:

X=`youtubeuploader -filename ${FILE}`
ID=`echo $X | sed -E 's/.*Video\ ID\:\ (.+).*/\1/'`;

But It's a good way to use youtubeuploader with bash scripts or other softwares.

Best regards!

Add multiple playlist?

Is it possible to add multiple playlist in the metaJSON file?

Example:
"playlistId": ["xxxxxxxxxxxxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyyyyyy"]

youtubeuploader -v

It would be nice if youtubeuploader was able to provide information on the version

Ability to authenticate without a browser

Other uploading scripts provide the user with an alternate way. While opening the browser the script also gives you link (which you can access from any computer) and it's waiting for a response to be pasted into it. Very useful when running script from an environment without proper graphic environment.

Retry upload upon a failure

Sometimes I'm hitting

Error 503: Backend Error

(up to 7% of uploads)
It would be nice to have a new parameter -retry [int] which would basically mean that if that error occurs the software stars uploading from a scratch a given number of tries. The side effect is that each failure means another copy on the uploaded video list but I suppose everyone would rather have the videos uploaded overnight and delete the corrupted copies rather than having to re-upload some of them.

Select channel

I can't find a way to select what channel the video goes to. It doesn't go to the channel selected as default channel for the account, but just to the account's own channel...

Pass authorization code as parameter

I am handling the authorization in my desktop application and already have the authorization code. Is there anyway to simply pass this in as a parameter? I realize I could write the info to disk and create my own request.token and client_secrets.json files, but I feel it would be cleaner and safer to just pass the access token in when I call the exe

about create playlist automatic

If I upload a video with an playlist which doesn't exist
It tell me error

2018/05/19 20:17:46 Error adding video to playlist: playlist ID xxxx doesn't exist

Can you create playlist automatic when it doesn't exist?

Backend error

"Error making YouTube API call: googleapi: Error 503: Backend Error, backendError"

What causes this?

No issue, just a success story

With little-to-no programming knowledge, I was able to get this going in under two minutes. I gave it a test MP4 (setting the privacy to unlisted) with a basic title and description. Uploaded with no issues at all.

I guess my only suggestion is to have a way to insert line breaks within the description (or maybe there is already?).

error when uploader

the error information:
2018/05/30 09:52:24 Error making YouTube API call: googleapi: Error 400: The req
uest metadata is invalid., invalidVideoMetadata

the meta json file:

{
  "title": "my test title",
  "description": "my test description",
  "tags": ["test tag1", "test tag2"],
  "privacyStatus": "public",
  "embeddable": true,
  "license": "creativeCommon",
  "categoryId": "22",
  "playlistIds":  ["PL-i_TB4my4RXO2_vwBW_qxzg-gZjUeYfBP"],
  "language":  "cn"
}

I had normal uploader using the metafile ,but now ,it suddenly reports the error, don't know what's wrong

Can't work with Google API creditial files

Hi Ian,

I followed your instructions on creating a secrets file. I noticed you mention at one place setting it to "web" and elsewhere to "installed" application type. I tried both, but I cannot get it going. Actually I let the secrets file initially be generated by the Google API web manager, on the Credentials page. It is accepted, however, when I run your program a browser opens that wants to go to "http://localhost:4001/" which doesn't work (no response from server). I dont understand where this comes from, can't find that port in config file. This is the case for both installed and web types. I did set the redirect_uris to http://localhost:8080/oauth2callback .

Any idea why this goes wrong?

Thanks,
Joris

no way to set chunksize

There is no way to set the chunksize which is rather important. One more option ( -1 should be acceptable) would be nice

Problem to add a playlist

Hello,

I have a little problem when i try to add a playlist.
I try this command:
youtubeuploader.exe -filename "test.avi" -metaJSON "test.json" -thumbnail "test.jpg"
With this JSON:

_{ "title": "test",
 "description": "test",
 "tags": ["test1", "test2"],
 "privacyStatus": "private",
 "embeddable": true,
 "publicStatsViewable": true,
 "recordingdate": "2013-04-20",
 "playlistIds": ["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-T"],
 "language":  "fr"
}_

I have this result:

Progress:   203.10 kbps, 223344138 / 223344138 (100.000%) ETA       0s
Upload successful! Video ID: xxxxxxx
Video added to playlist 'Playlist test' (xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
2018/06/28 12:51:11 Error adding video to playlist: playlist ID 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-T' doesn't exist_

The first playlist is ok, but the second no. My second playlist has a weird form with a "-": xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-T
Another problem is when a playlist is not added, the thumbnail is not uploaded.

Sorry for my english ;-(

Uploading from another machine than localhost

I would like to upload videos from my VPS, so I tried to set on Goolge dev console the VPS IP address as authorized redirect URI. It says: "Invalid Redirect: http://my-IP-address:8080/oauth2callback must end with a public top-level domain (such as .com or .org)"
On my VPS there is no GUI and browser, only SSH and CLI. How can I use this application to upload videos from the VPS if I can paste the long authorization URL only on another machine?

Error when building from source on Raspberry Pi

Hey! I'm trying to compile from source on a Raspberry Pi and I'm getting this error:

# google.golang.org/api/googleapi
../go/src/google.golang.org/api/googleapi/googleapi.go:289: u.RawPath undefined (type *url.URL has no field or method RawPath)
# golang.org/x/net/context/ctxhttp
../go/src/golang.org/x/net/context/ctxhttp/ctxhttp_pre17.go:36: req.Cancel undefined (type *http.Request has no field or method Cancel)

Any thoughts?

Headless w/ SSH

Hey, I have one other little problem. I'm using my Raspberry Pi in headless mode. When I run your program, it generates the link that I can open in the browser to authorize the app to work on behalf of my account. Since I'm SSH'd into the RPi, I can see the link and copy it into the browser in my host machine, but the redirect fails (since it's redirecting to localhost). I tried changing the client_secrets.json file so that the redirect_uris pointed to http://localhost:8080/oauth2callback, but then I got errors when I tried to open the link in the browser. I also tried running the program on my host machine and then copying the request.token file over to the RPi, but that didn't seem to do anything either. I even went so far as to install the links command line web browser on my RPi and tried to open the link in it, but the redirection requires JavaScript, which the links browser doesn't do. Any recommendations?

i can't understand how to use

i can't understand how to use
1、Run youtubeuploader for the first time, passing the -headlessAuth parameter
2、Copy-and-paste the URL displayed and open that in a browser
3、Copy the resulting authorisation code and paste that into the youtubeuploader prompt: "Enter authorisation code here:"

please tell me how to use it

Error at the end of an upload and YouTube cannot process the video

Hello 👻

I installed the program from archive to Ubuntu 16.04.1 x64 on DigitalOcean.
I used python3 setup.py install to install it.
I ran it twice with the same file and both times got the same error:

root@ubuntu-512mb-fra1-01:~# youtube-upload -t JC3-2 /var/lib/flussonic/archive/20170126.mp4
Using client secrets: /usr/local/share/youtube_upload/client_secrets.json
Using credentials file: /root/.youtube-upload-credentials.json
Start upload: /var/lib/flussonic/archive/20170126.mp4
100% |#####################################################################################################|   1.42 MB/s
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/youtube_upload/main.py", line 245, in main
    run_main(parser, options, args)
  File "/usr/local/lib/python3.5/dist-packages/youtube_upload/main.py", line 177, in run_main
    video_id = upload_youtube_video(youtube, options, video_path, len(args), index)
  File "/usr/local/lib/python3.5/dist-packages/youtube_upload/main.py", line 139, in upload_youtube_video
    request_body, progress_callback=progress.callback)
  File "/usr/local/lib/python3.5/dist-packages/youtube_upload/upload_video.py", line 42, in upload
    RETRIABLE_EXCEPTIONS, max_retries=max_retries)
  File "/usr/local/lib/python3.5/dist-packages/youtube_upload/lib.py", line 70, in retriable_exceptions
    return fun()
  File "/usr/local/lib/python3.5/dist-packages/youtube_upload/upload_video.py", line 40, in <lambda>
    upload_fun = lambda: _upload_to_request(request, progress_callback)
  File "/usr/local/lib/python3.5/dist-packages/youtube_upload/upload_video.py", line 24, in _upload_to_request
    status, response = request.next_chunk()
  File "/usr/lib/python3/dist-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/googleapiclient/http.py", line 880, in next_chunk
    return self._process_response(resp, content)
  File "/usr/lib/python3/dist-packages/googleapiclient/http.py", line 907, in _process_response
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 502 when requesting https://www.googleapis.com/upload/youtube/v3/videos?part=snippet%2Cstatus%2CrecordingDetails&uploadType=resumable&alt=json returned "Bad Gateway">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/youtube-upload", line 10, in <module>
    main.run()
  File "/usr/local/lib/python3.5/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/python3.5/dist-packages/youtube_upload/lib.py", line 42, in catch_exceptions
    fun(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/youtube_upload/main.py", line 247, in main
    response = bytes.decode(error.content, encoding=lib.get_encoding()).strip()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1441: ordinal not in range(128)

Both videos appeared on YouTube as unprocessed. It has now been ~6 hours since the last one and they still haven't been processed. It looks like they are corrupted.

It would be nice to understand what was the problem.

Thank you!

Headless authorization error

youtubeuploader -filename "xxxxxx/output.mkv" -metaJSON meta.json -secrets client_secrets.json -chunksize 0 -headlessAuth

Visit the URL for the auth dialog: [link here] Enter authorisation code here:

I copy and paste the link to browser on another PC which is fine.
I authorize the app to do things which is fine.

Then I get moved to:
http://localhost:8080/oauth2callback?state=[state]&code=[code]#
(state and code being some proper values)
Then I get ERR_CONNECTION_REFUSED on my browser. I suppose there is nothing listening on port 8080 even less replying on another PC?

Multi-line description

Hey, this may be a stupid question, but is it possible to create a multi-line video description? If so, how do you do it?
Thanks in advance

Unexpected EOF

Hi -
There've been several videos that I've tried to upload via URL that's stopped with an "unexpected EOC" message. When this happens it shows as processing in YouTube.

Totally understand that stuff happens. What's weird is that they've all stopped at exactly 16,777,216 bytes transferred. Is there something special about that number as to why it fails at that spot. Each that's failed is at that same number.

Plenty of other videos have worked fine, and on a couple I've tried to upload again and it worked fine.

ETA:
I went back and tried the one that just triggered the error and it uploaded without a problem, so I don't think it's specific to the file.

Age-Restriction

Hi,

Not an issue as such however there appears to be no way of setting age restricted content? is this correct?

Kind Regards
Tog

Add new parameter for user contribution

I don't known if youtube allow this, but a new parameter for user contribution would be great.
User contribution is in "advanced settings" in youtube:
drawing
Capture is in french but in english the position must be the same. In english this option is probably named like this: "Allow Internet users to contribute to the translation of titles, descriptions and subtitles".

meta.json vs command line option

I think that there is no rule which parameters can be passed as an opntion and which need to be run through meta.json. I think that everything should be possible via both ways or there should be some kind of logic to it.

(I'd actually benefit from command line option for playlist id which is not available but that's beside the point)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.