README.md (6606B)
1 **THIS PROJECT NEEDS A MAINTAINER**. If someone is willing to take over the project, let me know (pyarnau AT gmail.com). 2 3 Introduction 4 ============ 5 6 Command-line script to upload videos to Youtube using theYoutube [APIv3](https://developers.google.com/youtube/v3/). It should work on any platform (GNU/Linux, BSD, OS X, Windows, ...) that runs Python. 7 8 Dependencies 9 ============ 10 11 * [Python 2.6/2.7/3.x](http://www.python.org). 12 * Packages: [google-api-python-client](https://developers.google.com/api-client-library/python), [progressbar2](https://pypi.python.org/pypi/progressbar2) (optional). 13 14 Check if your operating system provides those packages (check also those [deb/rpm/mac files](https://github.com/qiuwei/youtube-upload/releases)), otherwise install them with `pip`: 15 16 ``` 17 $ sudo pip install --upgrade google-api-python-client oauth2client progressbar2 18 ``` 19 20 Install 21 ======= 22 23 ``` 24 $ wget https://github.com/tokland/youtube-upload/archive/master.zip 25 $ unzip master.zip 26 $ cd youtube-upload-master 27 $ sudo python setup.py install 28 ``` 29 30 Or run directly from sources: 31 32 ``` 33 $ cd youtube-upload-master 34 $ PYTHONPATH=. python bin/youtube-upload ... 35 ``` 36 37 Setup 38 ===== 39 40 You'll see that there is no email/password options. Instead, the Youtube API uses [OAuth 2.0](https://developers.google.com/accounts/docs/OAuth2) 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](https://developers.google.com/youtube/v3/) policies. 41 42 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](https://developers.google.com/youtube/registering_an_application), it's a free service. Steps: 43 44 * Go to the Google [console](https://console.developers.google.com/). 45 * _Create project_. 46 * Side menu: _APIs & auth_ -> _APIs_ 47 * Top menu: _Enabled API(s)_: Enable all Youtube APIs. 48 * Side menu: _APIs & auth_ -> _Credentials_. 49 * _Create a Client ID_: Add credentials -> OAuth 2.0 Client ID -> Other -> Name: youtube-upload -> Create -> OK 50 * _Download JSON_: Under the section "OAuth 2.0 client IDs". Save the file to your local system. 51 * Use this JSON as your credentials file: `--client-secrets=CLIENT_SECRETS` or copy it to `~/client_secrets.json`. 52 53 *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```.* 54 55 Examples 56 ======== 57 58 * Upload a video (a valid `~/.client_secrets.json` should exist, check the Setup section): 59 60 ``` 61 $ youtube-upload --title="A.S. Mutter" anne_sophie_mutter.flv 62 pxzZ-fYjeYs 63 ``` 64 65 * 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): 66 67 ``` 68 $ youtube-upload \ 69 --title="A.S. Mutter" " \ 70 --description="A.S. Mutter plays Beethoven" \ 71 --category="Music" \ 72 --tags="mutter, beethoven" \ 73 --recording-date="2011-03-10T15:32:17.0Z" \ 74 --default-language="en" \ 75 --default-audio-language="en" \ 76 --client-secrets="my_client_secrets.json" \ 77 --credentials-file="my_credentials.json" \ 78 --playlist="My favorite music" \ 79 --embeddable=True|False \ 80 anne_sophie_mutter.flv 81 tx2Zb-145Yz 82 ``` 83 *Other extra medata available :* 84 ``` 85 --privacy (public | unlisted | private) 86 --publish-at (YYYY-MM-DDThh:mm:ss.sZ) 87 --location (latitude=VAL,longitude=VAL[,altitude=VAL]) 88 --thumbnail (string) 89 ``` 90 91 * Upload a video using a browser GUI to authenticate: 92 93 ``` 94 $ youtube-upload --title="A.S. Mutter" --auth-browser anne_sophie_mutter.flv 95 ``` 96 97 * Split a video with _ffmpeg_ 98 99 If your video is too big or too long for Youtube limits, split it before uploading: 100 101 ``` 102 $ bash examples/split_video_for_youtube.sh video.avi 103 video.part1.avi 104 video.part2.avi 105 video.part3.avi 106 ``` 107 * Use a HTTP proxy 108 109 Set environment variables *http_proxy* and *https_proxy*: 110 111 ``` 112 $ export http_proxy=http://user:password@host:port 113 $ export https_proxy=$http_proxy 114 $ youtube-upload .... 115 ``` 116 117 Get available categories 118 ======================== 119 120 * Go to the [API Explorer](https://developers.google.com/apis-explorer) 121 - Search "youtube categories" -> *youtube.videoCategories.list* 122 - This bring you to [youtube.videoCategories.list service](https://developers.google.com/apis-explorer/#search/youtube%20categories/m/youtube/v3/youtube.videoCategories.list) 123 - part: `id,snippet` 124 - regionCode: `es` (2 letter code of your country) 125 - _Authorize and execute_ 126 127 And see the JSON response below. Note that categories with the attribute `assignable` equal to `false` cannot be used. 128 129 Using [shoogle](https://github.com/tokland/shoogle): 130 131 ``` 132 $ shoogle execute --client-secret-file client_secret.json \ 133 youtube:v3.videoCategories.list <(echo '{"part": "id,snippet", "regionCode": "es"}') | 134 jq ".items[] | select(.snippet.assignable) | {id: .id, title: .snippet.title}" 135 ``` 136 137 Notes for developers 138 ==================== 139 140 * Main logic of the upload: [main.py](youtube_upload/main.py) (function ```upload_video```). 141 * Check the [Youtube Data API](https://developers.google.com/youtube/v3/docs/). 142 * Some Youtube API [examples](https://github.com/youtube/api-samples/tree/master/python) provided by Google. 143 144 Alternatives 145 ============ 146 147 * [shoogle](https://github.com/tokland/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. 148 149 * [youtubeuploader](https://github.com/porjo/youtubeuploader) uploads videos to Youtube from local disk or from the web. It also provides rate-limited uploads. 150 151 More 152 ==== 153 154 * License: [GNU/GPLv3](http://www.gnu.org/licenses/gpl.html). 155 156 Feedback 157 ======== 158 159 * [Donations](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=pyarnau%40gmail%2ecom&lc=US&item_name=youtube%2dupload&no_note=0¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest). 160 * If you find a bug, [open an issue](https://github.com/tokland/youtube-upload/issues). 161 * 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.