Forum Moderators: coopster

Message Too Old, No Replies

How to detect if a video url is valid?

how Detect video url valid

         

btsinc

5:24 pm on Oct 12, 2006 (gmt 0)

10+ Year Member



how do i detect if a video url is valid or not with php?

henry0

6:13 pm on Oct 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



btsinc Welcome to WebmasterWorld!

I have been toying with that for a while

What are your requirements?

is the URL looking like [www....] etc...?
then
1)check if well formed
2)check for bad words
3)does it exists (Is the DN for real)?

let us know

btsinc

6:32 pm on Oct 12, 2006 (gmt 0)

10+ Year Member



hey henry , maybe i should have clarified.. i know the url is valid , want to know if the file is a valid video file

MattAU

9:31 pm on Oct 12, 2006 (gmt 0)

10+ Year Member



I think it'd be very hard... What's a valid video file? Mpg? Wmv? Flash? Quicktime? Divx? etc.

[edited by: coopster at 9:49 pm (utc) on Oct. 12, 2006]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]

ahmedtheking

9:34 pm on Oct 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, go get a video file, open it up in a text editor. You'll notice the first lines will have text in them. They'll normally say what the encoder was. So if you open, say, the first 10 lines of a video file, you can confirm that it's a vid and what the encoder is!

MattAU

9:53 pm on Oct 12, 2006 (gmt 0)

10+ Year Member



I just tried that with a few different mpeg and wmv files, one of them had the program that was used to encode it, the others had nothing.

However, if that does indeed happen with most videos, open the url with fopen / fsockopen, read the first x number of chars, make an array of all the different text strings that appear in the video types you're looking for and then search for those strings in the data you've read.

$handle = fopen('http://url...');
$data = fread($handle,4096); // reading 4096 chars
fclose($handle);

$video_text = array('Mpeg text string','Other mpeg string','wmv string'...);

foreach($video_text as $video_str)
{
if(strpos($data,$video_arr)!== false)
{
//is video
}
}

It'd also be worth checking out the Snoopy class, it makes open urls and getting the data very easy.