Youtube ve Vimeo-klipleri geçerli olup olmadığını kontrol edin

4 Cevap php

Ben teslim bağlantılar youtube.com veya vimeo.com geçerli film klipleri olup olmadığını kontrol etmek için sessiz bir süre için çalışıyorlar ama ben başarılı did't.

Url gibi nasıl kontrol Herhangi bir fikir:

http://www.youtube.com/watch?v=jc0rnCBCX2c&feature=fvhl (valid)
http://www.youtube.com/watch?v=jc0FFCBCX2c&feature=fvhl (not valid)
http://www.youtube.com/v/jc0rnCBCX2c (valid)
http://www.youtube.com/v/ddjcddddX2c (not valid)
http://www.vimeo.com/463l522 (not valid)
http://www.vimeo.com/1483909 (valid)
http://www.vimeo.com/lumiblue (not valid)
http://www.youtube.com/user/dd181921 (not valid)

?

Ben php kullanmak.

4 Cevap

i see a answer in this site : www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23765374.html

ve dedi:

I would suggest using youtube's API since you are trying to validate if the video exists. or if you don't want to go into API stuff then you can do simple trick. check this link:

http://code.google.com/apis/youtube/developers_guide_php.html#RetrievingVideoEntry

Eğer "v" değeri ayıklamak ve video kimliği için içeren bir istek göndermek için gereken bir videonun varlığını denetlemek için:

http://gdata.youtube.com/feeds/api/videos/videoID

where videoID is the "v" value for example a video FLE2htv9oxc will be queried like this http://gdata.youtube.com/feeds/api/videos/FLE2htv9oxc if it does not exist then you will get a page with "Invalid id" if it exists, will return an XML feed having various info about the video. this way you can check that the video exists.

Bu doğru yönde elde umuyoruz.

the same thing with vimeo , try to look in api documentation in there site. http://www.vimeo.com/api

Video var ve bir 400 (kötü istek) eğer video yoksa eğer videoId google video tanıtıcı olduğu http://gdata.youtube.com/feeds/api/videos/videoId, almalısınız bir 200 bir istek yanıt başlıklarını kontrol edin.

// PHP code

// Check if youtube video item exists by the existance of the the 200 response
$headers = get_headers('http://gdata.youtube.com/feeds/api/videos/' . $youtubeId);
if (!strpos($headers[0], '200')) {
    echo "The YouTube video you entered does not exist";
    return false;
}

Ben bağlantı geçerli youtube bağlantı olup olmadığını kontrol etmek için bu fonksiyonu yazdım.

/**
 * This function will check if 'url' is valid youtube video and return the ID.
 *  If the return value === false then this is **not** a valid youtube url, otherwise   the youtube id is returned.
 *
 * @param <type> $url
 * @return <type>
 */


 private static function get_youtube_id($url) {
        $link = parse_url($url,PHP_URL_QUERY);

    /**split the query string into an array**/
    if($link == null) $arr['v'] = $url;
    else  parse_str($link, $arr);
    /** end split the query string into an array**/
    if(! isset($arr['v'])) return false; //fast fail for links with no v attrib - youtube only

    $checklink = YOUTUBE_CHECK . $arr['v'];

    //** curl the check link ***//
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$checklink);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    $result = curl_exec($ch);
    curl_close($ch);

    $return = $arr['v'];
    if(trim($result)=="Invalid id") $return = false; //you tube response

    return $return; //the stream is a valid youtube id.
}

Bu video artık geçerli olmadığını you tube atar 301 başlık yakalamak için deneyebilirsiniz