Plugin to upload video to YouTube directly from your site

Source code and sample available at:

Usage: Please note that sample is available for RoR3 but it can be easily converted for any underlying platform. Refer README in git repo above to know how to run it in RoR3. To see how to tweak code to use it for any other platform, keep reading the post.

Purpose of this Utility: It will upload end user’s video directly to youtube and is easily integratable within your website.

Few Advantage:

  • No need to have storage on server machine as you can now dump/use all videos directly to/from youtube.
  • In case you have youtube channel, can directly organize video uploaded through your site to youtube channel.
  • NO need for end user to login to youtube first to upload video through your site.

Flow to upload video on YouTube

  1. Website requests  token and upload URL from youtube for every new video request. This is needed to avoid having end user logging into his/her YouTube account.
  2. Post your video to URL received in step#1 with parameter ‘nexturl’. ‘nexturl’ is callback url to be called by YouTube with status and video_id once upload operation is completed with failure or success. You need to send token received in step#1 too along with.
  3. Youtube invokes ‘nexturl’ with status and video_id, if upload is successful. Process/store this video_id as this will be key from now onwards based on which you can perform operations on this video directly in YouTube.

Source code contains of following things that you need to know:– Python script that uses Google Data Python client library.  This script contains few methods performing certain operation on youtube.

Usage: py [-t <comma separated title and description>] [-u <video_id>] [-s <video_id>] [-d <video_id>]

-t => to get token and url. Input required is comma separated video title and video description

-u => to get youtube URL for that video. Input required is video_id

-s => to get upload status of the video. Input required is video_id

-d => to delete video from youtube. Input required is video_id


    • Please refer Getting Started guide. In nutshell, you need to install Python and then google Data Library as specified in the link.
    • Replace following senstive data inside python script; like developer key, password, etc. with that of yours. You will need to sign in for YouTube developer key. Once signed in, register you product and get values for below attributes. ‘source’ and ‘client_id’   will be the name of the product you registered before.

yt_service.developer_key = ‘xxxxxxx’

yt_service.client_id = ‘xxxxxxx’ = ‘xxxxxxx’

yt_service.password = ‘xxxxxxxx’

yt_service.source = ‘xxxxxxxxxx’

  • Since above utility contains some sensitive data, hence for security reasons you would need to introduce a server side handler that will execute above script on client request and can send the required details back to client. In our case, we have introduced method ‘uploadToken’ inside multimedia controller which execute python script and returns back token and url needed to upload video on youtube.

[gist id=9885986309e63e38a598]

  • Below is the HTML code you’ll plug into your website to let end user select the video and upload it to youtube. Code just contains a form to have end use select the video and has action, token value blank at render time. If you have already noticed, there is async ajax request present at end of code which fetches upload URL and token from server at time page is loading and populate it inside form once ajax request gets completed.

[gist id=7235b56ea6c039a9cab0]

3 thoughts on “Plugin to upload video to YouTube directly from your site

  1. Hi i am looking the Joomla Plugin to upload video to YouTube directly from your site is it possible. Or can we convert this code into joomla