public static function getVideoIDList($youtubeURL, $optionalparameters, &$playlistid) { $optionalparameters_arr = explode(',', $optionalparameters); $videolist = array(); $spq = implode('&', $optionalparameters_arr); $videolist = array(); $keywords = VideoSource_YoutubeSearch::extractYouTubeSearchKeywords($youtubeURL); //echo '$keywords='.$keywords.'<br/>'; //die; if ($keywords == '') { return $videolist; } //WRONG LINK id not found $url = 'https://gdata.youtube.com/feeds/api/videos?q=' . urlencode($keywords) . '&v=2&' . $spq; $xml = false; $htmlcode = YouTubeGalleryMisc::getURLData($url); //print_r($htmlcode); //die; if (strpos($htmlcode, '<?xml version') === false) { if (strpos($htmlcode, 'Invalid id') === false) { return 'Cannot load data, Invalid id'; } return 'Cannot load data, no connection'; } $xml = simplexml_load_string($htmlcode); //print_r($xml); //die; if ($xml) { foreach ($xml->entry as $entry) { $media = $entry->children('http://search.yahoo.com/mrss/'); $link = $media->group->player->attributes(); if (isset($link)) { if (isset($link['url'])) { $videolist[] = $link['url']; } } //if(isset($link) } //foreach ($xml->entry as $entry) } //if($xml){ //print_r($videolist); //die; return $videolist; }
public static function getVideoIDList($youtubeURL, $optionalparameters, &$playlistid) { $optionalparameters_arr = explode(',', $optionalparameters); $videolist = array(); $spq = implode('&', $optionalparameters_arr); $videolist = array(); $keywords = VideoSource_YoutubeSearch::extractYouTubeSearchKeywords($youtubeURL); // echo '$keywords='.$keywords.'<br/>'; // die; require_once JPATH_ADMINISTRATOR . '/components/com_youtubegallery/google/_videos.php'; $videos = new YoutubeVideos(); $videos_raw = $videos->getVideosFromSearch($keywords); $videolist = array(); for ($i = 0, $limit = count($videos_raw); $i < $limit; $i++) { $url = 'https://www.youtube.com/watch?v=' . $videos_raw[$i]->id->videoId; $videolist[] = $url; } return $videolist; }
public static function getVideoIDList($youtubeURL, $optionalparameters, &$playlistid, &$datalink) { $optionalparameters_arr = explode(',', $optionalparameters); $videolist = array(); $base_url = 'https://www.googleapis.com/youtube/v3'; $api_key = YouTubeGalleryMisc::getSettingValue('youtube_api_key'); if ($api_key == '') { return $videolist; } $spq = implode('&', $optionalparameters_arr); $keywords = VideoSource_YoutubeSearch::extractYouTubeSearchKeywords($youtubeURL); if ($keywords == '') { return $videolist; } //WRONG LINK id not found $part = 'id,snippet'; $spq = str_replace('max-results', 'maxResults', $spq); $datalink = $base_url . '/search?q=' . urlencode($keywords) . '&part=' . $part . '&key=' . $api_key . ($spq != '' ? '&' . $spq : ''); $opt = ""; $count = YouTubeGalleryMisc::getMaxResults($spq, $opt); if ($count < 1) { $maxResults = 1; } elseif ($count > 50) { $maxResults = 50; } else { $maxResults = $count; } $videos_found = 0; $nextPageToken = ''; while ($videos_found < $count) { $newspq = str_replace($opt, 'maxResults=' . $maxResults, $spq); $url = $base_url . '/search?q=' . urlencode($keywords) . '&part=' . $part . '&key=' . $api_key . ($newspq != '' ? '&' . $newspq : ''); if ($nextPageToken != '') { $url .= '&pageToken=' . $nextPageToken; } $htmlcode = YouTubeGalleryMisc::getURLData($url); if ($htmlcode == '') { return $videolist; } $j = json_decode($htmlcode); if (!$j) { return 'Connection Error'; } $nextPageToken = $j->nextPageToken; $pageinfo = $j->pageInfo; if ($pageinfo->totalResults < $count) { $count = $pageinfo->totalResults; } $items = $j->items; if (count($items) < $maxResults) { $maxResults = count($items); } foreach ($items as $item) { if ($item->kind == 'youtube#searchResult') { $s = $item->id; if ($s->kind == 'youtube#video') { $videoId = $s->videoId; $videolist[] = 'https://www.youtube.com/watch?v=' . $videoId; } } } $videos_found += $maxResults; if ($count - $videos_found < 50) { $maxResults = $count - $videos_found; } } return $videolist; }