Aziz Saleh – Software development

  • Home
  • Downloads
    • AzizMVC Downloads
      • Database Plugin
        • Template Plugin
    • Flash Builder 4
      • Bypass, Hijack, Beat, and Defeat Same Origin Policy
      • Flash Click Tracker
      • Flash Link Hider
      • Pacman source V 1.0
    • Java Downloads
      • Currency Converter
    • Javascript Downloads
    • PHP/MySQL Downloads
      • Aziz MVC
      • AzizMVC Documentation
      • Contact Form Maker
      • NetFlix API 1.0 Wrapper
      • Simple Blog
    • Visual Basic Downloads
      • Currency Converter
        • Key Logger w/Store, email, registry options
  • Resume & Portfolio
  • Ask me a question
  • Contact Me

Posted on August 26, 2010 by Aziz Posted in PHP

This class will allow you to scrape MegaVideo Premium Links to share or use for your own.

Please note that you need to follow these steps:

1) Login into your account at MegaVideo (or MegaUpload).
2) View your cookies that you got from whichever site you loged into.
3) Replace USERNUMBER and SESSIONID with your user number and session id from the cookies in the attached file: megavideoCookie.txt.

If you do this excessively, MegaVideo will ban your IP, so you will have to renew your IP every now and then (depending on how heavy the load is).

Enjoy. Let me know if you have any problems.

Sample Implementation:

<?php
/*
MegaVideo Video Scraper
Premium Account Required
Written by Aziz S. Hussain
@
www.AzizSaleh.com
Produced under LGPL license
@
http://www.gnu.org/licenses/lgpl.html

Example Use of the class: megavideo.class.php
*/

# Include Main Class
require_once('megavideo.class.php');

# Setup the URL
$newVideo = new megaVideo('http://www.megavideo.com/?v=6PTHEVUY');
# Work to get the link
$newVideo->doScrape();
# You now have the link
echo $newVideo->getLink();
# The link can be used for download or stream
# To use for stream, you will need a flash player like JW Flash Player
# http://www.longtailvideo.com/players/jw-flv-player/

Main Class:

<?php

/*
MegaVideo Video Scraper
Premium Account Required
Written by Aziz S. Hussain
@
www.AzizSaleh.com
Produced under LGPL license
@
http://www.gnu.org/licenses/lgpl.html


Class Structure

class megaVideo
{
    # MegaVideo link
    private megaVideoURL
    # Final link
    private finalLink
    
    void __construct(string videoURL)                    # Store video link    
    array getMegaVideoVars(string megaVideoURL)            # Returns vars needed to create viewing key
    string decrypt(string str, string key1, string key2)# Actually decrypts the vars into the key
    void doScrape()                                        # Does the scraping
    string getLink()                                    # Return the URL for download or streaming        
}
*/

class megaVideo
{
    # MegaVideo link
    private $megaVideoURL;
    # Final link
    private $finalLink;
    
    # Construct, just store the vide link
    function __construct($videoURL)
    {
        $this->finalLink = $videoURL;
    }
    
    # This function will return the megaVideo vars
    # Note that it uses CURL and the COOKIE megavideoCookie.txt
    # Cookie text file must be in this format: 
    /*
    
    # Netscape HTTP Cookie File
    # http://www.netscape.com/newsref/std/cookie_spec.html
    # This file was generated by libcurl! Edit at your own risk.

    .megavideo.com    TRUE    /    FALSE    1263332544    user     4BDHJJNEJOKDF4KJHKJFJIUGHUYG3.JKLHDU4

    */
    # You need to change the user number 1263332544 and session  4BDHJJNEJOKDF4KJHKJFJIUGHUYG3.JKLHDU4
    # You can get that information by viewing the cookie information (using firefox)
    # URL passed must be in this format: http://www.megavideo.com/?v=6PTHEVUY
    function getMegaVideoVars()
    {
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$this->finalLink);
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'megavideoCookie.txt');
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'megavideoCookie.txt');
        curl_setopt($ch, CURLOPT_FAILONERROR, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 50);
    
        $buffer = curl_exec($ch);
        curl_close($ch);
        preg_match('/flashvars\.un = "(.*)";.*flashvars\.k1 = "(.*)";.*flashvars\.k2 = "(.*)";.*flashvars\.s = "(.*)";/Ums',
                $buffer,$results);
        # Return required vars
        $finalResults = array($results[4],$results[1],$results[2],$results[3]);
        return $finalResults;
    }


    # This function will decrypt the required keys form megavideo
    function decrypt($str, $key1, $key2)
    {
        $reg1 = array();
        for($reg3=0; $reg3<strlen($str); $reg3++)
        {
            $reg0 = $str[$reg3];
       
            switch($reg0)
            {
              case '0': $reg1[] = '0000'; break;
              case '1': $reg1[] = '0001'; break;
              case '2': $reg1[] = '0010'; break;
              case '3': $reg1[] = '0011'; break;
              case '4': $reg1[] = '0100'; break;
              case '5': $reg1[] = '0101'; break;
              case '6': $reg1[] = '0110'; break;
              case '7': $reg1[] = '0111'; break;
              case '8': $reg1[] = '1000'; break;
              case '9': $reg1[] = '1001'; break;
              case 'a': $reg1[] = '1010'; break;
              case 'b': $reg1[] = '1011'; break;
              case 'c': $reg1[] = '1100'; break;
              case 'd': $reg1[] = '1101'; break;
              case 'e': $reg1[] = '1110'; break;
              case 'f': $reg1[] = '1111'; break;
           }
        }
          
        $reg1 = join($reg1);
        $reg6 = array();
          
        for($reg3=0; $reg3<384; $reg3++)
        {
            $key1 = ($key1 * 11 + 77213) % 81371;
            $key2 = ($key2 * 17 + 92717) % 192811;
            $reg6[] = ($key1 + $key2) % 128;
        }
          
        for($reg3=256; $reg3>=0; $reg3--)
        {
            $reg5 = $reg6[$reg3];
            $reg4 = $reg3 % 128;
            $reg8 = $reg1[$reg5];
            $reg1[$reg5] = $reg1[$reg4];
            $reg1[$reg4] = $reg8;
        }
          
        for($reg3=0; $reg3<128; $reg3++)
        {
            $reg1[$reg3] = $reg1[$reg3] ^ ($reg6[$reg3+256] & 1);   
        }
          
        $reg12 = $reg1;
        $reg7 = array();
          
        for($reg3=0; $reg3<strlen($reg12); $reg3+=4)
        {
            $reg9 = substr($reg12, $reg3, 4);
            $reg7[] = $reg9;
        }
          
        $reg2 = array();
          
        for($reg3=0; $reg3<count($reg7); $reg3++)
        {
            $reg0 = $reg7[$reg3];
            switch($reg0)
            {
              case '0000': $reg2[] = '0'; break;
              case '0001': $reg2[] = '1'; break;
              case '0010': $reg2[] = '2'; break;
              case '0011': $reg2[] = '3'; break;
              case '0100': $reg2[] = '4'; break;
              case '0101': $reg2[] = '5'; break;
              case '0110': $reg2[] = '6'; break;
              case '0111': $reg2[] = '7'; break;
              case '1000': $reg2[] = '8'; break;
              case '1001': $reg2[] = '9'; break;
              case '1010': $reg2[] = 'a'; break;
              case '1011': $reg2[] = 'b'; break;
              case '1100': $reg2[] = 'c'; break;
              case '1101': $reg2[] = 'd'; break;
              case '1110': $reg2[] = 'e'; break;
              case '1111': $reg2[] = 'f'; break;
            }
        }
        return join($reg2);
    }
    
    # Actually return the URL that the video can be viewed without time restrictions
    function doScrape()
    {
        # Retrieve info
        list($serverID,$un,$k1,$k2) = $this->getMegaVideoVars();
        # Get the key
        $decKey = $this->decrypt($un,$k1,$k2);
        
        $this->finalLink = "http://www$serverID.megavideo.com/files/$decKey/randomName$un.flv";
    }
    
    # Return the link begotten after scraping
    function getLink()
    {
        return $this->finalLink;
    }    

}

Cookie File:

# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
# MegaVideo Premium Link Scraper by Aziz S. Hussain
# @ www.AzizSaleh.com


.megavideo.com    TRUE    /    FALSE    USERNUMBER    user     USERSESSION

« Content Extraction using Preg match
Currency Converter Using Java Netbeans »

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • PHP does not have MySQL support enabled.
  • Your PHP installation appears to be missing the MySQL extension which is required by WordPress
  • Undefined mysql functions (mysql_connect, mysql_select_db, mysql_query) – PDO alternative
  • Checking if you have Javascript installed by PHP
  • Process Maxmind countries, regions and cities – Parser to MySQL or SqLite

Recent Comments

  • fathima on Currency Converter Using Java Netbeans
  • Chris on Currency Converter
  • Khalid Ahmad Qweder on Resume & Portfolio
  • Michel on Currency Converter
  • Michel on Currency Converter

Archives

  • March 2014
  • September 2013
  • November 2012
  • October 2012
  • November 2011
  • February 2011
  • December 2010
  • November 2010
  • August 2010
  • May 2010
  • September 2009

Categories

  • Flash Builder 4
  • General
  • Java
  • Javascript
  • MySQL
  • PHP
  • Visual Basic

Meta

  • Register
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
CyberChimps ©2023