com.jimischopp.jyoutube
Class JYouTube

java.lang.Object
  extended by com.jimischopp.jyoutube.JYouTube
All Implemented Interfaces:
JYouTube.ProgressReportingFilePart.ProgressListener

public class JYouTube
extends java.lang.Object
implements JYouTube.ProgressReportingFilePart.ProgressListener

JYouTube A utility for uploading (and downloading) video content from YouTube programmatically. This class is a direct Java port of PHPTube by Michael Kamleitner (michael.kamleitner@gmail.com or http://www.kamleitner.com/code) Note that this class depends on: commons-httpclient (developed with version 3.1) commons-logging (developed with version 1.1) commens-codec (dependency of logging; developed with version 1.3) Quite often these files are quite large, so if you implement the "ProgressListener" interface, and add it to the listen of listeners on the JYouTube instance, you can receive updates about the upload progress. This is extremely useful. Also, in the interim, you can set the JYouTube instance itself as its own listener, since it implements the listener and logs to its logger (ie. myJYTube.addListener(myJYTube))

Version:
1.0
Author:
James Schopp

Nested Class Summary
static class JYouTube.Catgeory
          A list of video content categories as recognized by YouTube.
static class JYouTube.ProgressReportingFilePart
          ProgressReportingFilePart issues events to listeners updating them about the progress of a multi-part file upload of an HTTP request.
 
Field Summary
static java.lang.String USER_AGENT
           
static java.lang.String YT_COOKIE_LOGININFO
           
static java.lang.String YT_URL_GET
           
static java.lang.String YT_URL_LOGIN
           
static java.lang.String YT_URL_LOGIN_PASSWORD_KEY
           
static java.lang.String YT_URL_LOGIN_USERNAME_KEY
           
static java.lang.String YT_URL_MYVIDEOS
           
static java.lang.String YT_URL_PUT_MYVIDEOUPLOAD
           
static java.lang.String YT_URL_ROOT
           
static java.lang.String YT_URL_VIDEOID_KEY
           
static java.lang.String YT_URL_VIDEOIDTEMP_KEY
           
static java.lang.String YT_URL_VIEW
           
 
Constructor Summary
JYouTube()
          Create a new JYouTube object with no user/pass.
JYouTube(java.lang.String username, java.lang.String password)
          Create a new JYouTube object with the specified username/password.
 
Method Summary
 void addListener(JYouTube.ProgressReportingFilePart.ProgressListener listener)
          Add a new ProgressListener to the list of listeners to receive HTTP upload progress updates
 void download(java.lang.String videoId, java.lang.String videoFilename)
          Download existing video content to the specified local filename.
 void progressUpdate(JYouTube.ProgressReportingFilePart.ProgressUpdateEvent event)
          Default implementation of the ProgressListener interface, useful for logging when the calling app has not yet implemented the listener interface.
 boolean removeListener(JYouTube.ProgressReportingFilePart.ProgressListener listener)
          Remove a listener from the list of HTTP upload progress update listeners
 void setProxy(java.lang.String proxyHostName, int proxyPort)
          Set a proxy host for the underlying HttpClient object.
 java.lang.String upload(java.lang.String videoFilename, java.lang.String videoTitle, java.lang.String videoTags, java.lang.String videoDescription, JYouTube.Catgeory cat, java.lang.String videoLanguage, boolean isPublic)
          Upload new video content.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

YT_COOKIE_LOGININFO

public static final java.lang.String YT_COOKIE_LOGININFO
See Also:
Constant Field Values

YT_URL_LOGIN_USERNAME_KEY

public static final java.lang.String YT_URL_LOGIN_USERNAME_KEY
See Also:
Constant Field Values

YT_URL_LOGIN_PASSWORD_KEY

public static final java.lang.String YT_URL_LOGIN_PASSWORD_KEY
See Also:
Constant Field Values

YT_URL_VIDEOID_KEY

public static final java.lang.String YT_URL_VIDEOID_KEY
See Also:
Constant Field Values

YT_URL_VIDEOIDTEMP_KEY

public static final java.lang.String YT_URL_VIDEOIDTEMP_KEY
See Also:
Constant Field Values

YT_URL_ROOT

public static final java.lang.String YT_URL_ROOT
See Also:
Constant Field Values

YT_URL_LOGIN

public static final java.lang.String YT_URL_LOGIN
See Also:
Constant Field Values

YT_URL_VIEW

public static final java.lang.String YT_URL_VIEW
See Also:
Constant Field Values

YT_URL_GET

public static final java.lang.String YT_URL_GET
See Also:
Constant Field Values

YT_URL_PUT_MYVIDEOUPLOAD

public static final java.lang.String YT_URL_PUT_MYVIDEOUPLOAD
See Also:
Constant Field Values

YT_URL_MYVIDEOS

public static final java.lang.String YT_URL_MYVIDEOS
See Also:
Constant Field Values

USER_AGENT

public static final java.lang.String USER_AGENT
See Also:
Constant Field Values
Constructor Detail

JYouTube

public JYouTube()
         throws java.lang.Exception
Create a new JYouTube object with no user/pass. You can download with this, but you will not be able to upload new video content.

Throws:
java.lang.Exception

JYouTube

public JYouTube(java.lang.String username,
                java.lang.String password)
         throws java.lang.Exception
Create a new JYouTube object with the specified username/password. This object is capable of uploading new video content.

Parameters:
username -
password -
Throws:
java.lang.Exception
Method Detail

setProxy

public void setProxy(java.lang.String proxyHostName,
                     int proxyPort)
Set a proxy host for the underlying HttpClient object. Besides the "usual" reasons for using a proxy, this is primarily useful if/when debugging HTTP requests using the HTTPTracer tool in "proxy mode".

Parameters:
proxyHostName -
proxyPort -

download

public void download(java.lang.String videoId,
                     java.lang.String videoFilename)
              throws java.lang.Exception
Download existing video content to the specified local filename. The video will be in FlashVideo "flv" format.

Parameters:
videoId -
videoFilename -
Throws:
java.lang.Exception

upload

public java.lang.String upload(java.lang.String videoFilename,
                               java.lang.String videoTitle,
                               java.lang.String videoTags,
                               java.lang.String videoDescription,
                               JYouTube.Catgeory cat,
                               java.lang.String videoLanguage,
                               boolean isPublic)
                        throws java.lang.Exception
Upload new video content. Note that after a successful upload, your video will still not be immediately available since the YouTube servers must transcode your format to "flv" Flash Video format first. Only then will your new videoId be valid.

Parameters:
videoFilename - name of the local file to be uploaded
videoTitle - Video-Title on YouTube
videoTags - blank-separated list of keywords to tag the video content with for later search
videoDescription - description of the video
cat - category of the video content (sports, comedy, etc...)
videoLanguage - language of the video (DE, EN, etc...)
isPublic - if this video is viewable by the general public or not
Returns:
the videoId of the new content on YouTube
Throws:
java.lang.Exception

addListener

public void addListener(JYouTube.ProgressReportingFilePart.ProgressListener listener)
Add a new ProgressListener to the list of listeners to receive HTTP upload progress updates

Parameters:
listener -

removeListener

public boolean removeListener(JYouTube.ProgressReportingFilePart.ProgressListener listener)
Remove a listener from the list of HTTP upload progress update listeners

Parameters:
listener -
Returns:

progressUpdate

public void progressUpdate(JYouTube.ProgressReportingFilePart.ProgressUpdateEvent event)
Default implementation of the ProgressListener interface, useful for logging when the calling app has not yet implemented the listener interface.

Specified by:
progressUpdate in interface JYouTube.ProgressReportingFilePart.ProgressListener