function formVideoList($rawList, &$firstvideo) { $getinfomethod = YouTubeGalleryMisc::getSettingValue('getinfomethod'); $gallery_list = array(); $main_ordering = 10000; //10000 step foreach ($rawList as $b) { $datalink = ''; $playlistid = ''; $b = str_replace("\n", '', $b); $b = trim(str_replace("\r", '', $b)); $listitem = $this->csv_explode(',', $b, '"', false); $theLink = trim($listitem[0]); if (!(strpos($theLink, '/embed/') === false)) { //Convert Embed links to Address bar version $theLink = str_replace('www.youtube.com/embed/', 'youtu.be/', $theLink); $theLink = str_replace('youtube.com/embed/', 'youtu.be/', $theLink); } $vsn = $this->getVideoSourceName($theLink); if (isset($listitem[4])) { $specialparams = $listitem[4]; } else { $specialparams = ''; } if ($vsn == 'youtubeplaylist') { require_once 'youtubeplaylist.php'; $newlist = VideoSource_YoutubePlaylist::getVideoIDList($theLink, $specialparams, $playlistid, $datalink); } elseif ($vsn == 'youtubechannel') { require_once 'youtubechannel.php'; $newlist = VideoSource_YoutubeChannel::getVideoIDList($theLink, $specialparams, $playlistid, $datalink); } elseif ($vsn == 'youtubeshow') { require_once 'youtubeshow.php'; $newlist = VideoSource_YoutubeShow::getVideoIDList($theLink, $specialparams, $playlistid, $datalink); } elseif ($vsn == 'youtubeuserfavorites') { require_once 'youtubeuserfavorites.php'; $newlist = VideoSource_YoutubeUserFavorites::getVideoIDList($theLink, $specialparams, $playlistid, $datalink); } elseif ($vsn == 'youtubeuseruploads') { require_once 'youtubeuseruploads.php'; $newlist = VideoSource_YoutubeUserUploads::getVideoIDList($theLink, $specialparams, $playlistid, $datalink); } elseif ($vsn == 'youtubestandard') { require_once 'youtubestandard.php'; $newlist = VideoSource_YoutubeStandard::getVideoIDList($theLink, $specialparams, $playlistid, $datalink); } elseif ($vsn == 'youtubesearch') { require_once 'youtubesearch.php'; $newlist = VideoSource_YoutubeSearch::getVideoIDList($theLink, $specialparams, $playlistid, $datalink); if (!is_array($newlist)) { echo 'Youtube Search: ' . $newlist; die; } } elseif ($vsn == 'vimeouservideos') { require_once 'vimeouservideos.php'; $newlist = VideoSource_VimeoUserVideos::getVideoIDList($theLink, $specialparams, $playlistid, $datalink); } elseif ($vsn == 'vimeochannel') { require_once 'vimeochannel.php'; $newlist = VideoSource_VimeoChannel::getVideoIDList($theLink, $specialparams, $playlistid, $datalink); } elseif ($vsn == 'vimeoalbum') { require_once 'vimeoalbum.php'; $newlist = VideoSource_VimeoAlbum::getVideoIDList($theLink, $specialparams, $playlistid, $datalink); } elseif ($vsn == 'dailymotionplaylist') { require_once 'dailymotionplaylist.php'; $newlist = VideoSource_DailymotionPlaylist::getVideoIDList($theLink, $specialparams, $playlistid, $datalink); } $channels_youtube = array('youtubeuseruploads', 'youtubestandard', 'youtubeplaylist', 'youtubeshow', 'youtubeuserfavorites', 'youtubesearch', 'youtubechannel'); $channels_other = array('vimeouservideos', 'vimeochannel', 'vimeoalbum', 'dailymotionplaylist'); $channels_vimeo = array('vimeouservideos', 'vimeochannel', 'vimeoalbum'); if (in_array($vsn, $channels_youtube) or in_array($vsn, $channels_other)) { if (in_array($vsn, $channels_youtube)) { $video_source = 'youtube'; } if (in_array($vsn, $channels_vimeo)) { $video_source = 'vimeo'; } if ($vsn == 'dailymotionplaylist') { $video_source = 'dailymotion'; } $new_List_Clean = array(); $ordering = 1; $startsecond = 0; $endsecond = 0; if (isset($listitem[5])) { $startsecond = $listitem[5]; } if (isset($listitem[6])) { $endsecond = $listitem[6]; } // if (is_array($newlist)) { foreach ($newlist as $theLinkItem) { $item = $this->GrabVideoData($theLinkItem, $video_source, '', $getinfomethod); if ($item['videoid'] != '') { if ($firstvideo == '') { $firstvideo = $item['videoid']; } $item['ordering'] = $main_ordering + $ordering; if (isset($listitem[1])) { $item['title'] = $listitem[1]; $item['custom_title'] = $listitem[1]; } if (isset($listitem[2])) { $item['description'] = $listitem[2]; $item['custom_description'] = $listitem[2]; } if (isset($listitem[3])) { if (strpos($listitem[3], '#') === false) { $item['imageurl'] = $listitem[3]; } $item['custom_imageurl'] = $listitem[3]; } $item['startsecond'] = $startsecond; $item['endsecond'] = $endsecond; $new_List_Clean[] = $item; $ordering++; } } $item = array('datalink' => $datalink, 'videosource' => $vsn, 'videoid' => $playlistid, 'imageurl' => '', 'title' => '', 'description' => '', 'specialparams' => $specialparams, 'count' => count($new_List_Clean), 'link' => '', 'ordering' => $main_ordering, 'channel_username' => '', 'channel_title' => '', 'channel_subscribers' => '', 'channel_subscribed' => '', 'channel_location' => '', 'channel_commentcount' => '', 'channel_viewcount' => '', 'channel_videocount' => '', 'channel_description' => '', 'channel_totaluploadviews' => ''); if ($vsn == 'youtubeuseruploads' and !(strpos($specialparams, 'moredetails=true') === false)) { //Try to get channel info require_once 'youtubeuseruploads.php'; $datalink = $item['datalink']; $user_info = VideoSource_YoutubeUserUploads::getUserInfo($theLink, $item); if ($user_info != '') { $item['channel_title'] = $user_info; } $item['datalink'] = $datalink . ',' . $item['datalink']; } $gallery_list[] = $item; $gallery_list = array_merge($gallery_list, $new_List_Clean); } //for } elseif ($vsn == 'videolist') { $linkPair = explode(':', $theLink); if (isset($linkPair[1])) { if (trim($linkPair[1]) == 'all') { $vID = -1; } elseif (trim($linkPair[1]) == 'category') { if (isset($linkPair[2])) { $vID = 'category=' . $linkPair[2]; } } elseif (trim($linkPair[1]) == 'catid') { if (isset($linkPair[2])) { $vID = 'catid=' . (int) $linkPair[2]; } } else { $vID = (int) $linkPair[1]; } $item = array('videosource' => $vsn, 'videoid' => $vID, 'isvideo' => "0", 'imageurl' => '', 'title' => '', 'description' => '', 'specialparams' => '', 'count' => '', 'link' => '', 'ordering' => ''); $gallery_list[] = $item; } } else { $item = $this->GrabVideoData($listitem, $vsn, '', $getinfomethod); if (isset($item['videoid']) and $item['videoid'] != '') { if ($firstvideo == '') { $firstvideo = $item['videoid']; } $item['ordering'] = $main_ordering; $gallery_list[] = $item; } } $main_ordering += 10000; } //foreach($rawList as $b) return $gallery_list; }
public static function getVideoIDList($youtubeURL, $optionalparameters, &$channelid, &$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); $channelid = VideoSource_YoutubeChannel::extractID($youtubeURL); if ($channelid == '') { return $videolist; } //user id not found $part = 'id,snippet'; $spq = str_replace('max-results', 'maxResults', $spq); $datalink = $base_url . '/search?channelId=' . $channelid . '&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?channelId=' . $channelid . '&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') { $idKind = $item->id->kind; if ($idKind == 'youtube#video') { $videoId = $item->id->videoId; $videolist[] = 'https://www.youtube.com/watch?v=' . $videoId; } } } $videos_found += $maxResults; if ($count - $videos_found < 50) { $maxResults = $count - $videos_found; } } return $videolist; }