Пример #1
0
 /**
  * action swf untuk nampilin video $_uname swf player
  */
 public function swfAction()
 {
     $youtube = new Zend_Gdata_YouTube();
     try {
         $lists = $youtube->getUserUploads(self::$_uname);
     } catch (Exception $ex) {
         echo $ex->getMessage();
         exit;
     }
     // masih ngawur, masih belum selesai, klo dibikin gini cuma keluar 1 video :p
     // ntar aja dilanjut, ngantukkkkkkkkkkkkkkkkk
     foreach ($lists as $vids) {
         $pub = new Zend_Date($vids->getPublished()->getText(), Zend_Date::ISO_8601);
         // lempar ke view script
         $this->view->videoTitle = $this->view->escape($vids->getVideoTitle());
         $this->view->published = $pub;
         $this->view->videoTags = join(', ', $vids->getVideoTags());
         $this->view->desc = $this->view->escape($vids->getVideoDescription());
         if ($vids->isVideoEmbeddable()) {
             $this->view->url = 'http://www.youtube.com/v/' . $vids->getVideoId() . '&fs=1';
             $this->view->width = 320;
             $height->view->height = 240;
         }
     }
 }
Пример #2
0
	public function getApiComments($videoId)	
	{
	  echo "Checking for comment on: {$videoId}";
	  $yt = new Zend_Gdata_YouTube();
	  // set the version to 2 to retrieve a version 2 feed
	  $yt->setMajorProtocolVersion(2);
	  $commentFeed = $yt->getVideoCommentFeed($videoId);
	  $count = 1;
	  foreach ($commentFeed as $commentEntry) 
	  {
	  	if (!CommentData::commentExists($commentEntry->id))
				{  
	  				echo 'YouTube Comment: ' . $commentEntry->title->text . "\n";
	  				$c=CommentData::create();
					$c->setMessageId($this->getId());
					$c->setCommentId($commentEntry->id);
					$c->setComment($commentEntry->content);
					$c->setAuthorName($commentEntry->author[0]->name);
					$c->setServiceId('3');
					$tZulu=$commentEntry->published;
					$toStrip=array("T", "Z");
					$tZuluStripped=str_replace($toStrip, " ", $tZulu);
					$tZuluStrippedUnix=strtotime($tZuluStripped);
					$gooddate=date('Y-m-d H:i:s', $tZuluStrippedUnix);		
					$c->setPermalink($commentEntry->id);
					$c->setDate($gooddate);
				}
			}
		}
Пример #3
0
function searchAndPrint($searchTerms = 'sesame street')
{
    $yt = new Zend_Gdata_YouTube();
    $yt->setMajorProtocolVersion(2);
    $query = $yt->newVideoQuery();
    $query->setOrderBy('relevance');
    $query->setSafeSearch('moderate');
    $query->setVideoQuery($searchTerms);
    $query->setParam('caption', 'true');
    $query->setParam('start-index', $_GET['start_index']);
    $query->setParam('max-results', 8);
    //$query->setParam('max-results','2');
    // Note that we need to pass the version number to the query URL function
    // to ensure backward compatibility with version 1 of the API.
    //echo $query->getQueryUrl(2);
    //$videoFeed = $yt->getVideoFeed("http://gdata.youtube.com/feeds/api/videos?orderby=relevance&safeSearch=moderate&q=sesame+street");
    $videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));
    $links = $videoFeed->getLink();
    $suggestFlag = null;
    foreach ($links as $link) {
        if ($link->getRel() == 'http://schemas.google.com/g/2006#spellcorrection') {
            $videoFeed = $yt->getVideoFeed($link->getHref());
            //print_r($link->getTitle());
            $suggestFlag = $link->getTitle();
            break;
        }
    }
    //if($links[1]){
    //}
    printVideoFeed($videoFeed, $suggestFlag);
    //'Search results for: ' . $searchTerms);
}
Пример #4
0
 public function getLastVideos($limit = 5)
 {
     $ytUser = $this->_usr;
     $array = array();
     try {
         $gdata = new Zend_Gdata_YouTube();
         $feed = $gdata->getUserUploads($ytUser);
         if ($feed) {
             $i = 1;
             foreach ($feed as $entry) {
                 $thumb = max($entry->getVideoThumbnails());
                 $image = min($entry->getVideoThumbnails());
                 $date = new Zend_Date($entry->getVideoDuration(), Zend_Date::SECOND);
                 $array[] = array("id" => $entry->getVideoId(), "title" => $entry->getVideoTitle(), "thumb" => $thumb["url"], "time" => $date->get("mm:ss"), "image" => $image["url"]);
                 if ($i == $limit) {
                     break;
                     /* Sai */
                 }
                 $i++;
             }
         }
     } catch (Zend_Exception $e) {
     }
     return $array;
 }
function getAndPrintVideoFeed($location = Zend_Gdata_YouTube::VIDEO_URI)
{
    $yt = new Zend_Gdata_YouTube();
    // set the version to 2 to receive a version 2 feed of entries
    $yt->setMajorProtocolVersion(2);
    $videoFeed = $yt->getVideoFeed($location);
    printVideoFeed($videoFeed);
}
Пример #6
0
 /**
  * YT API KEY: AI39si53nkZgrhA-nJLOurfN5yOdLdQeWHK_M08w1A19kfwa718lRXR8Dilcpnc1D0BVXn8KLAfSyYdYbdrd3X7bgDV0ma59Zg
  */
 public function moveVideo($video)
 {
     ProjectConfiguration::registerZend();
     $httpClient = Zend_Gdata_ClientLogin::getHttpClient('*****@*****.**', 'watchm3now', 'youtube', null, 'lifeimpact', null, null, 'https://www.google.com/accounts/ClientLogin');
     $applicationId = 'lifeimpact';
     $clientId = 'lifeimpact';
     $yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, YOUTUBE_DEVELOPER_KEY);
     $yt->setMajorProtocolVersion(2);
 }
 function acceptAllContacts($userName)
 {
     $yt = new Zend_Gdata_YouTube();
     $contactsFeed = $yt->getContactFeed($userName);
     foreach ($contactsFeed as $contactsEntry) {
         $contactEntry->setStatus($yt->newStatus('accepted'));
         $contactEntry->save();
     }
 }
/**
 * @param $mod_reference
 * @param $module_params
 */
function module_last_youtube_playlist_videos($mod_reference, $module_params)
{
    global $smarty, $prefs;
    $tikilib = TikiLib::lib('tiki');
    $data = array();
    if (!empty($module_params['id'])) {
        $id = $module_params['id'];
        require_once 'lib/wiki-plugins/wikiplugin_youtube.php';
        if (!empty($module_params['orderby'])) {
            $orderby = $module_params['orderby'];
            $feedUrl = 'http://gdata.youtube.com/feeds/api/playlists/' . $id . '?orderby=' . $orderby;
        } else {
            $feedUrl = 'http://gdata.youtube.com/feeds/api/playlists/' . $id . '?orderby=position';
        }
        $yt = new Zend_Gdata_YouTube();
        $yt->setMajorProtocolVersion(2);
        $yt->setHttpClient($tikilib->get_http_client());
        try {
            $playlistVideoFeed = $yt->getPlaylistVideoFeed($feedUrl);
            $data[$id]['info']['title'] = $playlistVideoFeed->title->text;
            // Prepare params for video display
            $params = array();
            $params['width'] = isset($module_params['width']) ? $module_params['width'] : 425;
            $params['height'] = isset($module_params['height']) ? $module_params['height'] : 350;
            // Get information from all videos from playlist
            // Limit to $module_rows first videos if $module_rows is set
            $count_videos = 1;
            foreach ($playlistVideoFeed as $videoEntry) {
                $videoId = $videoEntry->getVideoId();
                $data[$id]['videos'][$videoId]['title'] = $videoEntry->getVideoTitle();
                $data[$id]['videos'][$videoId]['uploaded'] = $videoEntry->mediaGroup->uploaded->text;
                $data[$id]['videos'][$videoId]['description'] = $videoEntry->getVideoDescription();
                $params['movie'] = $videoId;
                $pluginstr = wikiplugin_youtube('', $params);
                $len = strlen($pluginstr);
                //need to take off the ~np~ and ~/np~ at the beginning and end of the string returned by wikiplugin_youtube
                $data[$id]['videos'][$videoId]['xhtml'] = substr($pluginstr, 4, $len - 4 - 5);
                if (isset($module_rows) && $module_rows > 0 && $count_videos >= $module_rows) {
                    break;
                }
                $count_videos++;
            }
        } catch (Exception $e) {
            $data[$id]['info']['title'] = tra('No Playlist found');
            $data[$id]['videos'][0]['title'] = $e->getMessage();
        }
    } else {
        $id = 0;
        $data[$id]['info']['title'] = tra('No Playlist found');
        $data[$id]['videos'][0]['title'] = tra('No Playlist ID was provided');
    }
    $smarty->assign('verbose', isset($module_params['verbose']) ? $module_params['verbose'] : 'y');
    $smarty->assign('link_url', isset($module_params['link_url']) ? $module_params['link_url'] : '');
    $smarty->assign('link_text', isset($module_params['link_text']) ? $module_params['link_text'] : 'More Videos');
    $smarty->assign_by_ref('data', $data[$id]);
}
 public function testSetClientIDAndDeveloperKeyHeader()
 {
     $applicationId = 'MyTestCompany-MyTestApp-0.1';
     $clientId = 'MyClientId';
     $developerKey = 'MyDeveloperKey';
     $httpClient = new Zend_Http_Client();
     $yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
     $this->assertTrue($yt instanceof Zend_Gdata_YouTube);
     $client = $yt->getHttpClient();
     $this->assertEquals($client->getHeader('X-Gdata-Key'), 'key=' . $developerKey);
     $this->assertEquals($client->getHeader('X-Gdata-Client'), $clientId);
 }
Пример #10
0
 public function getYtVideos()
 {
     $converted_values = array();
     $gdata = new Zend_Gdata_YouTube();
     $feed = $gdata->getUserUploads($this->_config->getConfiguracao(CFG_YOUTUBE));
     foreach ($feed as $entry) {
         /* @var $entry Zend_Gdata_YouTube_VideoEntry */
         $thumbnail = $entry->getVideoThumbnails();
         $date = new Zend_Date($entry->getPublished());
         $converted_values[$entry->getVideoId()] = array('video_id' => $entry->getVideoId(), 'nm_title' => $entry->getVideoTitle(), 'tx_description' => $entry->getVideoDescription(), 'thumbnail_small' => $thumbnail[0]['url'], 'thumbnail_big' => $thumbnail[2]['url'], 'nu_time' => $entry->getVideoDuration(), 'dt_upload' => $date->get('yyyy-MM-dd'));
     }
     return $converted_values;
 }
Пример #11
0
 function delete($username, $password, $source, $videoId)
 {
     $httpClient = $this->clientLogin($username, $password, $source);
     $httpClient->setHeaders('X-GData-Key', "key={$source}");
     $yt = new Zend_Gdata_YouTube($httpClient);
     try {
         $videoEntryToDelete = $yt->getVideoEntry($videoId, null, true);
         $result = $yt->delete($videoEntryToDelete);
         return $result;
     } catch (Zend_Gdata_App_HttpException $httpException) {
         echo $httpException->getRawResponseBody();
     } catch (Zend_Gdata_App_Exception $e) {
         echo $e->getMessage();
     }
 }
Пример #12
0
 /**
  *
  * @param  string                              $element_id
  * @return Zend_Gdata_YouTube_PlaylistListFeed
  */
 protected function get_PlaylistEntry_from_Id($element_id)
 {
     foreach ($this->_api->getPlaylistListFeed('default') as $playlist_entry) {
         if ($element_id == $playlist_entry->getPlaylistId()->getText()) {
             return $playlist_entry;
         }
     }
     return null;
 }
Пример #13
0
 public static function upload($asset)
 {
     try {
         $credentials = Asset_Video_Youtube::getYoutubeCredentials();
         if (!$credentials) {
             return;
         }
         $httpClient = Zend_Gdata_ClientLogin::getHttpClient($username = $credentials["username"], $password = $credentials["password"], $service = 'youtube', $client = Pimcore_Tool::getHttpClient("Zend_Gdata_HttpClient"), $source = 'Pimcore', $loginToken = null, $loginCaptcha = null, 'https://www.google.com/youtube/accounts/ClientLogin');
         $httpClient->setConfig(array("timeout" => 3600));
         $apikey = $credentials["apiKey"];
         $httpClient->setHeaders('X-GData-Key', "key={$apikey}");
         $yt = new Zend_Gdata_YouTube($httpClient);
         $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
         $filesource = $yt->newMediaFileSource($asset->getFileSystemPath());
         $filesource->setContentType($asset->getMimetype());
         $filesource->setSlug($asset->getFilename());
         $myVideoEntry->setMediaSource($filesource);
         $myVideoEntry->setVideoTitle($asset->getFullPath());
         $myVideoEntry->setVideoDescription($asset->getFullPath());
         $myVideoEntry->setVideoCategory('Comedy');
         // Set keywords, note that this must be a comma separated string
         // and that each keyword cannot contain whitespace
         $myVideoEntry->SetVideoTags('---, ---');
         // Optionally set some developer tags
         $myVideoEntry->setVideoDeveloperTags(array('mydevelopertag', 'anotherdevelopertag'));
         // Upload URI for the currently authenticated user
         $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/users/default/uploads';
         try {
             $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
             $asset->setCustomSetting("youtube", array("id" => strval($newEntry->getVideoId())));
             $asset->save();
             return true;
         } catch (Exception $e) {
             $asset->setCustomSetting("youtube", array("failed" => true));
             $asset->save();
         }
     } catch (Exception $e) {
         Logger::error($e);
     }
     return false;
 }
Пример #14
0
 function youtubeEntry()
 {
     ini_set("display_errors", 0);
     /**
      * credentials
      */
     define('EMAIL_ID', '*****@*****.**');
     define('EMAIL_PASS', 'uoatest@7');
     define('YOUTUBE_DEVELOPER_KEY', 'AI39si4DVYjRr1KL17gdDJwosRs4eUblWKBKB7rbqV90Ku1jDye7rVjXbZ_2KaZGiqcDeJBhDYgIzFjczF2FQBUslV27bMeJ9Q');
     require_once 'lib/vendor/Zend/Loader.php';
     Zend_Loader::loadClass('Zend_Gdata_YouTube');
     Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
     $httpClient = Zend_Gdata_ClientLogin::getHttpClient(EMAIL_ID, EMAIL_PASS, 'youtube', null, 'UoAyoutube', null, null, 'https://www.google.com/accounts/ClientLogin');
     $applicationId = 'Video uploader v1';
     $clientId = 'My video upload client - v1';
     $yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, YOUTUBE_DEVELOPER_KEY);
     $yt->setMajorProtocolVersion(2);
     //$videoFeed = $yt->getVideoFeed(Zend_Gdata_YouTube::VIDEO_URI);
     $videoFeed = $yt->getuserUploads("uoatest7");
     $this->printVideo($videoFeed);
 }
Пример #15
0
 /**
  * get a new video from from a youtube url
  *
  * @param $url
  * @return Model_Video video object
  */
 public function getFromYoutube($url)
 {
     $urlArray = parse_url($url);
     if (!isset($urlArray['query'])) {
         throw new Exception('Invalid URL');
     }
     parse_str($urlArray['query'], $query);
     if (!isset($query['v'])) {
         throw new Exception('Invalide YouTube Video URL');
     }
     $youtube_id = $query['v'];
     $yt = new Zend_Gdata_YouTube();
     try {
         $videoEntry = $yt->getVideoEntry($youtube_id);
     } catch (Zend_Gdata_App_HttpException $e) {
         //YouTube may be down too?
         throw new Exception('Invalid YouTube Video URL');
     }
     $data = array('url' => $url, 'youtube_id' => $youtube_id, 'title' => $videoEntry->getTitleValue());
     return new Model_Video($data);
 }
 public function doYoutubeUpload($options = array('title' => '', 'titleAlias' => '', 'introText' => '', 'source' => '', 'tags' => '', 'description' => ''))
 {
     $this->fileVideoName = $this->upload->getUploadName();
     $title = $options['title'];
     $titleAlias = $options['titleAlias'];
     $introText = $options['introText'];
     $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
     $fileName = $this->fileVideoName;
     Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
     $httpclient = Zend_Gdata_ClientLogin::getHttpClient($this->username, $this->password, $service = 'youtube', $client = null, $source = $options['source'], $loginToken = null, $loginCaptcha = null, $this->authenticationURL);
     Zend_Loader::loadClass('Zend_Gdata_YouTube');
     $yt = new Zend_Gdata_YouTube($httpclient, $options['name'], $options['name'], $this->developerKey);
     $videoEntry = new Zend_Gdata_YouTube_VideoEntry();
     $filesource = $yt->newMediaFileSource($fileName);
     $filesource->setContentType('video/' . $this->upload->fileExt);
     $filesource->setSlug($fileName);
     $videoEntry->setMediaSource($filesource);
     $videoEntry->setVideoTitle($title);
     $videoEntry->setVideoDescription($options['description']);
     $videoEntry->setVideoCategory($options['category']);
     $videoEntry->SetVideoTags($options['tags']);
     try {
         $videoEntry = $yt->insertEntry($videoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
         $state = $videoEntry->getVideoState();
         if ($state) {
             $youtubeId = $videoEntry->getVideoId();
             $this->videoId = $youtubeId;
             $this->videoUrl = "http://youtu.be/{$youtubeId}";
             $this->thumbSrc = "http://img.youtube.com/vi/{$youtubeId}/default.jpg";
             $this->duration = $this->length = 0;
             $this->parseAdditionalMetadata();
         } else {
             throw new Exception("Not able to retrieve the video status information yet. " . "Please try again later.\n");
         }
     } catch (Zend_Gdata_App_HttpException $httpException) {
         throw new Exception($httpException->getRawResponseBody());
     } catch (Zend_Gdata_App_Exception $e) {
         throw new Exception($e->getMessage());
     }
 }
Пример #17
0
 /**
  * Retrieve user's uploaded videos.
  *
  * @param $maxResults int
  *       	 Maximum number of YoutubeVideo to return.
  * @return array(YoutubeVideo) Videos retrieved.
  */
 public function getVideos($maxResults)
 {
     try {
         set_include_path(get_include_path() . PATH_SEPARATOR . dirname(WSW_Main::$plugin_dir) . '/lib/Youtube');
         if (!class_exists('Zend_Loader')) {
             require_once 'Zend/Loader.php';
         }
         Zend_Loader::loadClass('Zend_Gdata_Query');
         Zend_Loader::loadClass('Zend_Gdata_YouTube');
         // If the keyword is compoused, divide each word
         $key_phrase = $this->keyword;
         $key_phrase_arr = explode(' ', $key_phrase);
         $query_url = Zend_Gdata_YouTube::VIDEO_URI . "/-/";
         foreach ($key_phrase_arr as $key_phrase_item) {
             if (trim($key_phrase_item) != '') {
                 $query_url .= trim($key_phrase_item) . '/';
             }
         }
         //$query_url .= '?v=2';
         $query = new Zend_Gdata_Query($query_url);
         $query->setMaxResults($maxResults);
         $query->setParam('orderby', 'viewCount');
         $yt = new Zend_Gdata_YouTube();
         $yt->setMajorProtocolVersion(2);
         $videoFeed = $yt->getFeed($query, 'Zend_Gdata_YouTube_VideoFeed');
         // TODO See how this initialization must be done, I mean if is really neccesary
         $keyVideos = array();
         foreach ($videoFeed as $videoEntry) {
             $keyVideos[] = new WSW_YoutubeVideo($videoEntry);
         }
         return $keyVideos;
     } catch (Exception $e) {
         // Store to log
         $msg_to_log = 'Error while getVideos from Youtube, Url: ' . $query_url . ', Exception Msg: ' . $e->getMessage();
         return array();
     }
 }
Пример #18
0
 function video()
 {
     $videoId = $this->params['id'];
     $yt = new Zend_Gdata_YouTube();
     $entry = $yt->getVideoEntry($videoId);
     $this->set('videoTitle', $entry->mediaGroup->title);
     $this->set('description', $entry->mediaGroup->description);
     $this->set('authorUsername', $entry->author[0]->name);
     $this->set('authorUrl', 'http://www.youtube.com/profile?user='******'tags', $entry->mediaGroup->keywords);
     $this->set('duration', $entry->mediaGroup->duration->seconds);
     $this->set('watchPage', $entry->mediaGroup->player[0]->url);
     $this->set('viewCount', $entry->statistics->viewCount);
     $this->set('rating', $entry->rating->average);
     $this->set('numRaters', $entry->rating->numRaters);
     /* Get related Videos */
     $ytQuery = $yt->newVideoQuery();
     $ytQuery->setFeedType('related', $videoId);
     $ytQuery->setOrderBy('rating');
     $ytQuery->setMaxResults(5);
     $ytQuery->setFormat(5);
     $this->set('videoId', $videoId);
     $this->set('related', $yt->getVideoFeed($ytQuery));
 }
Пример #19
0
 public function populateFromUrl()
 {
     $urlArray = parse_url($this->getUrl());
     if (!isset($urlArray['query'])) {
         throw new Exception('Invalid URL');
     }
     parse_str($urlArray['query'], $query);
     if (!isset($query['v'])) {
         throw new Exception('Invalide YouTube Video URL');
     }
     $youtube_id = $query['v'];
     $yt = new Zend_Gdata_YouTube();
     try {
         $videoEntry = $yt->getVideoEntry($youtube_id);
     } catch (Zend_Gdata_App_HttpException $e) {
         //YouTube may be down too?
         throw new Exception('Invalid YouTube Video URL');
     }
     $this->youtube_id = $youtube_id;
     $this->youtube_title = $videoEntry->getVideoTitle();
     $this->youtube_description = $videoEntry->getVideoDescription();
     $thumbnails = $videoEntry->getVideoThumbnails();
     $this->youtube_thumbnail = $thumbnails[0]['url'];
 }
Пример #20
0
 /**
  * Prints a JSON with URL for form action and the needed token, and dies.<br />
  * Used with JSON POST requests.<br />
  * <p>Asks for the following POST fields:
  * <ul>
  *		<li>title</li>
  *		<li>description</li>
  *		<li>category (only one)</li>
  *		<li>keywords (comma-separated)</li>
  * </ul>
  * </p>
  * @return JSON
  */
 public function actionFormData()
 {
     Yii::import('system.collections.*');
     Yii::import('system.base.*');
     Yii::import('ext.*');
     Yii::import('ext.Zend.Gdata.*');
     require_once 'Zend/Loader.php';
     Yii::registerAutoloader(array('Zend_Loader', 'loadClass'));
     $login = Zend_Gdata_ClientLogin::getHttpClient($this->youtubeLogin, $this->youtubePassword, 'youtube', null, Yii::app()->name);
     $login->setHeaders('X-GData-Key', 'key=' . $this->youtubeDevKey);
     $utub = new Zend_Gdata_YouTube($login);
     $video = new Zend_Gdata_YouTube_VideoEntry();
     $media = $utub->newMediaGroup();
     $media->title = $utub->newMediaTitle()->setText($_POST['title']);
     $media->description = $utub->newMediaDescription()->setText($_POST['description']);
     $media->keywords = $utub->newMediaKeywords()->setText($_POST['keywords']);
     $media->category = array($utub->newMediaCategory()->setText($_POST['category'])->setScheme(self::CAT_SCHEME), $utub->newMediaCategory()->setText(preg_replace('/\\s/', '', Yii::app()->name) . 'Site')->setScheme(self::TAG_SCHEME));
     $video->mediaGroup = $media;
     $data = $utub->getFormUploadToken($video);
     exit(json_encode($data));
 }
/**
 * Delete a playlist
 *
 * @param string $newplaylistTitle New title for the playlist to be updated
 * @param string $newPlaylistDescription New description for the playlist to be updated
 * @param string $oldPlaylistTitle Title of the playlist to be updated
 * @return void
 */
function updatePlaylist($newPlaylistTitle, $newPlaylistDescription, $oldPlaylistTitle)
{
    $httpClient = getAuthSubHttpClient();
    $youTubeService = new Zend_Gdata_YouTube($httpClient);
    $feed = $youTubeService->getPlaylistListFeed('default');
    if (loggingEnabled()) {
        logMessage($httpClient->getLastRequest(), 'request');
        logMessage($httpClient->getLastResponse()->getBody(), 'response');
    }
    $playlistEntryToDelete = null;
    foreach ($feed as $playlistEntry) {
        if ($playlistEntry->getTitleValue() == $oldplaylistTitle) {
            $playlistEntryToDelete = $playlistEntry;
            break;
        }
    }
    if (!$playlistEntryToDelete instanceof Zend_Gdata_YouTube_PlaylistListEntry) {
        print 'ERROR - Could not retrieve playlist to be updated<br />' . printCacheWarning();
        return;
    }
    try {
        $response = $playlistEntryToDelete->delete();
        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 delete the playlist: ' . $e->getMessage();
        return;
    }
    print 'Playlist deleted succesfully.<br /><a href="#" onclick="' . 'ytVideoApp.retrievePlaylists();"' . '">(refresh your playlist listing)</a><br />' . printCacheWarning();
}
Пример #22
0
 function uploadvideo()
 {
     if (!empty($_FILES['image'])) {
         $uploaddir = BASEPATH . '../video';
         $fname = $_FILES['image']['name'];
         $fsize = $_FILES['image']['size'];
         $ftmpname = $_FILES['image']['tmp_name'];
         $ext = '';
         if (preg_match("/.+(\\..+)\$/", $fname, $matches)) {
             $ext = strtolower($matches[1]);
         }
         //file extension
         $filename = $this->_genFileName($ext, $uploaddir);
         $uploadfile = $uploaddir . '/' . $filename;
         //debug: //echo $uploadfile;
         //$fsize < 3000000  //allow to upload only pics that less then file_upload_size bytes
         if (in_array($ext, array('.avi', '.3gp', '.mov', '.mp4', '.mpeg', '.flv', '.swf', '.mkv'))) {
             if (move_uploaded_file($ftmpname, $uploadfile)) {
                 //uploaded
                 $uploaded = TRUE;
             } else {
                 //Error while uploading file
             }
         } else {
             //Picture shouldn't exceed file_upload_size bytes
             $_data['msg'] = $msg = 'Uploaded file should be a video';
         }
     } else {
         $_data['msg'] = $msg = 'You should select a video to upload';
     }
     if (empty($uploaded)) {
         if (empty($msg)) {
             $_data['msg'] = $msg = 'Cannot upload file';
         }
         $this->load->view('member_post_video', $_data);
     } else {
         $yt = new Zend_Gdata_YouTube($this->client);
         // create a new Zend_Gdata_YouTube_VideoEntry object
         $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
         // create a new Zend_Gdata_App_MediaFileSource object
         $filesource = $yt->newMediaFileSource($uploadfile);
         $filesource->setContentType('video/quicktime');
         // set slug header
         $filesource->setSlug($uploadfile);
         // add the filesource to the video entry
         $myVideoEntry->setMediaSource($filesource);
         // create a new Zend_Gdata_YouTube_MediaGroup object
         $mediaGroup = $yt->newMediaGroup();
         $mediaGroup->title = $yt->newMediaTitle()->setText('My Movie');
         $mediaGroup->description = $yt->newMediaDescription()->setText('My Movie Description');
         // the category must be a valid YouTube category
         // optionally set some developer tags (see Searching by Developer Tags for more details)
         $mediaGroup->category = array($yt->newMediaCategory()->setText('Autos')->setScheme('http://gdata.youtube.com/schemas/2007/categories.cat'));
         // set keywords
         $mediaGroup->keywords = $yt->newMediaKeywords()->setText('test');
         $myVideoEntry->mediaGroup = $mediaGroup;
         // set video location
         //$yt->registerPackage('Zend_Gdata_Geo');
         //$yt->registerPackage('Zend_Gdata_Geo_Extension');
         //$where = $yt->newGeoRssWhere();
         //$position = $yt->newGmlPos('37.0 -122.0');
         //$where->point = $yt->newGmlPoint($position);
         //$entry->setWhere($where);
         // upload URL for the currently authenticated user
         $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/users/default/uploads';
         try {
             $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
             //print"<pre>";var_dump($newEntry->getVideoWatchPageUrl());print"</pre>";
             if (!empty($this->fbUserId) && !empty($this->userSettings) && $this->userSettings[0]['facebook_vids_y_n'] == 1) {
                 // uploading video to Facebook
                 try {
                     $this->facebook->api_client->video_upload($uploadfile, "Uploading video with " . $this->conf['site_name'], null);
                 } catch (Exception $ex) {
                     echo $ex->getMessage();
                     //echo "Cannot upload video to facebook";
                 }
             }
             $lastMessage = $this->Post_model->getWhere(null, $limit = 1, $offset = 0, $order = 'id DESC');
             if (!empty($lastMessage) && $lastMessage[0]['user_id'] == $this->getUserId() && $lastMessage[0]['site_id'] == $this->subdomainId && $lastMessage[0]['post_type'] == 'video') {
                 $this->Post_videos_model->insert($lastMessage[0]['id'], $newEntry->getVideoWatchPageUrl());
             } else {
                 $this->Post_model->insert($this->getUserId(), $this->subdomainId, date("Y-m-d H:i"), 'video', NULL, $newEntry->getVideoWatchPageUrl(), NULL);
             }
             $this->load->view('member_post_video_success');
             $sitedata = $this->Site_model->getById($this->subdomainId);
             $users = $this->User_is_member_of_site_model->getList(0, 0, array('subscribe_y_n' => 1, 'site_id' => $this->subdomainId), '', array('table' => 'users', 'field1' => 'id', 'field2' => 'user_id'));
             foreach ($users as $user) {
                 $this->_sendemail('newpost', array('sitename' => $sitedata['name'], 'subdomain' => $sitedata['subdomain'], 'email' => $user['email']));
             }
             //$this->load->view('member_post_video_success', $_data);
         } catch (Zend_Gdata_App_Exception $e) {
             echo $e->getMessage();
         }
         @unlink($uploadfile);
     }
 }
Пример #23
0
 public function executeSearchYoutube(sfWebRequest $request)
 {
     ini_set('display_errors', false);
     $util = new Util();
     $yt = new Zend_Gdata_YouTube();
     $yt->setMajorProtocolVersion(2);
     $query = $yt->newVideoQuery();
     $query->setSafeSearch('none');
     $query->setMaxResults(10);
     $query->setVideoQuery($request->getPostParameter('data'));
     // Note that we need to pass the version number to the query URL function
     // to ensure backward compatibility with version 1 of the API.
     $videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));
     $html = $util->printVideoFeed($videoFeed);
     echo $html;
     return sfView::NONE;
 }
Пример #24
0
/**
 * Function to be run periodically according to the moodle cron
 * This function searches for things that need to be done, such 
 * as sending out mail, toggling flags etc ... 
 *
 * @uses $CFG
 * @return boolean
 * @todo Finish documenting this function
 **/
function mediaboard_cron()
{
    global $CFG, $DB;
    $fs = get_file_storage();
    if ($data = $DB->get_record_sql("SELECT * FROM {mediaboard_process} WHERE `status`='open' LIMIT 1")) {
        $CFG->mediaboard_convert = 0;
        if (in_array($data->type, json_decode(MEDIABOARD_VIDEOTYPES))) {
            $CFG->mediaboard_convert = $CFG->mediaboard_video_convert;
        } else {
            if (in_array($data->type, json_decode(MEDIABOARD_AUDIOTYPES))) {
                $CFG->mediaboard_convert = $CFG->mediaboard_audio_convert;
            }
        }
        //Check converting method local or mserver
        if ($CFG->mediaboard_convert == 1) {
            if (strstr($CFG->mediaboard_convert_url, "ffmpeg")) {
                $CFG->mediaboard_convert = 2;
            }
        }
        //local
        if ($CFG->mediaboard_convert == 1) {
            $from = mediaboard_getfileid($data->itemid);
            $add = new stdClass();
            $add->id = $data->id;
            $add->status = 'send';
            $DB->update_record("mediaboard_process", $add);
            $ch = curl_init();
            if (in_array($data->type, json_decode(MEDIABOARD_AUDIOTYPES))) {
                $datasend = array('name' => $data->name, 'mconverter_wav' => '@' . $from->fullpatch);
            }
            if (in_array($data->type, json_decode(MEDIABOARD_VIDEOTYPES))) {
                $datasend = array('name' => $data->name, 'mconverter_m4a' => '@' . $from->fullpatch);
            }
            curl_setopt($ch, CURLOPT_URL, $CFG->mediaboard_convert_url . '/send.php');
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $datasend);
            curl_exec($ch);
        } else {
            if ($CFG->mediaboard_convert == 3) {
                $from = mediaboard_getfileid($data->itemid);
                $add = new stdClass();
                $add->id = $data->id;
                $add->status = 'send';
                $DB->update_record("mediaboard_process", $add);
                if (in_array($data->type, json_decode(MEDIABOARD_VIDEOTYPES))) {
                    if ($item = $DB->get_record("mediaboard_files", array("itemoldid" => $data->itemid))) {
                        $table = 'mediaboard_files';
                    } else {
                        if ($item = $DB->get_record("mediaboard_comments", array("itemoldid" => $data->itemid))) {
                            $table = 'mediaboard_comments';
                        }
                    }
                    @set_include_path($CFG->dirroot . '/mod/mediaboard/library');
                    require_once "Zend/Gdata/ClientLogin.php";
                    require_once "Zend/Gdata/HttpClient.php";
                    require_once "Zend/Gdata/YouTube.php";
                    require_once "Zend/Gdata/App/HttpException.php";
                    require_once 'Zend/Uri/Http.php';
                    $authenticationURL = 'https://www.google.com/youtube/accounts/ClientLogin';
                    $httpClient = Zend_Gdata_ClientLogin::getHttpClient($username = $CFG->mediaboard_youtube_email, $password = $CFG->mediaboard_youtube_password, $service = 'youtube', $client = null, $source = 'mediaboard', $loginToken = null, $loginCaptcha = null, $authenticationURL);
                    $yt = new Zend_Gdata_YouTube($httpClient, 'mediaboard', NULL, $CFG->mediaboard_youtube_apikey);
                    $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
                    /// unlisted upload
                    $accessControlElement = new Zend_Gdata_App_Extension_Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
                    $accessControlElement->extensionAttributes = array(array('namespaceUri' => '', 'name' => 'action', 'value' => 'list'), array('namespaceUri' => '', 'name' => 'permission', 'value' => 'denied'));
                    $myVideoEntry->extensionElements = array($accessControlElement);
                    $filesource = $yt->newMediaFileSource($from->fullpatch);
                    $filesource->setContentType($data->type);
                    $filesource->setSlug('slug');
                    $myVideoEntry->setMediaSource($filesource);
                    $myVideoEntry->setVideoTitle($from->author);
                    $myVideoEntry->setVideoDescription($from->author);
                    $myVideoEntry->setVideoCategory('Education');
                    $myVideoEntry->SetVideoTags('mediaboard');
                    //$myVideoEntry->setVideoDeveloperTags(array($item->id));
                    //$yt->registerPackage('Zend_Gdata_Geo');
                    //$yt->registerPackage('Zend_Gdata_Geo_Extension');
                    //$where = $yt->newGeoRssWhere();
                    //$position = $yt->newGmlPos('37.0 -122.0');
                    //$where->point = $yt->newGmlPoint($position);
                    //$myVideoEntry->setWhere($where);
                    $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
                    try {
                        $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
                    } catch (Zend_Gdata_App_HttpException $httpException) {
                        echo $httpException->getRawResponseBody();
                        $DB->delete_records('mediaboard_process', array('id' => $data->id));
                    } catch (Zend_Gdata_App_Exception $e) {
                        echo $e->getMessage();
                        $DB->delete_records('mediaboard_process', array('id' => $data->id));
                    }
                    $itemidyoutube = $newEntry->getVideoId();
                    if (!empty($itemidyoutube)) {
                        $DB->set_field($table, "itemyoutube", $itemidyoutube, array("id" => $item->id));
                    }
                    $DB->delete_records('mediaboard_process', array('id' => $data->id));
                } else {
                    $DB->delete_records('mediaboard_process', array('id' => $data->id));
                }
            } else {
                if ($CFG->mediaboard_convert == 2) {
                    ///Old method
                    $DB->delete_records('mediaboard_process', array('id' => $data->id));
                    if (!($item = $DB->get_record("mediaboard_files", array("itemoldid" => $data->itemid)))) {
                        $item = $DB->get_record("mediaboard_comments", array("itemoldid" => $data->itemid));
                        $table = 'mediaboard_comments';
                    } else {
                        $table = 'mediaboard_files';
                    }
                    $student = $DB->get_record("user", array("id" => $item->userid));
                    $context = get_context_instance(CONTEXT_MODULE, $item->instance);
                    $file_record = new stdClass();
                    $file_record->component = 'mod_mediaboard';
                    $file_record->contextid = $context->id;
                    $file_record->userid = $item->userid;
                    $file_record->filearea = 'private';
                    $file_record->filepath = "/";
                    $file_record->itemid = $item->id;
                    $file_record->license = $CFG->sitedefaultlicense;
                    $file_record->author = fullname($student);
                    $file_record->source = '';
                    if (in_array($data->type, json_decode(MEDIABOARD_VIDEOTYPES))) {
                        $from = mediaboard_getfileid($data->itemid);
                        $to = $CFG->dataroot . "/temp/" . $item->filename . ".mp4";
                        $toimg = $CFG->dataroot . "/temp/" . $item->filename . ".jpg";
                        mediaboard_runExternal("/opt/handbrake/HandBrakeCLI -Z Universal -i {$from->fullpatch} -o {$to} -w 432 -l 320", $code);
                        mediaboard_runExternal("{$CFG->mediaboard_convert_url} -i {$to} -f image2 -s 432x320 {$toimg}", $code);
                        $file_record->filename = $item->filename . ".mp4";
                        $itemid = $fs->create_file_from_pathname($file_record, $to);
                        $file_record->filename = $item->filename . ".jpg";
                        $itemimgid = $fs->create_file_from_pathname($file_record, $toimg);
                        $DB->set_field($table, "itemid", $itemid->get_id(), array("id" => $item->id));
                        $DB->set_field($table, "itemimgid", $itemimgid->get_id(), array("id" => $item->id));
                        unlink($to);
                        unlink($toimg);
                    } else {
                        if (in_array($data->type, json_decode(MEDIABOARD_AUDIOTYPES))) {
                            $from = mediaboard_getfileid($data->itemid);
                            $to = $CFG->dataroot . "/temp/" . $item->filename . ".mp3";
                            mediaboard_runExternal("{$CFG->mediaboard_convert_url} -y -i {$from->fullpatch} -acodec libmp3lame -ab 68k -ar 44100 {$to}", $code);
                            $file_record->filename = $item->filename . ".mp3";
                            $itemid = $fs->create_file_from_pathname($file_record, $to);
                            $DB->set_field($table, "itemid", $itemid->get_id(), array("id" => $item->id));
                            unlink($to);
                        }
                    }
                }
            }
        }
    }
    ///Check convert server file ready
    if ($dataall = $DB->get_records_sql("SELECT * FROM {mediaboard_process} WHERE `status` = 'send'")) {
        foreach ($dataall as $data) {
            if (!($item = $DB->get_record("mediaboard_files", array("itemoldid" => $data->itemid)))) {
                if ($item = $DB->get_record("mediaboard_items", array("audio1" => $data->itemid))) {
                    $mark = 1;
                    $table = 'mediaboard_items';
                } else {
                    if ($item = $DB->get_record("mediaboard_items", array("audio2" => $data->itemid))) {
                        $mark = 2;
                        $table = 'mediaboard_items';
                    } else {
                        if ($item = $DB->get_record("mediaboard_items", array("audio3" => $data->itemid))) {
                            $mark = 3;
                            $table = 'mediaboard_items';
                        } else {
                            if ($item = $DB->get_record("mediaboard_items", array("audio4" => $data->itemid))) {
                                $mark = 4;
                                $table = 'mediaboard_items';
                            } else {
                                if ($item = $DB->get_record("mediaboard_items", array("audio5" => $data->itemid))) {
                                    $mark = 5;
                                    $table = 'mediaboard_items';
                                } else {
                                    if ($item = $DB->get_record("mediaboard_items", array("audio6" => $data->itemid))) {
                                        $mark = 6;
                                        $table = 'mediaboard_items';
                                    } else {
                                        if ($item = $DB->get_record("mediaboard_items", array("audio7" => $data->itemid))) {
                                            $mark = 7;
                                            $table = 'mediaboard_items';
                                        } else {
                                            if ($item = $DB->get_record("mediaboard_items", array("audio8" => $data->itemid))) {
                                                $mark = 8;
                                                $table = 'mediaboard_items';
                                            } else {
                                                if ($item = $DB->get_record("mediaboard_items", array("audio9" => $data->itemid))) {
                                                    $mark = 9;
                                                    $table = 'mediaboard_items';
                                                } else {
                                                    if ($item = $DB->get_record("mediaboard_items", array("audio10" => $data->itemid))) {
                                                        $mark = 10;
                                                        $table = 'mediaboard_items';
                                                    } else {
                                                        $DB->delete_records('mediaboard_process', array('id' => $data->id));
                                                        return true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                $fid = $DB->get_record("mediaboard_files", array("id" => $item->fileid));
                $itemdata = new stdClass();
                $itemdata->userid = $item->userid;
                $itemdata->instance = $fid->instance;
                $itemdata->id = $item->id;
                $itemdata->filename = 'slide_audio';
            } else {
                $table = 'mediaboard_files';
                $itemdata = new stdClass();
                $itemdata->userid = $item->userid;
                $itemdata->instance = $item->instance;
                $itemdata->id = $item->id;
                $itemdata->filename = $item->filename;
            }
            $unicalid = substr(time(), 2) . rand(0, 9);
            $student = $DB->get_record("user", array("id" => $itemdata->userid));
            $context = get_context_instance(CONTEXT_MODULE, $itemdata->instance);
            $file_record = new stdClass();
            $file_record->component = 'mod_mediaboard';
            $file_record->contextid = $context->id;
            $file_record->userid = $itemdata->userid;
            $file_record->filearea = 'private';
            $file_record->filepath = "/";
            $file_record->itemid = $unicalid;
            $file_record->license = $CFG->sitedefaultlicense;
            $file_record->author = fullname($student);
            $file_record->source = '';
            if (in_array($data->type, json_decode(MEDIABOARD_VIDEOTYPES)) && $CFG->mediaboard_video_convert == 1) {
                $json = json_decode(file_get_contents($CFG->mediaboard_convert_url . "/get.php?name={$data->name}.mp4"));
                $jsonimg = json_decode(file_get_contents($CFG->mediaboard_convert_url . "/get.php?name={$data->name}.jpg"));
            } else {
                if ($CFG->mediaboard_audio_convert == 1) {
                    $json = json_decode(file_get_contents($CFG->mediaboard_convert_url . "/get.php?name={$data->name}.mp3"));
                }
            }
            if (@(!empty($json->url))) {
                $DB->delete_records('mediaboard_process', array('id' => $data->id));
                if (in_array($data->type, json_decode(MEDIABOARD_VIDEOTYPES))) {
                    $to = $CFG->dataroot . "/temp/" . $itemdata->filename . ".mp4";
                    file_put_contents($to, file_get_contents($json->url));
                    $file_record->filename = $itemdata->filename . ".mp4";
                    $itemid = $fs->create_file_from_pathname($file_record, $to);
                    $file = mediaboard_getfileid($itemid->get_id());
                    @chmod($file->fullpatch, 0755);
                    $DB->set_field($table, "itemid", $itemid->get_id(), array("id" => $itemdata->id));
                    $toimg = $CFG->dataroot . "/temp/" . $itemdata->filename . ".jpg";
                    file_put_contents($toimg, file_get_contents($jsonimg->url));
                    $file_record->filename = $itemdata->filename . ".jpg";
                    $itemid = $fs->create_file_from_pathname($file_record, $toimg);
                    $file = mediaboard_getfileid($itemid->get_id());
                    @chmod($file->fullpatch, 0755);
                    $DB->set_field($table, "itemimgid", $itemid->get_id(), array("id" => $itemdata->id));
                } else {
                    $to = $CFG->dataroot . "/temp/" . $itemdata->filename . ".mp3";
                    file_put_contents($to, file_get_contents($json->url));
                    $file_record->filename = $itemdata->filename . ".mp3";
                    $itemid = $fs->create_file_from_pathname($file_record, $to);
                    $file = mediaboard_getfileid($itemid->get_id());
                    @chmod($file->fullpatch, 0755);
                    if ($table != 'mediaboard_items') {
                        $DB->set_field($table, "itemid", $itemid->get_id(), array("id" => $itemdata->id));
                    } else {
                        $DB->set_field($table, "audio" . $mark, $itemid->get_id(), array("id" => $itemdata->id));
                    }
                }
                unlink($to);
                @unlink($toimg);
                break;
            }
        }
    }
    $item = $DB->get_record_sql("SELECT * FROM {mediaboard_items} WHERE `combinateaudio`=0 AND `type`='photo' LIMIT 1");
    if ($item && $DB->count_records("mediaboard_process", array()) == 0) {
        if ($CFG->mediaboard_audio_convert == 2) {
            $combinatefiles = "";
            for ($i = 1; $i <= 10; $i++) {
                $name = 'audio' . $i;
                if ($file = mediaboard_getfile($item->{$name})) {
                    $combinatefiles .= $file->fullpatch . "\\|";
                }
            }
            mediaboard_runExternal("{$CFG->mediaboard_convert_url} -i concat:{$combinatefiles} -acodec libmp3lame {$CFG->dataroot}/combinate.mp3", $code);
            $filedata = $DB->get_record("mediaboard_files", array("id" => $item->fileid));
            $contextmodule = get_context_instance(CONTEXT_MODULE, $filedata->instance);
            $unicalid = substr(time(), 2) . rand(0, 9);
            $file_record = new stdClass();
            $file_record->component = 'mod_mediaboard';
            $file_record->contextid = $contextmodule->id;
            $file_record->userid = $USER->id;
            $file_record->filearea = 'private';
            $file_record->filepath = "/";
            $file_record->itemid = $unicalid;
            $file_record->license = $CFG->sitedefaultlicense;
            $file_record->author = fullname($USER);
            $file_record->source = '';
            $file_record->filename = "combinate.mp3";
            $itemid = $fs->create_file_from_pathname($file_record, "{$CFG->dataroot}/combinate.mp3");
            unlink("{$CFG->dataroot}/combinate.mp3");
            $DB->set_field("mediaboard_items", "combinateaudio", $itemid->get_id(), array("id" => $item->id));
        } else {
            if ($CFG->mediaboard_audio_convert == 1) {
                $combinatefiles = "";
                for ($i = 1; $i <= 10; $i++) {
                    $name = 'audio' . $i;
                    if ($file = mediaboard_getfileid($item->{$name})) {
                        $link = new moodle_url("/pluginfile.php/{$file->contextid}/mod_mediaboard/0/{$file->id}/");
                        $combinatefiles .= $link . "\\|";
                    }
                }
                $combinatefiles = substr($combinatefiles, 0, -2);
                if (!empty($combinatefiles)) {
                    $data = array('combinate' => $combinatefiles);
                    $options = array('http' => array('method' => 'POST', 'content' => http_build_query($data)));
                    $context = stream_context_create($options);
                    @file_put_contents("{$CFG->dataroot}/combinate.mp3", file_get_contents($CFG->mediaboard_convert_url . '/combinate.php', false, $context));
                    $filedata = $DB->get_record("mediaboard_files", array("id" => $item->fileid));
                    $contextmodule = get_context_instance(CONTEXT_MODULE, $filedata->instance);
                    if (!empty($contextmodule->id) && !empty($item->userid)) {
                        $unicalid = substr(time(), 2) . rand(0, 9);
                        $student = $DB->get_record("user", array("id" => $item->userid));
                        //$fs->delete_area_files($contextmodule->id, 'mod_mediaboard', 'private', $unicalid);
                        $file_record = new stdClass();
                        $file_record->component = 'mod_mediaboard';
                        $file_record->contextid = $contextmodule->id;
                        $file_record->userid = $item->userid;
                        $file_record->filearea = 'private';
                        $file_record->filepath = "/";
                        $file_record->itemid = $unicalid;
                        $file_record->license = $CFG->sitedefaultlicense;
                        $file_record->author = fullname($student);
                        $file_record->source = '';
                        $file_record->filename = "combinate.mp3";
                        $itemid = $fs->create_file_from_pathname($file_record, "{$CFG->dataroot}/combinate.mp3");
                        unlink("{$CFG->dataroot}/combinate.mp3");
                        $DB->set_field("mediaboard_items", "combinateaudio", $itemid->get_id(), array("id" => $item->id));
                    } else {
                        $DB->set_field("mediaboard_items", "combinateaudio", 1, array("id" => $item->id));
                    }
                } else {
                    $DB->set_field("mediaboard_items", "combinateaudio", 1, array("id" => $item->id));
                }
            }
        }
    }
    return true;
}
Пример #25
0
/**
 * Echo the video embed code, related videos and videos owned by the same user
 * as the specified videoId.
 *
 * @param string $videoId The video
 */
function echoVideoPlayer($videoId) 
{
    $yt = new Zend_Gdata_YouTube();
    
    $entry = $yt->getVideoEntry($videoId);
    $videoTitle = $entry->mediaGroup->title;
    $videoUrl = findFlashUrl($entry);
    $relatedVideoFeed = getRelatedVideos($entry->getVideoId());
    $topRatedFeed = getTopRatedVideosByUser($entry->author[0]->name);
    
    print <<<END
    <b>$videoTitle</b><br />
    <object width="425" height="350">
      <param name="movie" value="${videoUrl}&autoplay=1"></param>
      <param name="wmode" value="transparent"></param>
      <embed src="${videoUrl}&autoplay=1" type="application/x-shockwave-flash" wmode="transparent"
        width=425" height="350"></embed>
    </object>
END;
    echo '<br />';
    echoVideoMetadata($entry);
    echo '<br /><b>Related:</b><br />';
    echoThumbnails($relatedVideoFeed); 
    echo '<br /><b>Top rated videos by user:</b><br />';
    echoThumbnails($topRatedFeed); 
}
Пример #26
0
 /**
  * Validate that we can connect to the YouTube API.
  *
  * @return boolean False if there were errors.
  */
 private function validateYouTubeAPIConnectivity()
 {
     $connectivityErrors = array();
     require_once 'Zend/Loader.php';
     Zend_Loader::loadClass('Zend_Gdata_YouTube');
     $yt = new Zend_Gdata_YouTube();
     $topRatedFeed = $yt->getTopRatedVideoFeed();
     if ($topRatedFeed instanceof Zend_Gdata_YouTube_VideoFeed) {
         if ($topRatedFeed->getTotalResults()->getText() < 1) {
             $connectivityErrors[] = 'There was less than 1 video entry' . ' in the \'Top Rated Video Feed\'';
         }
     } else {
         $connectivityErrors[] = 'The call to \'getTopRatedVideoFeed()\' ' . 'did not result in a Zend_Gdata_YouTube_VideoFeed object';
     }
     $this->_allErrors[self::YOUTUBE_API_CONNECTIVITY_ERRORS]['tested'] = true;
     if (count($connectivityErrors) > 0) {
         $this->_allErrors[self::YOUTUBE_API_CONNECTIVITY_ERRORS]['tested'] = $connectivityErrors;
         return false;
     }
     return true;
 }
Пример #27
0
 public function testCommentOnAComment()
 {
     $developerKey = constant('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY');
     $clientId = constant('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID');
     $client = Zend_Gdata_ClientLogin::getHttpClient($this->user, $this->pass, 'youtube', null, 'ZF_UnitTest', null, null, 'https://www.google.com/youtube/accounts/ClientLogin');
     $youtube = new Zend_Gdata_YouTube($client, 'ZF_UnitTest', $clientId, $developerKey);
     $youtube->setMajorProtocolVersion(2);
     $mostDiscussedFeed = $youtube->getVideoFeed('http://gdata.youtube.com/feeds/api/standardfeeds/most_discussed');
     // get first entry
     $mostDiscussedFeed->rewind();
     $firstEntry = $mostDiscussedFeed->current();
     $this->assertTrue($firstEntry instanceof Zend_Gdata_YouTube_VideoEntry);
     $commentFeed = $youtube->getVideoCommentFeed($firstEntry->getVideoId());
     // get first comment
     $commentFeed->rewind();
     $firstCommentEntry = $commentFeed->current();
     $commentedComment = $youtube->replyToCommentEntry($firstCommentEntry, 'awesome ! (ZFUnitTest-test)');
     $this->assertTrue($commentedComment instanceof Zend_Gdata_YouTube_CommentEntry);
 }
Пример #28
0
 public function Test()
 {
     $yt = new Zend_Gdata_YouTube();
     $video_feed = $yt->getVideoFeed($this->feed['feed_url']);
 }
Пример #29
0
<?php

require_once '/usr/share/php/libzend-framework-php/Zend/Gdata.php';
require_once '/usr/share/php/libzend-framework-php/Zend/Gdata/ClientLogin.php';
require_once '/usr/share/php/libzend-framework-php/Zend/Gdata/YouTube.php';
// Enter your Google account credentials
$username = '******';
$passwd = 'parseitup';
$authenticationURL = 'https://www.google.com/accounts/ClientLogin';
try {
    $httpClient = Zend_Gdata_ClientLogin::getHttpClient($username, $passwd, $service = 'youtube', $client = null, $source = 'MySource', $loginToken = null, $loginCaptcha = null, $authenticationURL);
} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
    echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
    echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
} catch (Zend_Gdata_App_AuthException $ae) {
    echo 'Problem authenticating: ' . $ae->exception() . "\n";
}
$developerKey = "AI39si5GlWcy9S4eVFtajbVZk-DjFEhlM4Zt7CYzJG3f2bwIpsBSaGd8SCWts6V5lbqBHJYXAn73-8emsZg5zWt4EUlJJ4rpQA";
$applicationId = "class2go";
$clientId = "";
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
$yt->setMajorProtocolVersion(2);
$dirs_ary = glob('*', GLOB_ONLYDIR);
foreach ($dirs_ary as $dir) {
    $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
    $filestring = file_get_contents($dir . '/vidID.json');
    $vidID = substr($filestring, 1, -1);
    echo "{$dir}: {$vidID}\n";
    $videoEntry = $yt->getVideoEntry($vidID);
    echo 'Edit: ' . $videoEntry->getVideoWatchPageUrl() . "\n";
}
Пример #30
0
 public function getYoutubeVideoSuggestions()
 {
     if (Mage::helper('videogallery')->isVideoSuggestionsEnabled() == false) {
         return array();
     }
     if (!$this->_youtubeFeed) {
         try {
             $product = $this->getProduct();
             if (!$product->getId()) {
                 return array();
             }
             $yt = new Zend_Gdata_YouTube();
             $yt->getHttpClient()->setConfig(array('timeout' => 10));
             $query = $yt->newVideoQuery();
             $query->videoQuery = $product->getName() . ' ' . $product->getSku();
             $query->startIndex = 0;
             $query->maxResults = 5;
             $results = $yt->getVideoFeed($query);
             $this->_youtubeFeed = array();
             foreach ($results as $video) {
                 if ($this->videoAlreadyAdded($video->getVideoId())) {
                     continue;
                 }
                 $this->_youtubeFeed[] = $video;
             }
         } catch (Exception $e) {
             return "Error Retrieving Video Suggestions from Youtube: " . $e->getMessage();
         }
     }
     return $this->_youtubeFeed;
 }