コード例 #1
0
ファイル: Youtube.php プロジェクト: nlegoff/Phraseanet
 /**
  *
  * @param  type                         $element_type
  * @param  type                         $element_id
  * @param  type                         $destination
  * @param  type                         $container_id
  * @return Bridge_Api_Youtube_Container
  */
 public function add_element_to_container($element_type, $element_id, $destination, $container_id)
 {
     switch ($element_type) {
         case self::ELEMENT_TYPE_VIDEO:
             switch ($destination) {
                 case self::CONTAINER_TYPE_PLAYLIST:
                     $playlistEntry = $this->get_PlaylistEntry_from_Id($container_id);
                     $postUrl = $playlistEntry->getPlaylistVideoFeedUrl();
                     $videoEntryToAdd = $this->_api->getVideoEntry($element_id);
                     $newPlaylistListEntry = $this->_api->newPlaylistListEntry($videoEntryToAdd->getDOM());
                     $this->_api->insertEntry($newPlaylistListEntry, $postUrl);
                     $playlistEntry = $this->get_PlaylistEntry_from_Id($container_id);
                     return new Bridge_Api_Youtube_Container($playlistEntry, $destination, null);
                     break;
                 default:
                     throw new Bridge_Exception_ContainerUnknown('Unknown element ' . $destination);
                     break;
             }
             break;
         default:
             throw new Bridge_Exception_ElementUnknown('Unknown container ' . $element_type);
             break;
     }
 }
コード例 #2
0
ファイル: YouTubeOnlineTest.php プロジェクト: netvlies/zf
 public function testAddUpdateAndDeletePlaylistV2()
 {
     $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
     $authenticationURL = 'https://www.google.com/youtube/accounts/ClientLogin';
     $httpClient = Zend_Gdata_ClientLogin::getHttpClient($username = $this->user, $password = $this->pass, $service = $service, $client = null, $source = 'Google-UnitTests-1.0', $loginToken = null, $loginCaptcha = null, $authenticationURL);
     $yt = new Zend_Gdata_YouTube($httpClient, 'Google-UnitTests-1.0', 'ytapi-gdataops-12345-u78960r7-0', 'AI39si6c-ZMGFZ5fkDAEJoCNHP9LOM2LSO1XuycZF7E' . 'yu1IuvkioESqzRcf3voDLymIUGIrxdMx2aTufdbf5D7E51NyLYyfeaw');
     $yt->setMajorProtocolVersion(2);
     $feed = $yt->getPlaylistListFeed($this->ytAccount);
     // Add new
     $newPlaylist = $yt->newPlaylistListEntry();
     $newPlaylist->setMajorProtocolVersion(2);
     $titleString = $this->generateRandomString(10);
     $newPlaylist->title = $yt->newTitle()->setText($titleString);
     $newPlaylist->summary = $yt->newSummary()->setText('testing');
     $postUrl = 'http://gdata.youtube.com/feeds/api/users/default/playlists';
     $successfulInsertion = true;
     try {
         $yt->insertEntry($newPlaylist, $postUrl);
     } catch (Zend_Gdata_App_Exception $e) {
         $successfulInsertion = false;
     }
     $this->assertTrue($successfulInsertion, 'Failed to insert a new ' . 'playlist.');
     $playlistListFeed = $yt->getPlaylistListFeed('default');
     $playlistFound = false;
     $newPlaylistEntry = null;
     foreach ($playlistListFeed as $playlistListEntry) {
         if ($playlistListEntry->title->text == $titleString) {
             $playlistFound = true;
             $newPlaylistEntry = $playlistListEntry;
             break;
         }
     }
     $this->assertTrue($playlistFound, 'Could not find the newly inserted ' . 'playlist.');
     // Update it
     $newTitle = $this->generateRandomString(10);
     $newPlaylistEntry->title->setText($newTitle);
     $updatedSuccesfully = true;
     try {
         $newPlaylistEntry->save();
     } catch (Zend_Gdata_App_Exception $e) {
         $updatedSuccesfully = false;
     }
     $this->assertTrue($updatedSuccesfully, 'Could not succesfully update ' . 'a new playlist.');
     // Delete it
     $deletedSuccesfully = true;
     try {
         $newPlaylistEntry->delete();
     } catch (Zend_Gdata_App_Exception $e) {
         $deletedSuccesfully = false;
     }
     $this->assertTrue($deletedSuccesfully, 'Could not succesfully delete ' . 'a new playlist.');
 }
コード例 #3
0
/**
 * Create a new playlist for the currently authenticated user
 *
 * @param string $playlistTitle Title of the new playlist
 * @param string $playlistDescription Description for the new playlist
 * @return void
 */
function createPlaylist($playlistTitle, $playlistDescription)
{
    $httpClient = getAuthSubHttpClient();
    $youTubeService = new Zend_Gdata_YouTube($httpClient);
    $feed = $youTubeService->getPlaylistListFeed('default');
    if (loggingEnabled()) {
        logMessage($httpClient->getLastRequest(), 'request');
        logMessage($httpClient->getLastResponse()->getBody(), 'response');
    }
    $newPlaylist = $youTubeService->newPlaylistListEntry();
    $newPlaylist->description = $youTubeService->newDescription()->setText($playlistDescription);
    $newPlaylist->title = $youTubeService->newTitle()->setText($playlistDescription);
    if (!$feed instanceof Zend_Gdata_YouTube_PlaylistListFeed) {
        print 'ERROR - Could not retrieve playlists<br />' . printCacheWarning();
        return;
    }
    $playlistFeedUrl = 'http://gdata.youtube.com/feeds/users/default/playlists';
    try {
        $updatedEntry = $youTubeService->insertEntry($newPlaylist, $playlistFeedUrl);
        if (loggingEnabled()) {
            logMessage($httpClient->getLastRequest(), 'request');
            logMessage($httpClient->getLastResponse()->getBody(), 'response');
        }
    } catch (Zend_Gdata_App_HttpException $httpException) {
        print 'ERROR ' . $httpException->getMessage() . ' HTTP details<br /><textarea cols="100" rows="20">' . $httpException->getRawResponseBody() . '</textarea><br />' . '<a href="session_details.php">' . 'click here to view details of last request</a><br />';
        return;
    } catch (Zend_Gdata_App_Exception $e) {
        print 'ERROR - Could not create new playlist: ' . $e->getMessage();
        return;
    }
    print 'Playlist added succesfully.<br /><a href="#" onclick="' . 'ytVideoApp.retrievePlaylists();"' . '">(refresh your playlist listing)</a><br />' . printCacheWarning();
}