tags:

views:

57

answers:

3

I'm trying to create a code to download mp3 files embedded in a page. It starts out as a submit form. You input the URL and submit it, and it writes the HTML source of that page to a text file. I also set the script to search the source to see if there is an audio file embedded. I suppose I should include that it's not in the format of filename.mp3. The format is:

embed type="application/x-shockwave-flash" src="http://diaryofthedead.tumblr.com/swf/audio_player_black.swf?audio_file=http://www.tumblr.com/audio_file/1435664895/tumblr_lb2ybulZkt1qb5hrc&color=FFFFFF" height="27" width="207" quality="best"

So here's the thing, there's just a certain string you have to add to the end of the file, for it to redirect to the mp3 file. I know the string. What I want to do is extract, for example "http://www.tumblr.com/audio_file/1435664895/tumblr_lb3ybulZkt1q5hrc" from the middle of this. I know how to read from files but I have no idea how to extract certain parts from it without knowing the exact filename already. So is there any way I can have it search the source for "audio_file" and if it finds the string, extract the audio file?

A: 

You can try using preg_match (http://php.net/manual/en/function.preg-match.php) to get the contents between "audio_file=" and "&".

Or you can also use a string between function to get the contents between those two strings: http://www.php.net/manual/en/function.substr.php#89493

Andrew M
A: 

If your program is just a parser for extracting MP3 files embedded in a webpage you don't even need to save the contents of the webpage onto a file, you can work with the page source inside just your server's memory.

If you want to detect paths to MP3 inside flashes, provided you know how does it match a regular expression, you are done.

If you don't know much about rgular expressions, you should look at them.

If you don't want as much power as a regular expression can give to you, you can always find strings by position, like:

$pos = strpos($haystack, $needle);

Beware: strpos() will find the first (strrpos will find the last) occurrence of a string. So you need to make it as explicit as you can, or you might end up capturing something unwanted.

Take a look at http://www.regular-expressions.info/quickstart.html or something similar.

I can't post more links because I don't have enough reputation yet

ssice
A: 

Thank you all! This is excellent. I found a solution using the first answer, but I'll definitely start looking into regular expressions. Thanks again, I've learned a lot from this. :)

Tommy