Jump to content

Recommended Posts

What I am doing is creating a simple page to use with Megashares.com .... if you have a valid account on Megashares and are logged in you can browse to http://d01.megashares.com/?d01=be86c04 for example and you are presented with a link that says Click Here to Download. Well, instead of going through all that, I wanted to create a script that parsed that page to grab the AVI link and paste it directly into the in browser DIVX Player because it starts streaming immediately. Neat huh? I think so...

 

The below code works, but since cURL is run from the server side, its logging in and grabbing a link that can only be access by the server... I need to find an alternative method for allowing me, the client to log into Megashares.com and then grab the contents of the chosen URL to parse for the link directly pointing to the AVI file using the regex below...

 

Suggestions?

 

 

<?php

//Requested URL
$urlmega = $_REQUEST['urlmega']; // Not direct path to AVI
$urlmega2 = $_REQUEST['urlmega2']; // Direct path to AVI
//Login Info
$email = "user@email.com";
$password = "yourpassword";


// If Megashares link submitted AND Direct Link to AVI NOT submitted... login to megashares and get direct AVI link
if ($urlmega != '' && $urlmega2 == '')
{
     // CURL METHOD
     $curlPost = "lc_email=".urlencode($email)."&lc_pin=".urlencode($password)."&lc_signin=Sign-In";
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $urlmega);
     curl_setopt($ch, CURLOPT_HEADER, 1);
 curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10');
     curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); // Use cookie.txt for STORING cookies
     curl_setopt($ch, CURLOPT_POST, true); // Tell curl that we are posting data
     curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
     $output = curl_exec($ch); // Execute!
     //echo $output; // Spit out what we found
     curl_close($ch); // Free the memory
} 

// Load THIS page on first load, this means urlmega or urlmega2 has not been defined....
elseif ($urlmega == '' && $urlmega2 == '')
{
    echo '
<h3>This form will parse, authenticate and play valid Megashares.com links...</h3>
    Example : http://d01.megashares.com/?d01=be86c04
    <div class="box2">
      <form name="form" action="megashares.php" method="post">
        <input type="text" name="urlmega" size="65"/ value="http://d01.megashares.com/?d01=be86c04">
	<br />
	Or you can enter a direct link to any URL and attempt to play it with DIVX in browser player.<br />
	<input type="text" name="urlmega2" size="65"/ value="">
          
        <input type="submit" name="Submit" value="Roll the Dice" class="button"/>
      </form>';
}
// End Megashares Login

// PARSE MEGASHARES URL FOR DOWNLOAD LINK if cURL has ran and $output has contents
if ($output != '')
{
    // This REGEX will grab the direct link to the AVI through the pages source
    $regexp = "%http[^\" >]*?\\webprod(.*).avi%";

    if (preg_match_all($regexp, $output, $matches, PREG_SET_ORDER))
    {

        foreach ($matches as $match)
        {
            $match = $match[0]; // $match is now a direct AVI link

            // echo $match."<br />";

        }
    }
}

// END PARSE MEGASHARES URL FOR DOWNLOAD LINK

if ($match != '')
{
    // PLAYER EMBED
    echo "<object classid='clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616' width='512' height='384' codebase='http://go.divx.com/plugin/DivXBrowserPlugin.cab'>".
    "<param name='custommode' value='none' />".
    "<param name='src' value='".$match."' />".
    "<embed type='video/divx' src='".$match."' custommode='none' width='512' height='384' pluginspage='http://go.divx.com/plugin/download/'>".
    "</embed></object>".
    "<br>No video? Get the DivX Web Player for <a style='text-decoration: underline;' href='http://download.divx.com/player/DivXWebPlayerInstaller.exe'>Windows</a> or <a style='text-decoration: underline;' href='http://download.divx.com/player/DivXWebPlayer.dmg'>Mac</a>";
    echo '<br />Attemping to play the following URL :<br />';
    echo $match."<br />";
    // END PLAYER EMBED
} 
if ($urlmega2 != '')
{
    // PLAYER EMBED FOR DIRECT AVI LINK
    echo "<object classid='clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616' width='512' height='384' codebase='http://go.divx.com/plugin/DivXBrowserPlugin.cab'>".
    "<param name='custommode' value='none' />".
    "<param name='src' value='".$urlmega2."' />".
    "<embed type='video/divx' src='".$urlmega2."' custommode='none' width='512' height='384' pluginspage='http://go.divx.com/plugin/download/'>".
    "</embed></object>".
    "<br>No video? Get the DivX Web Player for <a style='text-decoration: underline;' href='http://download.divx.com/player/DivXWebPlayerInstaller.exe'>Windows</a> or <a style='text-decoration: underline;' href='http://download.divx.com/player/DivXWebPlayer.dmg'>Mac</a>";
    // END PLAYER EMBED
}
?>

Link to comment
https://forums.phpfreaks.com/topic/159782-need-options-on-alternitive-to-curl/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.