View Single Post
  #1  
Old 21st October 2009, 01:50
joeroberts's Avatar
joeroberts joeroberts is offline
BT.Manager Owner
 
Join Date: Jan 2008
United States
Posts: 2,113
Default Import TBdev & TT torrents to phpMyBitTorrent
Here is a add-on for user import which together they can help you convert Most TBdev and alike source to phpMyBitTorrent.

To Use just upload to your PMBT root and edit [$oldupload = "oldt";//edit to your old upload file] to old upload folder and call to the page

Down side is you may have to run it a couple times but if every thing goes as it should it well import torrents nfo and comments and add them all to your new source.

PHP Code:
<?php
/*
*----------------------------phpMyBitTorrent V 2.0.4---------------------------*
*--- The Ultimate BitTorrent Tracker and BMS (Bittorrent Management System) ---*
*--------------   Created By Antonio Anzivino (aka DJ Echelon)   --------------*
*-------------------   And Joe Robertson (aka joeroberts)   -------------------*
*-------------               http://www.p2pmania.it               -------------*
*------------ Based on the Bit Torrent Protocol made by Bram Cohen ------------*
*-------------              http://www.bittorrent.com             -------------*
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
*--   This program is free software; you can redistribute it and/or modify   --*
*--   it under the terms of the GNU General Public License as published by   --*
*--   the Free Software Foundation; either version 2 of the License, or      --*
*--   (at your option) any later version.                                    --*
*--                                                                          --*
*--   This program is distributed in the hope that it will be useful,        --*
*--   but WITHOUT ANY WARRANTY; without even the implied warranty of         --*
*--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          --*
*--   GNU General Public License for more details.                           --*
*--                                                                          --*
*--   You should have received a copy of the GNU General Public License      --*
*--   along with this program; if not, write to the Free Software            --*
*-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA --*
*--                                                                          --*
*------------------------------------------------------------------------------*
*------              ©2010 phpMyBitTorrent Development Team              ------*
*-----------               http://phpmybittorrent.com               -----------*
*------------------------------------------------------------------------------*
*--------------------   Sunday, Oct 20, 2009 1:05 AM   ------------------------*
*/

$oldupload "oldones";//edit to your old upload file
@set_time_limit(20);
@
ini_set("memory_limit","64M");
if (
defined('IN_PMBT'))die ("You can't include this file");
define('IN_PMBT'true);
include(
'header.php');
require_once(
"include/bdecoder.php");
require_once(
"include/bencoder.php");
//die($announce_url);
$sql "SELECT * FROM torrents ORDER BY `id` ASC;";
$res $db->sql_query($sql)or btsqlerror($sql);
while(
$row $db->sql_fetchrow($res)){
//echo $row['id']."<br>";
if (file_exists("torrent/".$row['id'].".torrent"))continue;
echo 
$row['id']."<br>";
$pagetorrent "";
$fp = @fopen($oldupload."/".$row['id'].".torrent","rb");
echo 
"checking torrent <br>";
if(!
$fp) echo "No Torrent File here<br>";
else
echo 
"Torrent is here<br>";
if(!
$fp)continue;
while (!@
feof($fp)) {
        
$pagetorrent .= @fread($fp,1000);
}
@
fclose($fp);
unset(
$fp);

$md5file $oldupload."/".$row['id'].".torrent";
//echo $row['id'];
//die;
//Decode
$nfopath $oldupload."/".$row['id'].".nfo";
if (
file_exists($nfopath)) rename($nfopath"torrent/".$row['id'].".nfo");
$info ='';
$infohash '';
$torrent Bdecode($pagetorrent);
$info entry_get($torrent,"info");
#Parsing files
$filelist = array();
if (
entry_exists($torrent,"info/length(Integer)")) {
        
//Single file
        
$totallen entry_read($torrent,"info/length(Integer)");

        if (
entry_exists($torrent,"info/sha1(String)")) {
                
$sha1code entry_read($torrent"info/sha1(String)");
                
$magnet_link "magnet:?xt=urn:sha1:".addslashes(hex_to_base32($sha1code))."&dn=".urlencode($dname);
        } else {
                
$magnet_link "";
        }
        if (
entry_exists($torrent,"info/ed2k(String)")) {
                
$ed2k entry_read($torrent"info/ed2k(String)");
                
$ed2k_link "ed2k://|file|".urlencode($dname)."|".$totallen."|".strtoupper(str_pad($ed2k,32,"0"))."|/";
        } else {
                
$ed2k_link "";
        }
        
$filelist[] = array($dname$totallen$magnet_link$ed2k_link);
        
$type "single";
} else {
        
//Multiple files
        
$flist entry_read($torrent"info/files(List)");
        if (!isset(
$flist))
                
bterror(_btmissinglength,_btuploaderror);
        if (!
count($flist))
                
bterror(_btnofilesintorrent,_btuplaoderror);
        
#$totallen = 0;
        
foreach ($flist as $fn) {
                
$ffe "";
                
$magnet_link "";
                
$ed2k_link "";
                
$children $fn->child_nodes();
                
$file = array();
                foreach (
$children as $child) {
                        
$file[$child->tagname] = $child;
                }

                if (!
array_key_exists("length",$file) OR !array_key_exists("path",$file)) bterror("test5",_btuploaderror);

                
$ll $file["length"]->get_content();

                
$path = array();
                foreach (
$file["path"]->child_nodes() as $parray_push($path,$p->get_content());
                
$ffe implode("/",$path);
                if (empty(
$ffe)) bterror(_btfilenamerror,_btuploaderror);

                if (
array_key_exists("sha1",$file)) {
                        
$magnet_link "magnet:?xt=urn:sha1:".addslashes(hex_to_base32($file["sha1"]->get_content()))."&dn=".urlencode($path[count($path)-1]);
                }
                if (
array_key_exists("ed2k",$file)) {
                        
$ed2k_link "ed2k://|file|".urlencode($path[count($path)-1])."|".$ll."|".strtoupper(str_pad($file["ed2k"]->get_content(),32,0))."|/";
                }
                unset(
$p$path);

                
$filelist[] = array($ffe$ll$magnet_link$ed2k_link);
                
$totallen += $ll;
        }
        
$type "multi";
}
$infohash_hex sha1(Benc($info));
$infohash pack("H*"$infohash_hex);
unset(
$info);
$dht "no";
if (
entry_exists($torrent,"azureus_properties/dht_backup_enable(Integer)")) {
        if (
entry_read($torrent,"azureus_properties/dht_backup_enable(Integer)") != 0$dht "yes";
}
$announce entry_read($torrent,"announce(String)");
$info_intact true;
#Name, piece length and pieces

if (!entry_exists($torrent,"info/piece length(Integer)")) bterror("test3",_btuploaderror);
if (!
entry_exists($torrent,"info/pieces(String)")) bterror("test4",_btuploaderror);
$dname = (entry_exists($torrent,"info/name(String)")) ? $dname entry_read($torrent,"info/name(String)") : "";
$plen entry_read($torrent,"info/piece length(Integer)");
$pieces entry_read($torrent,"info/pieces(String)");

if (
strlen($pieces) % 20 != 0)
        
bterror(_btinvpieces,_btuploaderror);
unset(
$pieces);

$tcomment = (entry_exists($torrent,"comment(String)")) ? entry_read($torrent,"comment(String)") : "";
#Parsing Announce
$annregexp_http "/(http[s]?+):\/\/[-\/.:_\\w]*\/announce[^\/\\s]*/i";
$annregexp_dht "/^dht:\/\/[0-9a-f]*.dht\/announce$/i";
$annregexp_udp "/udp:\/\/[-\/.:_\\w]*\/announce[^\/\\s]*/i";
if (
$announce == $announce_url) {
        if (
$stealthmodebterror(str_replace("**name**",$sitename,_bttrackerdisabled),_btuploaderror);
        
$announce "";
} elseif (
preg_match($annregexp_http$announce)) {
        
$sql "SELECT id FROM ".$db_prefix."_trackers WHERE url = '".addslashes($announce)."' AND status = 'blacklisted' LIMIT 1;";
        
$res $db->sql_query($sql);
        if (
$db->sql_numrows($res) > 0bterror(str_replace("**trk**",$announce,_bttrackerblacklisted),_btuploaderror);
        
$db->sql_freeresult($res);
} elseif (
preg_match($annregexp_dht,$announce)) {
        
$dht "yes";
} else {
        
bterror(_btinvannounce."<b>".$announce."</b>",_btuploaderror);
}
//UDP trackers or trackers inside the TOR/I2P networks are not supported *yet*
$trackers "NULL";
$backup_tracker "false";
if (
entry_exists($torrent,"announce-list(List)")) {
        
$trackers = Array();
        
$to_check = Array();
        
$announce_list entry_read($torrent,"announce-list(List)");
        foreach (
$announce_list as $group) {
                
$trackers_in_group = Array();
                foreach (
$group->child_nodes() as $tracker_node) {
                        
$tracker $tracker_node->get_content();
                        if (!
preg_match($annregexp_http,$tracker) AND !preg_match($annregexp_udp,$tracker)) bterror(_btinvannounce."<b>".$tracker."</b>",_btuploaderror);
                        
//If the main tracker is NOT this one, but this one APPEARS within the Announce list then we're running backup tracker
                        
if ($tracker["value"] == $announce_url AND $announce != ""$backup_tracker "true";
                        
array_push($trackers_in_group,$tracker);
                        
array_push($to_check,"'".$tracker."'");
                        unset(
$tracker$tracker_node);
                }
                
array_push($trackers,$trackers_in_group);
                unset(
$trackers_in_group$group);

        }
        unset(
$sql$to_check,$announce_list$res2);
        for (
$i 0$i count($trackers); $i++) $trackers[$i] = implode("\n",$trackers[$i]);
        
$trackers "'".addslashes(implode("\n\n",$trackers))."'";
}
#Checking against the SAME Torrent
$jump_check false;
if (
$jump_check ) {
$sql "SELECT id FROM ".$db_prefix."_torrents WHERE info_hash = '".addslashes($infohash)."';";
$res2 $db->sql_query($sql) or btsqlerror($sql);
if (
$db->sql_numrows($res2) > 0) {
continue;
}
$db->sql_freeresult($res2);
}
$password "NULL";
$searchtext "".$row['filename']." "$row['filename']." "$row['descr']." ";
#Preparing SQL
$torrentfields = Array();
$torrentvalues = Array();

$torrentfields[] = "id";
$torrentvalues[] = "'".$row['id']."'";

$torrentfields[] = "info_hash";
$torrentvalues[] = "'".addslashes($infohash)."'";

$torrentfields[] = "name";
$torrentvalues[] = "'".addslashes($row['name'])."'";

$torrentfields[] = "filename";
$torrentvalues[] = "'".addslashes($row['filename'])."'";

$torrentfields[] = "save_as";
$torrentvalues[] = "'".addslashes($row['save_as'])."'";

$torrentfields[] = "md5sum";
$torrentvalues[] = "'".md5_file($md5file)."'";

$torrentfields[] = "search_text";
$torrentvalues[] = "'".addslashes($row['filename'])."'";

$torrentfields[] = "descr";
$torrentvalues[] = "'".addslashes($row['descr'])."'";

$torrentfields[] = "added";
$torrentvalues[] = "'".$row['added']."'";

$torrentfields[] = "size";
$torrentvalues[] = "'".$row['size']."'";

$torrentfields[] = "ratiobuild";
$torrentvalues[] = "'".$row['free']."'";

$torrentfields[] = "plen";
$torrentvalues[] = "'".entry_read($torrent,"info/piece length(Integer)")."'";

$torrentfields[] = "category";
$torrentvalues[] = "'".$row['free']."'";

$torrentfields[] = "type";
$torrentvalues[] = "'".$row['type']."'";

$torrentfields[] = "numfiles";
$torrentvalues[] = "'".$row['numfiles']."'";

$torrentfields[] = "exeem";
$torrentvalues[] = "NULL";

$torrentfields[] = "dht";
$torrentvalues[] = "'".$dht."'";

$torrentfields[] = "backup_tracker";
$torrentvalues[] = "'".$backup_tracker."'";

$torrentfields[] = "views";
$torrentvalues[] = "'".$row['views']."'";

$torrentfields[] = "downloaded";
$torrentvalues[] = "'".$row['hits']."'";

$torrentfields[] = "completed";
$torrentvalues[] = "'".$row['times_completed']."'";

$torrentfields[] = "banned";
$torrentvalues[] = "'".$row['banned']."'";

$torrentfields[] = "password";
$torrentvalues[] = $password;

$torrentfields[] = "visible";
$torrentvalues[] = "'".$row['visible']."'";

$torrentfields[] = "evidence";
$torrentvalues[] = "'0'";

$torrentfields[] = "owner";
$torrentvalues[] = "'".$row['owner']."'";

$torrentfields[] = "ownertype";
$torrentvalues[] = "'0'";

$torrentfields[] = "uploader_host";
$torrentvalues[] = "'0'";

$torrentfields[] = "numratings";
$torrentvalues[] = "'0'";

$torrentfields[] = "ratingsum";
$torrentvalues[] = "'0'";

$torrentfields[] = "seeders";
$torrentvalues[] = "'".$row['seeders']."'";

$torrentfields[] = "leechers";
$torrentvalues[] = "'".$row['leechers']."'";

$torrentfields[] = "tot_peer";
$torrentvalues[] = "'".intval($row['seeders']+$row['leechers'])."'";

$torrentfields[] = "speed";
$torrentvalues[] = "'0'";

$torrentfields[] = "comments";
$torrentvalues[] = "'".$row['comments']."'";

$torrentfields[] = "complaints";
$torrentvalues[] = "'0,0'";

$torrentfields[] = "tracker";
if (
$announce == ""$torrentvalues[] = "NULL";
else 
$torrentvalues[] = "'".$announce."'";

$torrentfields[] = "tracker_list";
$torrentvalues[] = $trackers;

$torrentfields[] = "tracker_update";
$torrentvalues[] = "NOW()";

$torrentfields[] = "last_action";
$torrentvalues[] = "NOW()";

$torrentfields[] = "imdb";
$torrentvalues[] = "'".$row['imdb']."'";

$torrentsql "INSERT INTO ".$db_prefix."_torrents (".implode(", ",$torrentfields).") VALUES (".implode(", ",$torrentvalues).");";
$db->sql_query($torrentsql) or btsqlerror($torrentsql);
if (
$announce != ""){ 
$db->sql_query("INSERT INTO ".$db_prefix."_trackers (url, updated) VALUES ('".addslashes($announce)."', NOW());");
}
foreach (
$filelist as $file) {
        list (
$fname$fsize$magnet$ed2k) = $file;
        
$fields "(torrent, filename, size";
        
$values "('".$row['id']."', '".str_replace("'","\'",$fname)."', '".$fsize."'";
        if (
$magnet != "") {
                
$fields.= ", magnet";
                
$values.= ", '".addslashes($magnet)."'";
        }
        if (
$ed2k != "") {
                
$fields.= ", ed2k";
                
$values.= ", '".addslashes($ed2k)."'";
        }
        
$fields.= ")";
        
$values.= ")";
        
$filesql "INSERT INTO ".$db_prefix."_files ".$fields." VALUES ".$values.";";
        if (!
$db->sql_query($filesql)) { //Rollback
                
$db->sql_query("DELETE FROM ".$db_prefix."_torrents WHERE id = '".$row['id']."' LIMIT 1;");
                
$db->sql_query("DELETE FROM ".$db_prefix."_files WHERE torrent = '".$row['id']."';");
                
btsqlerror($filesql);
        }
}
$torrentpath $torrent_dir."/".$row['id'].".torrent";
if (
file_exists($torrentpath)) unlink($torrentpath);

$fp fopen($torrentpath,"wb");
fwrite($fp,Bencode($torrent));
fclose($fp);
//@unlink($tmpname);
echo "Torrent ".$row['name']." added<br />";
$sqlc "SELECT * FROM `comments` WHERE `torrent`='".$row['id']."';";
$resc $db->sql_query($sqlc)or btsqlerror($sql);
while(
$rowc $db->sql_fetchrow($resc)){
                        
$sql "INSERT INTO ".$db_prefix."_comments (user, torrent, added, text) VALUES ('".$rowc['user']."', '".$row['id']."', '".$row['added']."', '" $row['text'] . "');";
                        
$db->sql_query($sql) or btsqlerror($sql);
}
$db->sql_freeresult($resc);


}
$db->sql_freeresult($res);
include
'footer.php';
?>
__________________
Do not ask me to help you work on your site that is not phpMyBitTorrent
Do not ask me to make a mod for any other source
Do not Ask me to setup your site.
I will no longer help you setup your site, there is a setup script if you have trouble with it post in the forum here or in BT.Manager™ forum
My Current Demo is here http://demo.btmanager.org/

Last edited by joeroberts; 12th November 2010 at 11:11.
Reply With Quote