[localhost:~]$ cat * > /dev/ragfield

Wednesday, July 8, 2009

Upload videos to YouTube with Mathematica

First, install the GData package in $UserBaseDirectory/Applications. Load the GData package which contains the code used to interact with YouTube (and other Google services).
<<GData`
Next, log in to YouTube. This will prompt for a user name and/or password if either is not specified.
yt = YouTubeLogin["User"->"robragfield"]
YouTube[<...>]
We can make sure it's working by asking for a list of videos uploaded to this account.
("Title"/.#)&/@YouTubeUploads[yt]
{OmetepeProfile.mov, Homer Fireworks, Tripod, Cobb Park Crit, Mt. Diablo descent, Seymour TT starts, Screaming hard drive, Descent (iMovie image stabilization comparison), Descent, Descent, Carpenter Park Cross #2 (Line Art), Indy Marathon chase}
We can also check out other accounts.
YouTubeUploads[yt, "wolframmathematica"]//Length
950
Finally, we can upload a new video to YouTube.
YouTubeUpload[yt, "/Users/schofield/Movies/carpenter_park_2.mp4", "Title"->"Carpenter", "Description"->"Carpenter Park cyclocross race"]
«JavaObject[com.google.gdata.data.youtube.VideoEntry]»
You can also specify the category and keywords.
Options[YouTubeUpload]
{Title->Automatic, Description->Undescripted, Category->Tech, Keywords->{uploaded by Mathematica}}

4 comments:

Sander Huisman said...

Trying to get this working...
So i put the folder GData next to the notebook. And ran the notebook. I added
SetDirectory[NotebookDirectory[]]
on the first line to make it even find th GData package.
When i then load the package it gives me a nice message:
Java::excptn: A Java exception occurred: java.lang.ClassNotFoundException: com.google.gdata.data.youtube.YouTubeNamespace
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242).

LoadJavaClass::fail: Java failed to load class com.google.gdata.data.youtube.YouTubeNamespace. >>


What basically means that "com.google.gdata.data.youtube.YouTubeNamespace" can't be found. So I opened the init.m inside the kernel folder, and on the second input line of the YouTube section it spawns the error. Do I need additional material? I'm not very familiar with java.

Best Regards,

Sander Huisman

Sander Huisman said...

Forgot to mention, i'm using:
$Version =>
"7.0 for Mac OS X x86 (64-bit) (February 19, 2009)"

Sander

Ragfield said...

Sorry for the confusion. The GData package should be installed in the standard location:

~/Library/Mathematica/Applications/

I'll update the post to reflect this.

-Rob

Sander Huisman said...

Thanks Rob!
Got it working! Not yet tried the uploading part, but the other functions seem to work.
Let's see if I can somehow get the number of views of my videos, and find the grand total!

Sander