Viewing 9 replies - 16 through 24 (of 24 total)
  • HI guys,

    sorry for not getting back at you asap, i have been really busy with my work.

    I’m seeing all kind of small issues, i have just create a solution that works for me, for the rest we can solve it as we are doing it now, collaborating. I don’t really have the time to check everyone’s issues with this plugin, but i can try to help, I give you the guidance and the most important piece of code to make it work, it is not working then lets all get involved and try one another. I’m happy that my solution though helped some of you.

    @nextart I think you are right most of the values i have copied from youtube, a couple of them did changed i have noticed, certainly i forgot that one so yes try changing to the one in youtube “videoDuration” stead of “duration”. I will have to change also in my code.

    thanks.

    Hi payplautje thanks for your response, but if i change “videoDuration” instead of “duration” , in Manage Gallery is still 0:00:00..

    for “Task Queue failed at step 5” problems?
    no one use youtube-nocookie solution?

    bye
    Maurizio

    @nextart: thanks for your replay! ??

    I entered only the VIDEO ID (https://www.youtube.com/watch?v=5OYKlN36LNg -> 5OYKlN36LNg).

    I also have the same problem about “Duration 0:00:00”.

    I’ll try to find a solution…

    Bye,
    Simona

    duration is still 0:00:00…. ??

    also for me….. ??

    If you use the function file_get_contents(); remember you must activate
    extension=php_openssl.dll
    allow_url_include = On

    in ph.ini file, beacuse the “https” url get the data.

    Other option is use the code:
    —–
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
    curl_close($ch);
    $entry = json_decode($result,false);

    —–
    and commented this line:
    //$entry = json_decode(file_get_contents($url,0,null,null),false);

    I hope this tip will be useful.

    Regards.

    Hi, this should work as expected:

    <?php
    /**
     * 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 = 'https://www.youtube.com/watch?v=' . $media -> {'items'}[0] -> {'id'};
    		$obj -> watchURL = 'https://www.youtube-nocookie.com/embed/' . $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 = ISO8601ToSeconds ( $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 = 'https://www.youtube.com/watch?v=' . $media -> items[0] -> id;
    			$obj -> commentsCount = $media -> items[0] -> statistics -> commentCount;
    
    		// get feed URL for video responses
    			$obj -> responsesURL = 'https://www.youtube.com/watch?v=' . $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) {        
    
        $key_id='your-api-key';
        $url = "https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics,status&key=". $key_id ."&id=". $vid;
    
    		// set JSON video data fetching URL
    		//$feedURL = 'https://gdata.youtube.com/feeds/api/videos/' . $vid;
    
    		$entry = json_decode(file_get_contents($url,0,null,null),false);
    
    		// parse video entry
    		$video = $this -> parseVideoEntry($entry);
    
    			return $video;
    
    	}
    }
    
    /**
     * Convert ISO 8601 values like PT15M33S
     * to a total value of seconds.
     *
     * @param string $ISO8601
     */
    function ISO8601ToSeconds($ISO8601)
    {
        preg_match('/\d{1,2}[H]/', $ISO8601, $hours);
        preg_match('/\d{1,2}[M]/', $ISO8601, $minutes);
        preg_match('/\d{1,2}[S]/', $ISO8601, $seconds);
    
        $duration = [
            'hours'   => $hours ? $hours[0] : 0,
            'minutes' => $minutes ? $minutes[0] : 0,
            'seconds' => $seconds ? $seconds[0] : 0,
        ];
    
        $hours   = substr($duration['hours'], 0, -1);
        $minutes = substr($duration['minutes'], 0, -1);
        $seconds = substr($duration['seconds'], 0, -1);
    
        $toltalSeconds = ($hours * 60 * 60) + ($minutes * 60) + $seconds;
    
        return $toltalSeconds;
    }
    ?>

    Just replace your-API-key with your real Youtube API key ??

    Note: if you get crossdomain policy errors, just modify the code as follows:

    // get video player URL
    $obj -> watchURL = 'https://www.youtube.com/watch?v=' . $media -> {'items'}[0] -> {'id'};
    //$obj -> watchURL = 'https://www.youtube-nocookie.com/embed/' . $media -> items[0] -> id;

    Plugin Author Praveen Rajan

    (@praveen-rajan)

    Latest youtube API integration Youtube API 3.0 added in plugin. Thanks everyone for support.

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