scene.releases.free.fr data parser

Status
Not open for further replies.

sqider

Member
8
2012
3
0
So i wrote this simple parser like a month ago and since i have a better method to get information with even higher quality i want to share my small script i used to parse the data with.

I'm not a blackhat and i am not interested in piracy, so dont think bad of me.

Feel free to complain, this version is old and wont ever ever be changed (by me)
Feel free to change the script.
Feel free to use it as you like.
If you use it for non-moral things, dont forget to feel bad.

I am not responsible for any damage.

Run as root or choose the right wisely.

parser_php.png


PHP:
<?php
/*
run as root or choose right wisely
*/
error_reporting(E_ALL);
ini_set('display_errors','1');
$start = microtime(true);

$NDSParser = new NDSParser();
//print_r($NDSParser);

class NDSParser {
    public $limit = 0;
    public $img_dir = 'img/';
    public $nfo_dir = 'nfo/';
    public $data_dir = 'data/';
    public $sys_arr = array('dsi','3ds','nds');
    public $url_3ds = 'http://scene.releases.free.fr/index.php?page=list&p=3ds&g=';
    public $url_nds = 'http://scene.releases.free.fr/index.php?page=list&p=nds&g=';
    public $url_dsi = 'http://scene.releases.free.fr/index.php?page=list&p=dsi&g=';
    public $current_sys = '';

    public function __construct() {
        $this->init();
        $this->process();
    }
    public function init() {
        foreach ($this->sys_arr as $sys) if (!is_dir($sys)) mkdir($sys);
        foreach ($this->sys_arr as $sys) if (!is_dir($sys.'/'.$this->img_dir)) mkdir($sys.'/'.$this->img_dir);
        foreach ($this->sys_arr as $sys) if (!is_dir($sys.'/'.$this->nfo_dir)) mkdir($sys.'/'.$this->nfo_dir);
        foreach ($this->sys_arr as $sys) if (!is_dir($sys.'/'.$this->data_dir)) mkdir($sys.'/'.$this->data_dir);
    }
    public function process() {
        foreach($this->sys_arr as $sys) {
            $this->current_sys = $sys;
            $this->getInformation();
        }
    }
    public function getInformation() {
        $build_url = 'url_'.$this->current_sys;
        $url = $this->$build_url;
        $dom = new DOMDocument();
        $skip = 0;
        $pID = $this->getPID();
        echo '___'.strtoupper($this->current_sys)."___\n";
        while ($skip != 3) {
            $number = str_pad($pID, 4, "0", STR_PAD_LEFT);
            $content = file_get_contents($url.$pID);
            error_reporting(E_ALL & ~E_WARNING);
            $dom->loadHTML($content);
            error_reporting(E_ALL);
            $xml = simplexml_import_dom($dom);

            $ava = $xml->xpath('/html/body/div[2]/div[2]/table/tr[2]/td[2]/div[2]/table');
            if (!empty($ava)) {
                $skip = 0;
                echo "\n -> Processing: [$number] <- \n";
                $rls_left = $xml->xpath('/html/body/div/div/table/tr/td/div/table/tr/td/b');
                $rls_right = $xml->xpath('/html/body/div/div/table/tr/td/div/table/tr/td[2]');
                //print_r($rls_left);die;
                $format_data = '';
                for($x=0;$x < count($rls_left)-1;$x++) {
                    $format_data .= "##".trim(str_replace(':','',$rls_left[$x]))."##".trim($rls_right[($x+1)])."\n";
                }
                $rls_dir = trim($rls_right[12]);
                
                if (isset($rls_dir)) $this->current_rls = str_replace('\\','',$rls_dir);
                else $this->current_rls = $number;

                $this->setInfo($number,$format_data);
                $this->getMainImage($number);
                $this->getNFO($number);
                $this->setPID($pID+1);
            } else {
                $this->warning("$number not available");
                $skip++;
            }
            if ($pID == $this->limit) {
                $this->warning("Limit reached");
                break;
            }
            $pID++;
            
            //$this->error("testmode");
        }
    }
    public function getPID() {
                $file = $this->current_sys.'/limit.txt';
                if (file_exists($file)) {
                        $num =  trim(file_get_contents($file));
                        return $num;
                } else {
                        file_put_contents($file,'1');
                        return 1;
                }
        }
        public function setPID($pID) {
                $file = $this->current_sys.'/limit.txt';
                $put = file_put_contents($file,$pID);
                if ($put) return true;
        }
    public function getMainImage($num) {
        $filename = $this->current_rls;
        $full_path = $this->current_sys.'/'.$this->img_dir.$filename;
        $img = 'http://scene.releases.free.fr/box/'.$this->current_sys.'-'.$num;
        
        $search = glob($full_path.'*');
        if (empty($search)) {
            $extension = array(
                'jpg' => '.jpg',
                'png' => '.png',
                'gif' => '.gif',
                'jpeg' => '.jpg'
            );
            foreach ($extension as $key => $exy) {
                if ($img_get = file_get_contents($img.$exy)) {
                        file_put_contents($full_path.$exy,$img_get);
                        echo '->'.$filename.$exy." saved \n";
                        break;
                }
            }
        }
    }
    public function getNFO ($num) {
        $full_path = $this->current_sys . '/' . $this->nfo_dir . $this->current_rls . '.nfo';
        if (!file_exists($full_path)) {
            file_put_contents($full_path,file_get_contents('http://scene.releases.free.fr/dl_nfo.php?s=' . $this->current_sys . '&g=' . $num));
            echo '---->'.$this->current_rls. ".nfo saved \n";
        }
    }
    public function setInfo($num,$data) {
        if (!file_exists($this->current_sys . '/' . $this->data_dir . $this->current_rls . '.txt')) {
            $full_path = $this->current_sys . '/' . $this->data_dir . $this->current_rls . '.txt';
            if (!empty($data)) file_put_contents($full_path,$data);
            echo "\n ---> $this->current_rls <---\n";
        }
    }
    function warning($msg) {
        if (!isset($this->warning)) $this->warning = array();
        $this->warning[] = $msg;
        echo $msg."\n";
    }
    function error($error = 'Unexpected Error') {
        die("\n ---> ".trim($error)." <---\n");
    }
}
$end = microtime(true)-$start;
echo "\n ---> Time: $end Sec. <---\n";
?>

If not allowed, feel free to delete and if you dont mind PM me afterwards.
 
3 comments
this script gets all the information for dsi,nds and 3ds from the scene.releases.free.fr site.

it gets all the information, the boxart and the nfo
 
Status
Not open for further replies.
Back
Top