Click to See Complete Forum and Search --> : file read, preg match, echo matched content


bustya
02-01-2008, 06:13 PM
Sounds simple enough, but I can't get it working. What I'm trying to accomplish here is to first check the url (to the file) to see if it's valid, if so I want to read the url found in the file's embed tag and then write it to an object tag.

This is to retrieve a myspace band mediaplayer. I don't want the entire object from myspace because I want to change the size of the object I'm going to echo.

So basically I want to read the page, retrieve the url from the embed and use that url in my own object tag.


Here's a sample of the code as it is on myspace, this is the entire object, but I just need the url in the embed tag....



<OBJECT id="mp3player" codeBase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab##version=8,0,0,0"
height="345" width="450" border="0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
VIEWASTEXT>
<PARAM NAME="_cx" VALUE="11906">
<PARAM NAME="_cy" VALUE="9128">
<param name="FlashVars" value="culture=en-US" />
<PARAM NAME="Movie" VALUE="http://lads.myspace.com/music/musicplayer.swf?n=aHR0cDovL211c2ljLm15c3BhY2UuY29t&t=lBupI3PXcwP0zfuzSQhr6cciFVqGNE8HgoT7HiVxolb6QF+rHo57DjLKAB/cg4u+yZigshK1U9b9iJR3az+YIA==&u=LTE=&a=0&d=MTM0MDIwNDcwXjEyMDE4ODIxOTI=">
<PARAM NAME="Src" VALUE="http://lads.myspace.com/music/musicplayer.swf?n=aHR0cDovL211c2ljLm15c3BhY2UuY29t&t=Qd15jlyjjVzXW+MzKr4kTt8b2vx98BnFkjbo0tSaW3XbI95SFyaaF8VXtCx+1p+TJu3ZvrL3/MQWKw4bUn4+Qg==&u=LTE=&a=0&d=MTM0MDIwNDcwXjEyMDE4ODIxOTI=">

<PARAM NAME="WMode" VALUE="Window">
<PARAM NAME="Play" VALUE="-1">
<PARAM NAME="Loop" VALUE="-1">
<PARAM NAME="Quality" VALUE="High">
<PARAM NAME="SAlign" VALUE="">
<PARAM NAME="Menu" VALUE="-1">
<PARAM NAME="Base" VALUE="">
<PARAM NAME="AllowScriptAccess" VALUE="always">
<PARAM NAME="Scale" VALUE="ShowAll">

<PARAM NAME="DeviceFont" VALUE="0">
<PARAM NAME="EmbedMovie" VALUE="0">
<PARAM NAME="BGColor" VALUE="#FFF">
<PARAM NAME="SWRemote" VALUE="">
<PARAM NAME="MovieData" VALUE="">
<PARAM NAME="SeamlessTabbing" VALUE="1">
<embed src="http://lads.myspace.com/music/musicplayer.swf?n=aHR0cDovL211c2ljLm15c3BhY2UuY29t&t=j8ASSojSr0Gd3BARpJ/3WCFe+CtSyYjl0VY9/CsqpYo/9gAW9JiXb1okplxRG1OUtg1ywNlsIxRBnA928TB+Hw==&u=LTE=&a=0&d=MTM0MDIwNDcwXjEyMDE4ODIxOTI=" quality=high bgcolor=#FFFFFF
width="450" height="345" name="mp3player" align="" AllowScriptAccess="always"
type="application/x-shockwave-flash" FlashVars="culture=en-US"
pluginspage="http://www.macromedia.com/go/getflashplayer"> </embed>
</OBJECT>



Now here's the code I'm working on, this reads/echos the entire page, not what I want, but close.


<?php

// set file to read
$file = 'http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=134020470';
// read file into string
$data = file_get_contents($file) or die('Could not read file!');
// print contents
echo $data;

?>


I tried adding preg_match to the above but to no avail, something like so:


<?php

// set file to read
$file = 'http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=134020470';
// read file into string
$player = preg_match("/<embed src=\"(.*)\"*><\/embed>/", $file);
$data = file_get_contents($player) or die('Could not read file!');
// print contents
echo $data;

?>



The above returns a '0', as in nothing in the array. Any ideas?

Also, there's one last thing to consider. If the object (embed) no longer exists on the myspace page, i need to return text instead of a broken object.

andre4s_y
02-01-2008, 06:55 PM
Wrong step of your code...
You need to get the page first before you can capture the embed's url..
try :

// set file to read
$file = 'http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=134020470';
// read file into string
$data = file_get_contents($file) or die('Could not read file!');
preg_match("/<embed src=\"(.*)\"*><\/embed>/", $data,$player);
// print contents
echo $player[1];

bustya
02-01-2008, 07:09 PM
Hmm, I tried that, still no luck.

andre4s_y
02-01-2008, 07:19 PM
I think your pattern is not correct...
Try :

preg_match("/\<embed.*src\=\"(.+)\".*\>.*\<\/embed\>/Us",$data,$player);

Replace it in my old preg_match() function..
Sorry, i can not try it in the actual page, because my internet connection is very slow here.. i can not open http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=134020470...

bustya
02-01-2008, 07:25 PM
That did it, thanks. Here it is all together...


<?php

// set file to read
$file = 'http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=134020470';
// read file into string
$data = file_get_contents($file) or die('Could not read file!');
preg_match("/\<embed.*src\=\"(.+)\".*\>.*\<\/embed\>/Us",$data,$player);
// print contents
echo $player[0];

?>



Thanks again.

andre4s_y
02-01-2008, 07:34 PM
If you want the url inside the embed tag,
it is quicker if you echo-ing $player[1]...
Inside $player[1] is the url -> http://blablabla
because of the subpattern in preg_match() function..

And if you want to check the page : the page has embed tag with url inside it or not, use :

if(preg_match(...))
{
//if there is a url here..
}
else
{
//if there is no url here..
}

Finally, some luck arrived.... :P

ZAP Killer
04-29-2008, 06:27 AM
Hello

I was using this kind of procedure to grab the MySpace player. It was a very usefull and appreciated function on my website, but this WE, a visitor called me to and said "... it is now a big white square ...".

It was a bad news. MySpace doesn't allowed anymore its player from other domains (or ip addresses ?).

So I quickly tried to put the player (musicplayer.swf) in a iframe, but it is only works with few MySpace accounts.

Any idea, any great idea ?

bustya
05-03-2008, 09:53 PM
Hello

I was using this kind of procedure to grab the MySpace player. It was a very usefull and appreciated function on my website, but this WE, a visitor called me to and said "... it is now a big white square ...".

It was a bad news. MySpace doesn't allowed anymore its player from other domains (or ip addresses ?).

So I quickly tried to put the player (musicplayer.swf) in a iframe, but it is only works with few MySpace accounts.

Any idea, any great idea ?

I just checked my old music streaming project (using myspace's music) and you're right, they're disallowing hotlinks now... probably my fault. This must be a new development in the last week. Well, screw them anyway I've got a better site for streaming music: Deezer.com (http://www.deezer.com). I'm now building my own personal library out of their database using the GET method to swap songs and/or playlists. You can check that out right here: My Streaming Music Library (http://www.4thenextstep.com/player/player.php). I've gotta fix my CSS for IE6, but other than that it works perfectly.

bustya
05-18-2008, 04:06 AM
Hey ZAP, I just tested it in an Iframe. First I used the URL found within the Object tag's param(s), this didn't work (I got the permission denied message). Then I tried the URL in the Embed tag (they're different BTW) and this worked. So I'd suggest using php to swap URLs in an Iframe, that is, until Tom catches on and blocks this method too. Good luck.

patinapraxis
06-01-2008, 01:32 PM
pulling the whole object from myspace still seems to work, at least on band pages.

what is possible by only pulling the url in the embed tag?

is it possible to extract the music and band photo only, and put them into a custom, restyled player, possibly with a queue? this is what i'd like to do, but i don't know flash/flex/actionscript... if i learned these, could it be done?