Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-19-2010, 02:36 PM   PM User | #1
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
Exclamation curl advice please?

Hi

I have a list of products which i am displaying on my site and im using an API to get the data like title, url, image etc but what i am trying to achieve is to get the trailers from the provided urls so for example

if i had the following url
http://www.play.com/DVD/DVD/4-/-/-/P...23&source=9593

would it be possible to extract the trailer link and store it in a db table? and as i would be doing this with several products from play.com hopefully the taga would be the same so should be quite straight forward? and then display the trailer on a webpage on my site? would i need plays permission? im advertising play.com product through an affiliate agreement.

is there another way of doing this?

any help is appreciated
thanks
Luke
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
LJackson is offline   Reply With Quote
Old 03-19-2010, 02:46 PM   PM User | #2
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
ok i have looked around and i have come up with this

PHP Code:
<?php

$curl_handle
=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://www.play.com/DVD/DVD/4-/-/-/Product.html?title=10674623&source=9593');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer curl_exec($curl_handle);
curl_close($curl_handle);

if (empty(
$buffer))
{
    print 
"Error.<p>";
}
else
{
    print 
$buffer;
}
?>
which when run loads up my example link which is great!

but now im not sure where to go from here to get just the trailer?

any help please
thanks
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
LJackson is offline   Reply With Quote
Old 03-19-2010, 02:59 PM   PM User | #3
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
the video is within this code on there page
PHP Code:
<div class="special slice"><ul><li><br><center><object type="application/x-shockwave-flash" width="403" height="298" id="playVideoPlayer" wmode="transparent" data="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/10674623.flv&vol=0.5&packShot=http://images.play.com/covers/10674623m.jpg" allowScriptAccess="always"><param name="movie" value="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/10674623.flv&vol=0.5&packShot=http://images.play.com/covers/10674623m.jpg" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="always" /><embed name="playVideoPlayer" src="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/10674623.flv&vol=0.5&packShot=http://images.play.com/covers/10674623m.jpg" loop="false" width="403" height="298" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object></center><br><br></li><liBehind the Scenes</li><liInterviews with Cast and Crew</li></ul></div
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
LJackson is offline   Reply With Quote
Old 03-19-2010, 03:27 PM   PM User | #4
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
ok i now have this
PHP Code:
<?php
include("dbinfo.php");

function 
storeLink($url,$gathered_from) {
    
$query "INSERT INTO links (url, gathered_from) VALUES ('$url', '$gathered_from')";
    
mysql_query($query) or die('Error, insert query failed');
}

$target_url "http://www.play.com/DVD/DVD/4-/-/-/Product.html?title=10674623&source=9593";
$userAgent 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';

// make the cURL request to $target_url
$ch curl_init();
curl_setopt($chCURLOPT_USERAGENT$userAgent);
curl_setopt($chCURLOPT_URL,$target_url);
curl_setopt($chCURLOPT_FAILONERRORtrue);
#curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($chCURLOPT_AUTOREFERERtrue);
curl_setopt($chCURLOPT_RETURNTRANSFER,true);
curl_setopt($chCURLOPT_TIMEOUT10);
$htmlcurl_exec($ch);
if (!
$html) {
    echo 
"<br />cURL error number:" .curl_errno($ch);
    echo 
"<br />cURL error:" curl_error($ch);
    exit;
}

// parse the html into a DOMDocument
$dom = new DOMDocument();
@
$dom->loadHTML($html);

// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs $xpath->evaluate("/html/body/center//object");

for (
$i 0$i $hrefs->length$i++) {
    
$href $hrefs->item($i);
    
$url $href->getAttribute('href');
    
storeLink($url,$target_url);
    echo 
"<br />Link stored: $url";
}
?>
but this throws up an error on this line
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

which is why ive commented it out, but it does not insert anything into the db???

the error it throws out is

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set on line 17

any ideas
thanks
Luke
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook

Last edited by LJackson; 03-19-2010 at 03:33 PM..
LJackson is offline   Reply With Quote
Old 03-20-2010, 12:58 AM   PM User | #5
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
anyone have any ideas as to why this is not working???

thanks
Luke
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
LJackson is offline   Reply With Quote
Old 03-20-2010, 01:14 AM   PM User | #6
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
Are you just wanting to embed the video or actually download the flv file? This part of the link contains the name/id of the flv file, btw.

title=10674623
MattF is offline   Reply With Quote
Old 03-20-2010, 01:17 AM   PM User | #7
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
hi mate i want the code to embed it in to my site, i will take the object code and add it to my db table and then call that code to show the video on my site. just not sure where im going wrong with the curl, only just started using it today

thanks
Luke
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
LJackson is offline   Reply With Quote
Old 03-20-2010, 01:21 AM   PM User | #8
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
This will give you the link to the flv file:

Code:
$uri = 'http://www.play.com/DVD/DVD/4-/-/-/Product.html?title=10674623&source=9593';
preg_match('#title\=(\d+?)\&#', $uri, $match);
$link = 'http://media.play.com/ProductPage_Trailers/Films/'.$match[1].'.flv';
Just alter the $link var to contain the object code. You have the file id/name. No need for using curl or suchlike.

Last edited by MattF; 03-20-2010 at 01:23 AM..
MattF is offline   Reply With Quote
Users who have thanked MattF for this post:
LJackson (03-20-2010)
Old 03-20-2010, 01:25 AM   PM User | #9
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
hi mate thanks for your reply,

firstly would this work with more than one url from the same website play.com for example if i wanted another video of another dvd would this work for it?

and secondly how does one show the video on my site?

sorry havent got a clue
thanks
Luke

p.s this is the code i was referring to
Code:
<object type="application/x-shockwave-flash" width="403" height="298" id="playVideoPlayer" wmode="transparent" data="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/10674623.flv&vol=0.5&packShot=http://images.play.com/covers/10674623m.jpg" allowScriptAccess="always"><param name="movie" value="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/10674623.flv&vol=0.5&packShot=http://images.play.com/covers/10674623m.jpg" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="always" /><embed name="playVideoPlayer" src="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/10674623.flv&vol=0.5&packShot=http://images.play.com/covers/10674623m.jpg" loop="false" width="403" height="298" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>
which when pasting in to a php page it displays the related video

cheers
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook

Last edited by LJackson; 03-20-2010 at 01:30 AM..
LJackson is offline   Reply With Quote
Old 03-20-2010, 01:31 AM   PM User | #10
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
Try this on your testpage:

Code:
$uri = 'http://www.play.com/DVD/DVD/4-/-/-/Product.html?title=10674623&source=9593';
preg_match('#title\=(\d+?)\&#', $uri, $match);
$link = '<object type="application/x-shockwave-flash" width="403" height="298" id="playVideoPlayer" wmode="transparent" data="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/'.$match[1].'.flv&vol=0.5&packShot=http://images.play.com/covers/'.$match[1].'m.jpg" allowScriptAccess="always"><param name="movie" value="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/'.$match[1].'.flv&vol=0.5&packShot=http://images.play.com/covers/'.$match[1].'m.jpg" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="always" /><embed name="playVideoPlayer" src="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/'.$match[1].'.flv&vol=0.5&packShot=http://images.play.com/covers/'.$match[1].'m.jpg" loop="false" width="403" height="298" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/></object>';

print($link);
MattF is offline   Reply With Quote
Users who have thanked MattF for this post:
LJackson (03-20-2010)
Old 03-20-2010, 01:36 AM   PM User | #11
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
hi mate yeah that works

loads the video fine, will try it with another product?

one moment....
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
LJackson is offline   Reply With Quote
Old 03-20-2010, 01:45 AM   PM User | #12
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
ok using this url
http://www.play.com/DVD/Blu-ray/4-/-...33&source=9593

it loads the player and images but wont play the video when you click on the play button? there are no errors or anything like that?

which is a bit strange.
cheers
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
LJackson is offline   Reply With Quote
Old 03-20-2010, 02:02 AM   PM User | #13
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
it seems to work with other dvds but not other categories and the ony thing i can see that is different in the url is

PHP Code:
http://www.play.com/DVD/Blu-ray/4-/-/-/Product.html?title=12090170&source=9593
http://www.play.com/DVD/DVD/4-/-/-/Product.html?title=10853630&source=9593 
this bit /DVD/Blu-ray/ which seems to show the categoy of the product, would that break your preg_match? bearing in mind the firsh category could be Games as well

cheers mate
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook

Last edited by LJackson; 03-20-2010 at 02:04 AM..
LJackson is offline   Reply With Quote
Old 03-20-2010, 02:02 AM   PM User | #14
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
Try this:

Code:
$uri = 'http://www.play.com/DVD/Blu-ray/4-/-/-/Product.html?title=12089933&source=9593';
$input = file_get_contents($uri);

if (preg_match('#/Films/(\w+?)\.flv\&#', $input, $match))
{
    $link = '<object type="application/x-shockwave-flash" width="403" height="298" id="playVideoPlayer" wmode="transparent" data="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/'.$match[1].'.flv&vol=0.5&packShot=http://images.play.com/covers/'.$match[1].'m.jpg" allowScriptAccess="always"><param name="movie" value="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/'.$match[1].'.flv&vol=0.5&packShot=http://images.play.com/covers/'.$match[1].'m.jpg" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="always" /><embed name="playVideoPlayer" src="http://media.play.com/trailers/videoPlayer.swf?file=http://media.play.com/ProductPage_Trailers/Films/'.$match[1].'.flv&vol=0.5&packShot=http://images.play.com/covers/'.$match[1].'m.jpg" loop="false" width="403" height="298" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/></object>';

    print($link);
}

Last edited by MattF; 03-20-2010 at 02:13 AM..
MattF is offline   Reply With Quote
Users who have thanked MattF for this post:
LJackson (03-20-2010)
Old 03-20-2010, 02:05 AM   PM User | #15
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
Quote:
Originally Posted by LJackson View Post
it seems to work with other dvds but not other categories and the ony thing i can see that is different in the url is
There are some discrepancies between some of the links and some of the filenames. That code I've posted above will actually parse the page itself, so should hopefully work across the board.
MattF is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:28 PM.


Advertisement
Log in to turn off these ads.