Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 55
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts

    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

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    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

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    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

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    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
    Last edited by LJackson; 03-19-2010 at 03:33 PM.

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    anyone have any ideas as to why this is not working???

    thanks
    Luke

  • #6
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    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

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    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

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    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.

  • Users who have thanked MattF for this post:

    LJackson (03-20-2010)

  • #9
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    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
    Last edited by LJackson; 03-20-2010 at 01:30 AM.

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    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);

  • Users who have thanked MattF for this post:

    LJackson (03-20-2010)

  • #11
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    hi mate yeah that works

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

    one moment....

  • #12
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    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

  • #13
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    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
    Last edited by LJackson; 03-20-2010 at 02:04 AM.

  • #14
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    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.

  • Users who have thanked MattF for this post:

    LJackson (03-20-2010)

  • #15
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    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.


  •  
    Page 1 of 4 123 ... LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •