Validate mp3 url link

oracle

New Member
Messages
430
Reaction score
0
Points
0
Hello,

I have this problem which i am unable to solve, kindly help me with a code if possible:

I have this mp3 url:
http://www.yaymita.net/wp-content/uploads/2007/01/BGSR.mp3

Now one first look it seems to be an mp3 file, but actually its an html page.

So in my application I need to filter out such links.

However I am unable to find a method through which I can validate such links from normal mp3 links (valid ones i mean) like :
http://download.fmw11.com/songs/Audio/indian/movies/Om Shanti Om (2007)/01 - Ajab Si - K. K. @ Fmw11.com.mp3

Can someone please help me on this ??
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
Moved to programming help

You would probably have to use some type of fopen or something similar to verify the actual file. I'm not really sure of any other way to make sure it's really an mp3 file.

-Corey
 

Jober68

Member
Messages
63
Reaction score
0
Points
6
Fopen is the only way I can think of... possibly an htaccess file? although i would have no Idea how other than restrict file size so that it has to be greater than like 1000kb because I don't know of any pages that are larger than that...
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
I would try using the Fileinfo PECL extension, or, if that doesn't work, the mime_content_type() function. But from what I know, the mime_content_type() function isn't very reliable.

If neither of those work, or if you know your server doesn't support them, then you'll have to use fopen()/fread() on the file as stated above. This method is actually most reliable if the algorithm is well written. However, it would probably be preferred to try to install the Fileinfo extension before doing that as the algorithm can get rather complex, especially with files like mp3's.

The only other option I can think of would be to have human validation of the mp3's before they're officially added. But this isn't really viable if you expect many submissions, unless you have a large team of validators.

If you have to resort to creating a byte checking algorithm, then you need to at least figure out all the common magic numbers for mp3's. That is, the bytes which are common to all mp3's, which usually appear at or around the beginning of a file. The magic.mime file, which mime_content_type() uses, only lists FFF0. I'm very certain there's more than that, though.

You'll have to view your own mp3's in a hex editor to determine the common bytes, unless you can find an online resource. Be sure to confirm them by messing around with the bytes and seeing if an mp3 player can still play them. From what I can tell by messing around with my own mp3's, you've really got your work cut out for you if you have to make this algorithm :p
 
Top