Re: Re: Help With Custom onlinemedia.xml – Youtube
Home › Forums › Help and Support › Help With Custom onlinemedia.xml – Youtube › Re: Re: Help With Custom onlinemedia.xml – Youtube
http://pagesofinterest.net/wiimc/youtube.php
For now, one can use this URL to query like so:
For a user’s videos as a list, similar to an RSS feed for a blog:
This will show about 20-24 of the most recent uploads by the given user, with most recent videos appearing first.
Url: http://pagesofinterest.net/wiimc/youtube.php?q=USERNAME%26type=user
Both q and type are required.
Required parameters:
- q = the username, e.g. “HDStarcraft”
- type = ‘user’
For a more general search:
This may be used to generate more customizable playlists.
URL: http://pagesofinterest.net/wiimc/youtube.php?q=QUERY_STRING
Possible parameters:
- q = the text you are searching for, e.g. ‘wiimc rocks’
- order_by = optional the order you want results in, one of: relevance, view_count, updated, or rating
- safe = optional level of safe-search you want imposed, one of: none, moderate or strict
- author = optional the author of the videos you’re searching for
Examples:
In the format required by onlinemedia.xml.
Now I can have HDStarcraft’s Youtube feed on my Wii!
For more information on the Youtube API: http://code.google.com/apis/youtube/2.0/developers_guide_php.html
There are many possibilities, if there is a C++ programmer out there interested in extending WiiMC’s Youtube functions further, I’m able to handle the PHP side.
Does what I want anyway, here is the source:
<?php
//Requires: http://framework.zend.com/download/gdata/
ini_set("include_path", '/must/point/to/folder/containing/Zend_folder');
require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
Zend_Loader::loadClass('Zend_Gdata_YouTube');
class wiiMcPlaylistRetriever extends Zend_Gdata_YouTube {
const YOUTUBE_BASE = 'http://gdata.youtube.com/';
const STANDARD_FEED_PREFIX = 'feeds/api/standardfeeds/';
const YOUTUBE_USER_SEARCH = 'feeds/base/users/';
const PLAYLIST_HEAD = '[playlist]';
// $_GET keys:
const QUERY = 'q';
const QUERY_TYPE = 'type'; // user, author
const ORDER_BY = 'order_by'; // relevance, view_count, updated, or rating
const SAFE_SEARCH = 'safe'; // none, moderate or strict
const AUTHOR = 'author';
// Possible $_GET values:
const QUERY_TYPE_USER = 'user';
const QUERY_TYPE_GENERAL = 'general';
function __construct()
{
parent::__construct();
$this->setMajorProtocolVersion(2);
$this->beginRetrieval();
}
function beginRetrieval()
{
$args = Array();
if( isset( $_GET[ self::QUERY ] ) ){ // This is a search
$args[ self::QUERY ] = $_GET[ self::QUERY ];
if( isset( $_GET[ self::QUERY_TYPE ] ) ){
$args[ self::QUERY_TYPE ] = $_GET[ self::QUERY_TYPE ];
}
}
if( isset( $_GET[ self::ORDER_BY ] ) ){
$args[ self::ORDER_BY ] = $_GET[ self::ORDER_BY ];
}
if( isset( $_GET[ self::SAFE_SEARCH ] ) ){
$args[ self::SAFE_SEARCH ] = $_GET[ self::SAFE_SEARCH ];
}
if( isset( $_GET[ self::AUTHOR ] ) ){
$args[ self::AUTHOR ] = $_GET[ self::AUTHOR ];
}
if( isset( $args[ self::QUERY ] ) ){ // This is a search
echo $this->doSearch( $args );
}
}
/**
* Perform the search with given arguments
*
* @author Michael Robinson
* @param unknown_type $args
*/
function doSearch( $args=Array() )
{
$uri = '';
$params = Array();
// USER
if( isset( $args[ self::QUERY_TYPE ] ) && self::QUERY_TYPE_USER == $args[ self::QUERY_TYPE ] ){
return $this->generateStandardPlaylist( $this->getUserUploads( $args[ self::QUERY ] ) );
}
// NORMAL SEARCH WITH PARAMS
else{
$query = $this->newVideoQuery();
if( isset( $args[ self::ORDER_BY ] ) ){
$query->setOrderby( $args[ self::ORDER_BY ] );
}
if( isset( $args[ self::SAFE_SEARCH ] ) ){
$query->setSafeSearch( $args[ self::SAFE_SEARCH ] );
}
if( isset( $args[ self::AUTHOR ] ) ){
$query->setAuthor( $args[ self::AUTHOR ] );
}
$query->setVideoQuery( $args[ self::QUERY ] );
return $this->generateStandardPlaylist( $this->getVideoFeed( $query->getQueryUrl( 2 ) ) );
}
}
/**
* Prints a video feed in the format expected by WiiMC
*
* [playlist]
*
* File1=http://www.youtube.com/watch?v=l9gPGYqpAuA
* Title1=HD Starcraft 2 BoxeR v Set
* Length1=-1
*
* File2=http://www.youtube.com/watch?v=cmD5b85x_rw
* Title2=HD Starcraft 2 IdrA v Ddoro
* Length2=-1
*
* ( ... )
*
* @author Michael Robinson - [email protected] Copyright (c) ECPod, 2010
* @param $videoFeed
*/
function generateStandardPlaylist( $videoFeed )
{
$playlist = '';
$len = sizeof( $videoFeed );
$playlist .= self::PLAYLIST_HEAD . "nn";
$i = 1;
foreach( $videoFeed as $videoEntry ){
$playlist .= "File$i=http://www.youtube.com/watch?v=" . $videoEntry->getVideoId() . "n";
$playlist .= "Title$i=" . $videoEntry->getVideoTitle() . "n";
$playlist .= "Length$i=" . ( ( !is_null( $videoEntry->getVideoDuration() ) ) ? $videoEntry->getVideoDuration() : '-1' ) . "nn";
$i++;
}
return $playlist;
}
}
$wiiMcPlaylistRetriever = new wiiMcPlaylistRetriever();
?>
