Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Add a method to add a video to a playlist, and a method to change the…
Browse files Browse the repository at this point in the history
… position of a video in a playlist
  • Loading branch information
sebdesign committed Sep 23, 2011
1 parent 1e14b42 commit 7313266
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions libraries/youtube.php
Expand Up @@ -41,6 +41,7 @@ class youtube
'STANDARD_MOST_VIEWED_URI' => 'feeds/api/standardfeeds/most_viewed',
'STANDARD_RECENTLY_FEATURED_URI' => 'feeds/api/standardfeeds/recently_featured',
'STANDARD_WATCH_ON_MOBILE_URI' => 'feeds/api/standardfeeds/watch_on_mobile',
'PLAYLIST_URI' => 'feeds/api/playlists',
'USER_URI' => 'feeds/api/users',
'INBOX_FEED_URI' => 'feeds/api/users/default/inbox',
'SUBSCRIPTION_URI' => 'feeds/api/users/default/subscriptions',
Expand Down Expand Up @@ -387,7 +388,7 @@ public function getInboxFeedForCurrentUser()
* @param $metadata the data to send for this request (usually XML)
* @return mixed false if not authroized otherwise the response is returned.
**/
private function _data_request($uri, $metadata)
private function _data_request($uri, $metadata, $method = 'POST')
{
if($this->_access !== false)
{
Expand All @@ -400,7 +401,7 @@ private function _data_request($uri, $metadata)

$extra .= "Content-Length: ".mb_strlen($metadata.self::LINE_END).self::LINE_END.self::LINE_END;

$fullrequest = $this->_build_header($url, $header, $extra, 'POST');
$fullrequest = $this->_build_header($url, $header, $extra, $method);
$fullrequest .= $metadata.self::LINE_END;

$handle = $this->_connect();
Expand Down Expand Up @@ -578,6 +579,33 @@ public function addFavorite($videoId)
$xml = "<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom'><id>{$videoId}</id></entry>";
return $this->_data_request("/{$this->_uris['FAVORITE_URI']}", $xml);
}

/**
* Adds specified video to the specified playlist
*
* @param string $videoId the youtube video you want to add to the playlist.
* @param string $playlistId the youtube playlist you want to add the video to.
* @return mixed false if not authenticated otherwise the http response is sent.
*/
public function addVideoToPlaylist($videoId, $playlistId)
{
$xml = "<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:yt='http://gdata.youtube.com/schemas/2007'><id>{$videoId}</id></entry>";
return $this->_data_request("/{$this->_uris['PLAYLIST_URI']}/{$playlistId}", $xml);
}

/**
* Sets the position of the specified video entry in the specified playlist
*
* @param string $playlistEntryId the youtube video entry you want to change the position.
* @param string $playlistId the youtube playlist you want to change the position.
* @param integer $position the position of the video in the playlist.
* @return mixed false if not authenticated otherwise the http response is sent.
*/
public function setVideoPositionInPlaylist($playlistEntryId, $playlistId, $position)
{
$xml = "<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:yt='http://gdata.youtube.com/schemas/2007'><yt:position>{$position}</yt:position></entry>";
return $this->_data_request("/{$this->_uris['PLAYLIST_URI']}/{$playlistId}/{$playlistEntryId}", $xml, 'PUT');
}
}
// ./application/libraries
?>

0 comments on commit 7313266

Please sign in to comment.