Results 1 to 2 of 2

Thread: torrent file parsing

  1. #1
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation torrent file parsing

    Hi all!
    Please help me finish script that would have counted the torrent file size that's what I tried to do:
    PHP Code:
    $new_torr_file_size '.$new_torr.';  //$new_torr_filename = "torrent/".$_FILES['file']['name'];
            
    if ($new_torr_file_size>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB
                
    $theDiv $theFileSize 1000000;
                
    $new_torr_file_size round($theDiv1)." MB"//round($WhatToRound, $DecimalPlaces)
            
    } else { //OTHERWISE DISPLAY AS KB
                
    $theDiv $theFileSize 1000;
                
    $new_torr_file_size round($theDiv1)." KB"//round($WhatToRound, $DecimalPlaces)
            

    Here's the script that Pars information from the file:
    PHP Code:
    require_once './BEncoder.inc.php';
    $my_tracker_url 'http://ya.ru/';
    $torr_filename 'http://torrents.thepiratebay.org/6687573/Rurouni_Kenshin_-_Artbook_(825x1200)_[JPG]_TNT_Village.6687573.TPB.torrent';
    $new_torr_filename './456.torrent';
    // Read torrent file
    $torr_data = @file_get_contents($torr_filename);
    if (
    $torr_data!==false && !empty($torr_data))
    {
        try {
            
    $encoder = new BEncoder ();
            
    // decode input torrent file
            
    $torr_array $encoder->decode ($torr_data);
            if (!isset(
    $torr_array["announce-list"]))
            {
    // if torrent dont have list, create it and add to it main announcer
                
    $torr_array["announce-list"][] = array($torr_array["announce"]);
            }
            
    // add new tracker
            
    $torr_array["announce-list"][] = array($my_tracker_url);
            
    $new_torr $encoder->encode($torr_array);
            if (!
    file_put_contents($new_torr_filename,$new_torr))
            {
                echo 
    'cant write new torrent file <b>' $new_torr_filename '</b>';
            }
        } catch (
    Exception $e) {
            echo 
    'wrong format in torrent file <b>' $torr_filename '</b>:<br /><b>'$e->getMessage() .'</b>';
        }
    }
    else
    {
        echo (
    'Cannot load file <b>' $torr_filename '</b>');

    I hope for your help!
    PS: I am from Ukraine, so sorry for my English ^_^

  2. #2
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Help connect this feature!
    PHP Code:
    function size($size$short_notation false){
        
    $kb 1024;            // Kilobyte
        
    $mb 1024 $kb;    // Megabyte
        
    $gb 1024 $mb;    // Gigabyte
        
    $tb 1024 $gb;    // Terabyte
        
        
    if($short_notation == true){
            
    $byte 'B';
            
    $kilobyte 'KB';
            
    $megabyte 'MB';
            
    $gigabyte 'GB';
            
    $terabyte 'TB';
        }
        else{
            
    $byte 'bytes';
            
    $kilobyte 'kilobyte';
            
    $megabyte 'megabyte';
            
    $gigabyte 'gigabyte';
            
    $terabyte 'terabyte';
        }
        
        if (
    $size $kb$size $size.'&nbsp;'.$byte;
        else if (
    $size $mb$size round($size/$kb,2).'&nbsp;'.$kilobyte;
        else if (
    $size $gb$size round($size/$mb,2).'&nbsp;'.$megabyte;
        else if (
    $size $tb$size round($size/$gb,2).'&nbsp;'.$gigabyte;
        else 
    $size round($size/$tb,2).'&nbsp;'.$terabyte;
        return 
    $size;


Bookmarks

Posting Permissions

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