Support » Plugin: Cool Video Gallery » Youtube device support when adding new video's

Viewing 15 replies - 1 through 15 (of 24 total)
  • Same issue here.

    Shame, because this is the best video gallery plugin. Any fix?

    Hi guys,

    This plugin is using the YouTube Data API (v2) not supported anymore since april 2015.

    I have faced the same problem. This issue really bothered me so much that stead of downloading another plugin i have DECIDED to try fixing it or DIE! It took me 2 days to figure it out how YouTube Data API (v3) and How Cool Video Gallery works.

    I have re-build the whole CVGYoutubeAPI class
    to be able to work with YouTube Data API (v3).

    1. Open: /wp-content/plugins/cool-video-gallery/lib/youtube.php
    2. Replace the whole class CVGYoutubeAPI {} with the one below
     * Helper Class for Youtube API
     * @author - Praveen Rajan
    class CVGYoutubeAPI {
    	 * Initializes values
    	 * @author Praveen Rajan
    	function CVGYoutubeAPI() {
    	 * Returns Youtube video ID
    	 * @author Praveen Rajan
    	function getPatternFromUrl($url) {
    		$url = $url . '&';
    		$pattern = '/v=(.+?)&+/';
    		preg_match($pattern, $url, $matches);
    		return ($matches[1]);
    	 * Parses Youtube video to get details of video
    	 * @author Praveen Rajan
    	function parseVideoEntry($entry) {
    		$obj = new stdClass;
    		// get nodes in media: namespace for media information
    		$media = $entry ;
    		$obj -> title = $media -> {'items'}[0]->{'snippet'}->{'title'};
    		$obj -> description = $media -> {'items'}[0] -> {'snippet'} -> {'description'};
    		// get video player URL
    		$obj -> watchURL = '' . $media -> {'items'}[0] -> {'id'};
    		// get video thumbnail
    		$obj -> thumbnailURL = $media -> {'items'}[0] -> {'snippet'} -> {'thumbnails'} -> {'default'} -> {'url'};
    		// get <yt:duration> node for video length
    		$obj -> length = $media -> {'items'}[0] -> {'contentDetails'} -> {'duration'};
    		// get <yt:stats> node for viewer statistics
    		$obj -> viewCount = $media -> {'items'}[0] -> {'statistics'} -> {'viewCount'};
    		// get <gd:rating> node for video ratings
    		$gd = $media -> {'items'}[0] -> {'statistics'} -> {'likeCount'};
    		if ( $gd > 0 ) {
    			$obj -> rating = $media -> {'items'}[0] -> {'statistics'} -> {'likeCount'};
    		} else {
    			$obj -> rating = 0;
    		// get <gd:comments> node for video comments
    			$obj -> commentsURL = '' . $media -> {'items'}[0] -> {'id'};
    			$obj -> commentsCount = $media -> {'items'}[0] -> {'statistics'} -> {'commentCount'};
    		// get feed URL for video responses
    			$obj -> responsesURL = '' . $media -> {'items'}[0] -> {'id'};
    		// get feed URL for related videos
    			$obj -> relatedURL = '';
    		// return object to caller
    		return $obj;
    	 * Returns Youtube video details
    	 * @author Praveen Rajan
    	function youtube_video_details($vid) {        
        $url = "". $key_id ."&id=". $vid;
    		// set JSON video data fetching URL
    		$feedURL = '' . $vid;
    		$entry = json_decode(file_get_contents($url,0,null,null),false);
    		// parse video entry
    		$video = $this -> parseVideoEntry($entry);
    			return $video;

    To make it work you need to create a API key
    Public API access Key => Key for server applications
    Then at your google dashboard give permission to Youtube.

    Go here: to create a new api key and give permission to youtube.

    Tried your way, payplautje, but still can’t seem to get it to work.

    Got the API key, added YouTube Data API and even YouTube Analytics API..

    Added your code and then put my API key here: $key_id=’YOUR_GOOGLE_API_KEY’;

    What error are you getting? And can you plz post your source code here.

    Just to be sure i have made a short video adding the API, i was doing all correct also but it was not going at the first 3 attempts cause i haven’t selected the right project on the Google Console Dashboard, I was giving permission to the YouTube API on another project. Just check this video.

    Cool Video Gallery: Generating & Adding YouTube API Key v3


    I also tried your solution but there is no difference, the same video appears ( instead of the correct one.

    Can you guys Zip your cool video gallery folder, and email it to me…
    Im really curious to know what is wrong then, mine is working perfectly.


    Hi, I try your code and it work a little, but not work completely. I see the video preview in gallery view and when i publish it and i see in post there is a error : [video not fund], so what issue is it?
    I have another question, I hope the youtube video can download to my gallery in my wordpress website, not just place a youtube video url in gallery view, so how to fix it? looking for help,thanks.


    @payplautje: I found what the problem was in my case. After using your solution, I also need to re-add the videos because the correct link was not saved in database.
    Adding again the videos solved the problem.


    hi i change youtube.php and the video is loaded, but when i click on it i receive this message “Task Queue failed at step 5: Playlist could not be loaded due to crossdomain policiy restrictions.”
    i use jwplayer to view the youtube video..

    this for new video , for old ones i have no problem.


    i change this line
    $obj -> watchURL = '' . $media -> {'items'}[0] -> {'id'};

    with this one for cookie policy reason

    $obj -> watchURL = '' . $media -> {'items'}[0] -> {'id'};

    onliy with this change i receive the error…

    another problem
    in Manage Gallery where i see the list of the videos, for new ones i see this: Duration: 00:00:00.0

    why now it can’t retrieve the duration of the video?

    thanks for your response @payplautje

    I’ve changed youtube.php but when i click on it (in Manage Gallery) i receive this message “Invalid Video ID”.
    I also have the same problem of Nexart (Duration 00:00:00:0).
    Thanks to all

    @cica.c : probably you have entered the full link to the video, you had to enter only the VIDEO ID….

    Guys this method with a proper API key is working for me.

    i have the proper API key, but the duration is still 0:00:00

    in youtube.php we have

    // get <yt:duration> node for video length
    $obj -> length = $media -> {'items'}[0] -> {'contentDetails'} -> {'duration'};

    but in gallery-details.php we have:
    _e('<b>Duration:</b> '); echo $video_meta_data['videoDuration'];

    maybe we have to change $video_meta_data['videoDuration']; ?

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘Youtube device support when adding new video's’ is closed to new replies.