Howto: Youtube auto-upload script

So you’re making lots of movies and you want things to upload to youtube automatically without you having to do any heavy lifting? If you are comfortable with a little bit of terminal and command line stuff, no problem.

A few things you will need:
Gmail account and Youtube account. These will be linked. You can use one gmail account as the developer for multiple youtube accounts but each youtube account needs it’s own independent email address, and for multiple gmail accounts you might need to get some dummy address at yahoo.com or mail.com as an alternative email. Then get yourself a developer key while logged into your developer gmail account.

Python 2.6 is probably already installed. But if not, install that too.

We’ve gotten this working for MacOSX and Linux (ubuntu 9.10 and fedora 11 anyway).
It’s probably not too hard to get it working with Windows but we’ve never tried.

Files you need:
uploader2.py at http://gist.github.com/319734
edit login information for youtube and gmail accounts.
edit developer key. edit the keywords and description to fit your project.

videochecker.sh at https://gist.github.com/e2569bca9313b1056c0e
check the path.
Thanks to Sean Levin for writing these.

Gdata and Atom directories. They are zipped and downloadable here: http://www.divshare.com/download/11521457-3da Unzip and place into same directory as uploader2.py.

Copy these files into whatever directory you will be uploading videos from.
You will now need to edit both of these files as noted above. Do you have a favorite text editor for simple code? We like smultron on mac and gedit or emacs on linux but any will do. Whatever music you like.

make sure both files are executable.

chmod 755 uploader2.py
chmod 755 videochecker.sh

then try it out manually. from the video directory prompt try running the videochecker.
yourvideodirectory$ ./videochecker.sh
Got Upload directory
You have a save directory
Not running
just before loop start
inside for loop
Uploading OMPD-20100301-20100302.mp4
uploader-log: running doit with the_time=2010-03-02T00:00:53 and the_filename=OMPD-20100301-20100302.mp4
uploader-log: created media_group
uploader-log: created youtube entry
uploader-log: created YouTubeService
uploader-log: attempting to find previous login token in token file
uploader-log: token file found
uploader-log: set login token to DQAAAHUAAA ...
uploader-log: trying login with captcha_token=None and captcha_response=None
uploader-log: login succeeded continuing on to upload
uploader-log: saving token (DQAAAHYAAABXiMigRrgi5 ... ) to token file (youtube_login_token.txt)
uploader-log: starting to upload video entry
uploader-log: completed upload of video entry
uploader-log: OMPD-20100301-20100302.mp4 uploaded to service successfully. Returning success to calling script (0)
yourvideodirectory$

if you’re getting an error with videochecker, try changing the first line to
#! /bin/bash -ex and it will output lots of extra info as it runs.

Ok. So you made it that far and now you want to set it up so it runs automatically each day or week or hour. Time for crontab. What is a crontab you ask? It’s sort of like asking your alarm clock to run a program instead of make a loud sound. It’s just a simple text file that you add some instructions to. The only problem is that you usually edit it in vi (a text editor). vi is nice and all but it’s rather confusing if you haven’t used it before. With vi, there are 2 modes, insert-text mode and command mode. 3 most useful key sequences are:
i – enter insert mode,
esc – exit insert mode
ZZ – save file and exit program.
Want to learn more: http://heather.cs.ucdavis.edu/~matloff/UnixAndC/Editors/ViIntro.html

In the terminal window (here your current path matters not), enter
crontab -e
type i to put the editor in INSERT mode. (see text in bottom left of editor)

- then make your crontab look like:
# m h dom mon dow command
*/10 * * * * /home/yourlinuxboxname/Videos/Webcam/videochecker.sh

(which runs that script every 10 minutes.)
or

# m h dom mon dow command
* 3 * * * /home/yourmac/Movies/AUTOUPLOAD/videochecker.sh

(which runs that script at 3am each evening. But only when the computer is awake.)

- hit the ‘esc’ key to get out of insert mode.

- then type ZZ to save and exit.

Let us know how this works for you and we will try to keep an updated version of these instructions.

About these ads

Tags: , , , , , , ,

32 Responses to “Howto: Youtube auto-upload script”

  1. One Minute Per Day instructions, b1 « Plebian Design: Blog Says:

    [...] Want automatic uploading to YOUTUBE? Follow the instructions here: http://broadcasterproject.wordpress.com/2010/03/03/howto-youtube-auto-upload-script/ [...]

  2. Lars Says:

    I’m running ubuntu 10.04, and am having serious issues with the videochecker.sh script: It gave me a ton of error messages until I removed quotes from some of the string variables like SEARCH_DIR.

    This is what I have so far:
    lhaeh@ubuntu:~/youtube$ ./videochecker.sh
    “Got Videos directory”
    “You have a save directory”
    “Not running”
    ./videochecker.sh: line 105: syntax error near unexpected token `done’
    ./videochecker.sh: line 105: `done’

    Maybe it is not picking up where my videos are? Thanks for making this, it looks like it will be very useful.

  3. danielpaluska Says:

    lars,
    mac and linux handle shell differently and i think you need to delete the ” ” around any variable name. or better yet, just regrab the gist. i just deleted them all from it.

    for those who want the mac version, it’s this version https://gist.github.com/e2569bca9313b1056c0e/7730b56f15f47f18e3f74600eb34d3410d4ebb86

    one other thing, i forgot to include atom and gdata directories which you need as well: http://www.divshare.com/download/11521457-3da
    download and unzip this and there will be 2 directories (gdata and atom) and place these into same folder as uploader2.py

  4. How to make a timelapse shared memory server « The Broadcaster Project Says:

    [...] If you’d like the movies to upload to a youtube channel automatically every night, you can do that as well. Instructions here. [...]

  5. python uploading scripts for youtube « The Broadcaster Project Says:

    [...] python uploading scripts for youtube By t he ans weri saque stion? UPDATE: condiser skipping this post and going right to this newer one: http://broadcasterproject.wordpress.com/2010/03/03/howto-youtube-auto-upload-script/ [...]

  6. greg Says:

    Hello Guys, I love th elook of this. Two questions though.

    Can it be adapted to PHP?
    And does it still work in these days of YouTube API?

    thanks

    • t he ans weri saque stion? Says:

      yes this still works. we use it all the time.

      it probably can be adapted to php if someone takes the time to do the work.

  7. Digika Says:

    Hey, the uploader2.py is your script, right? Can you update it to support the ability to specify video name, category and description?

    • t he ans weri saque stion? Says:

      yes you can edit the python file to change the name, category, and description. just edit uploader2.py in a text editor that will keep the spaces as they are. python is space and tab sensitive.

  8. All Asia Timelapse Twvee « The Broadcaster Project Says:

    [...] The machine also uses the youtube uploader stuff described in this post. [...]

  9. Gavin Says:

    Ready made python uploader here:

    http://code.google.com/p/youtube-upload/

  10. Robert Ojok Says:

    youtube uploader
    I have followed the instructions as listed. When I run manually the video checker I get

    You have new mail.
    ojokr:~ robert$ cd /Users/robert/Desktop/YOUTUBEROBERT
    ojokr:YOUTUBEROBERT robert$ ./videochecker.sh+ SEARCH_DIR=/Users/robert/Desktop/YOUTUBEROBERT/MyVideos/MyVideos
    + COPY_DIR=/Users/robert/Desktop/YOUTUBEROBERT/MyVideos/MyVideos/copies
    + ‘[' -d /Users/robert/Desktop/YOUTUBEROBERT/MyVideos/MyVideos ']‘
    + echo $’?\200\234Got’ Videos $’directory?\200\235′
    “Got Videos directory”
    + cd /Users/robert/Desktop/YOUTUBEROBERT/MyVideos/MyVideos
    + ‘[' -d /Users/robert/Desktop/YOUTUBEROBERT/MyVideos/MyVideos/copies ']‘
    + echo $’?\200\234You’ have a save $’directory?\200\235′
    “You have a save directory”
    ++ basename ./videochecker.sh
    + PDIR=./
    ++ basename ./videochecker.sh
    + LCK_FILE=videochecker.sh.lck
    + ‘[' -f videochecker.sh.lck ']‘
    ++ head -n 1 videochecker.sh.lck
    + MYPID=2048
    ++ ps -p 2048
    ++ grep 2048
    + TEST_RUNNING=
    ojokr:YOUTUBEROBERT robert$

    When i run the upload in terminal Mac I get the following error

    robert$ /Users/robert/Desktop/YOUTUBEROBERT/uploader2.py
    from: can’t read /var/mail/gdata.youtube
    from: can’t read /var/mail/gdata.youtube.service
    /Users/robert/Desktop/YOUTUBEROBERT/uploader2.py: line 3: import: command not found
    from: can’t read /var/mail/gdata.service
    from: can’t read /var/mail/optparse
    /Users/robert/Desktop/YOUTUBEROBERT/uploader2.py: line 8: import: command not found
    /Users/robert/Desktop/YOUTUBEROBERT/uploader2.py: line 9: import: command not found
    /Users/robert/Desktop/YOUTUBEROBERT/uploader2.py: line 10: import: command not found
    /Users/robert/Desktop/YOUTUBEROBERT/uploader2.py: line 13: debug: command not found
    /Users/robert/Desktop/YOUTUBEROBERT/uploader2.py: line 15: syntax error near unexpected token `(‘
    /Users/robert/Desktop/YOUTUBEROBERT/uploader2.py: line 15: `def log(line):’
    ojokr:YOUTUBEROBERT robert$

    Any suggestions?

    • t he ans weri saque stion? Says:

      do you have the gdata and atom directories installed? i think that is the error. check the divshare link above and make sure those directories are in the same directory as the .py script.

      also, you should consider using this program instead, i think it is better. works well on linux, but i haven’t tried it on mac.
      Ready made python uploader here:

      http://code.google.com/p/youtube-upload/

      • Robert Ojok Says:

        Thanks for the python however it appears that I cannot auto upload as in the one above. Both the atom gdata are in the same folder as the videochecker.sh and upload2.py. I removed them from the folder Atom-Gdata and placed them both at top level of the folder.

        When I run the uploader2.py I get the following report. There must be more that needs modifying than the above instructions provide?

        Thanks anyway for the help

        /Users/robertojok/Desktop/YouTubeupload/uploader2.py
        from: can’t read /var/mail/gdata.youtube
        from: can’t read /var/mail/gdata.youtube.service
        /Users/robertojok/Desktop/YouTubeupload/uploader2.py: line 3: import: command not found
        from: can’t read /var/mail/gdata.service
        from: can’t read /var/mail/optparse
        /Users/robertojok/Desktop/YouTubeupload/uploader2.py: line 8: import: command not found
        /Users/robertojok/Desktop/YouTubeupload/uploader2.py: line 9: import: command not found
        /Users/robertojok/Desktop/YouTubeupload/uploader2.py: line 10: import: command not found
        /Users/robertojok/Desktop/YouTubeupload/uploader2.py: line 13: debug: command not found
        /Users/robertojok/Desktop/YouTubeupload/uploader2.py: line 15: syntax error near unexpected token `(‘
        /Users/robertojok/Desktop/YouTubeupload/uploader2.py: line 15: `def log(line):’

      • Robert Ojok Says:

        I forgot to mention that the line 3: import: command not found

        When I checked the uploader2.py line 3 it has

        import gdata

        Is that correct or should it be modified?

    • t he ans weri saque stion? Says:

      robert do you have developer tools installed?
      xcode?
      try this at the command line to see if you have python 2.6
      robert$which python

  11. Robert Ojok Says:

    I edited the files that I am required to edit in Text wrangler. the Files are already available from the download

  12. Sherif Says:

    The script is great but I am having the problem below.

    “Got Videos directory”
    “You have a save directory”
    “Not running”
    “Uploading ./0050.flv”
    /usr/local/bin/gdata/tlslite/utils/cryptomath.py:9: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
    import sha
    uploader-log: running doit with the_time=20110704171025 and the_filename=./0050.flv

    uploader-log: created media_group

    uploader-log: created youtube entry

    uploader-log: created YouTubeService

    uploader-log: attempting to find previous login token in token file

    uploader-log: unable to set previous login token, continuing with default login settings

    uploader-log: trying login with captcha_token=None and captcha_response=None

    uploader-log: Some Error ocurred, returning failure to calling script (1)

    global name ‘Error’ is not defined

    any help will be appreciated…

  13. Robert Ojok Says:

    I gave up. I do not think that the script works. If it does then there is considerably more that needs to be done to it for it to work.
    This one
    “http://code.google.com/p/youtube-upload/”
    seems better BUT means you would have to keep modifying it each time to get a file uploaded.
    I thought I could use podcast producer workflow to post files to a folder then have the above script run from that folder and upload to youtube; BUT cannot get it to work.

  14. Ted Says:

    Hi – I am running a Joomla site with lots of users uploading video into JomSocial stream – I want to be able to cron load user videos to our YT channel automatically. does anyone know of a Joomla plugin or component that can handle this task? Anyone who can do this – i can pay for DEV. Please let me know.

    Peace

  15. planetzuda Says:

    Is this GPL? What license is this under?

  16. Ivica Says:

    Should this work with Python 2.4? For some reason I have it on my VPS – no other reason to upgrade. But if necessary, I will. I’m also getting error

    uploader-log: trying login with captcha_token=None and captcha_response=None

    uploader-log: Some Error ocurred, returning failure to calling script (1)

    Could it be Python or it’s something else?

    • t he ans weri saque stion? Says:

      i apologize, it’s been a while since i ran this script.
      but i’m guessing it’s youtube login not successful rather than python version.
      i will try to run again sometime in next couple weeks and report back…

      • Ivica Says:

        Hello. No need for apologizes. Your response wa quite fast for private blog. However, I need to report to you and any other interested parties that it was Python version. Script is still functional and already running on my CentOS box :)

      • t he ans weri saque stion? Says:

        great! thanks!

  17. bharathcinemashansa Says:

    Can you please post for windows os?

    • t he ans weri saque stion? Says:

      if you install cygwin it most of the rest of the instructions should be useable.
      i don’t own a windows machine so i can’t do it but if you try it out, i can post it here or link to you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: