Bir video PHP kullanarak, YouTube'da var olmadığını nasıl kontrol edebilirim?
What about using Youtube's API ?
After all, that would mean using some official, which is less likely to change than going with parsing some HTML page.
Detaylı bilgi için: YouTube APIs and Tools - Developer's Guide: PHP strong>
The Retrieving a specific video entry seems quite interesting : if you send a request to an URL like this one :
http://gdata.youtube.com/feeds/api/videos/videoID
(Replacing "videoID" by the idea of the video, of course -- "GeppLPQtihA" in your example)
Video geçerli olup olmadığını, bazı ATOM yayınını alırsınız; ve "Geçersiz kimliği" eğer o değil
And, I insist : this way, you rely on a documented API, and not on some kind of behavior that exists today, but is not garanteed.
Böylece gibi HEAD yöntemi ile URL'leri isteyin:
HEAD /watch?v=p72I7g-RXpg HTTP/1.1
Host: www.youtube.com
HTTP/1.1 200 OK
[SNIP]
HEAD /watch?v=p72I7g-BOGUS HTTP/1.1
Host: www.youtube.com
HTTP/1.1 303 See Other
[SNIP]
Location: http://www.youtube.com/index?ytsession=pXHSDn5Mgc78t2_s7AwyMvu_Tvxn6szTJFAbsYz8KifV-OP20gt7FShXtE4gNYS9Cb7Eh55SgoeFznYK616MmFrT3Cecfu8BcNJ7cs8B6YPddHQSQFT7fSIXFHd5FmQBk299p9_YFCrEBBwTgtYhzKL-jYKPp2zZaACNnDkeZxCr9JEoNEDXyqLvgbB1w8zgOjJacI4iIS6_QvIdmdmLXz7EhBSl92O-qHOG9Rf1HNux_xrcB_xCAz3P3_KbryeQk_9JSRFgCWWgfwWMM3SjrE74-vkSDm5jVRE3ZlUI6bHLgVb7rcIPcg
Bir youtube url gerçek youtube video bir url ise doğrulamak istiyor? Bu oldukça zor, düzenli ifadeleri kullanabilirsiniz, ancak bir youtube url ifade geçerli yollar yükler vardır unutmayın:
Ayrıca video kod alfanümerik karakterler, alt çizgiler,-karakterleri (onlar ne denir bilmiyorum) ve muhtemelen daha fazla içerebilir.
I tried @Pascal MARTIN's answer but it was giving me wrong results so I just decided to improve @streetlogics's suggestion: using Youtube oEmbed support. If I want to know if the video with videoID=yyDUC1LUXSU exists I just need to get the header from http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=yyDUC1LUXSU.
function get_http_response_code($theURL) {
$headers = get_headers($theURL);
return substr($headers[0], 9, 3);
}
$string = "http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=$videoID&format=json";
$code = get_http_response_code ($string);
if ($code == "404") {
//Url doesn't exist anymore
} else {
//You are good to go!
}
Sadece kurulum $ videoID değişken hatırlamak ve gitmek iyidir ;)