Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Torrent 2 BLOB data Migrator
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Mods Completed

2020-08-16 10:20:23
I've developed a mod for my upcoming changes and my main site itself. So what this script does is it scans all
of the .torrent files in your /uploads/ dir and converts them all to database BLOB data. This is file-less bencoded/bdecoded data pulled from
your database and has several advantages, notably backups and database security.

With the days of internet censorship, among all else - I am in this direction.

[url='https://study.com/academy/lesson/sql-data-types-binary-large-object.html']Read about BLOB data and what it can do for you.[/url]

So I spent the day developing this tool to grab all your torrents, parse all their data and push that bencoded data to your database.
This is as easy as it gets and wasn't very easy for me but this cuts a lot of technicality and bs and just gets it done for you (and myself) at a click!

Just upload ZIP to root, and head to /migratev3.php

[ATTACH type="full" alt="migrate1.png"]5755[/ATTACH]

[ATTACH type="full" alt="migrate2.png"]5756[/ATTACH]

NOTE:
Be sure to make a full SQL backup immediately, before running this tool. This rehashes info_hash on ALL rows, as they are rehashed by bencode().

What can I do with the data?
Keep the BLOB data stored for now. It is safe. More will follow in a few days. What will come, is a change for torrents-details.php to feed all torrent-related data through the bdecode class instead of
how it pulls it right now. That will provide file info, sizes, info_hash, data, comment, announce etc

UPDATE: This is a perfect and safe update as to migrate all with NO interference of any sort. For those who want this in the future.


<?php
// Convert .torrent files => DB => BLOB data
// STorrents2020@TorrentTrader.xyz
require_once 'backend/functions.php';
require_once 'backend/classes/bencoding.class.php';
dbconn();
?>

<style>.migrator{box-shadow:inset 0 39px 0 -24px #e67a73;background:#e4685d;border-radius:4px;border:1px solid #fff;display:inline-block;cursor:pointer;color:#fff;font-family:Arial;font-size:15px;padding:6px 15px;text-decoration:none;text-shadow:0 1px 0 #e61d12}.migrator:hover{background-color:#f31717}.migrator:active{position:relative;top:1px}</style>

<?php
stdhead("Torrent BLOB Migrator");
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
   // Add missing data column if needed
   @SQL_Query_exec("ALTER TABLE torrents ADD COLUMN data MEDIUMBLOB NOT NULL");
   // Locate .torrent files
   $dir = new DirectoryIterator('uploads/');
   foreach ($dir as $fileinfo) {
       if (!$fileinfo->isDot()) {
           $getthelist = $fileinfo->getFilename();
           $fp         = fopen('uploads/' . $getthelist, 'rb');
           $data       = '';
           while (!feof($fp)) {
               $data .= fread($fp, 8192);
           }
           fclose($fp);
           $arr = bdecode($data);
           if ($arr === false) {
               //die('invalid torrent');
               continue;
           }
           if (!array_key_exists('info', $arr)) {
               //die('invalid torrent');
               continue;
           }
           //$arr['info']['private'] = 1;
           $infobc                 = bencode($arr['info']);
           if ($infobc === false) {
               die('bencoding error');
           }
           $info_hash  = sha1($infobc);
           $total_size = 0;
          if ($checktype['info']['private'] = 1) { // Added - Check if torrent is private - Sep 1, 2020
               if (array_key_exists('files', $arr['info'])) {
                   foreach ($arr['info']['files'] as $file) {
                       if (array_key_exists('length', $file)) {
                           $total_size += $file['length'];
                       }
                   }
               } else if (array_key_exists('length', $arr['info'])) {
                   $total_size += $arr['info']['length'];
               }
               $data = bencode($arr);
           } else {
               $data = bdecode($data); // Public torrent            
           }
           $fileid = str_replace('.torrent', '', $getthelist);
           $data   = bencode($arr);
           $db = new mysqli($mysql_host, $mysql_user, $mysql_pass, $mysql_db);
           $db->set_charset("utf8mb4");
           $stmt = $db->prepare("UPDATE torrents SET data = ?, size = ? WHERE id = ?");
           $stmt->bind_param("sii", $data, $total_size, $fileid);
           $stmt->execute();
           $stmt->close();
       }
   }
   header("Location: " . $site_config['SITEURL'] . "/migratev3.php?complete");
   exit();
}

begin_frame("<h1>TTv4 Torrent => BLOB Database Migrator</h1>");
    $totaltorrents = new DirectoryIterator('uploads');
    $checkcolumn = true;
   if (!empty($checkcolumn)): echo '<div style="margin:0 0 10px 0;padding:10px;background:#242424;color:#FFF;border-radius:7px;text-align:left">BLOB database column: <span style="font-weight:500;color:orange">Found</span></div>'; else: echo '<div>Data column <b>not</b> found.</div>'; endif;
   printf('<form action="migratev3.php" method="post">');
   printf('<a href="#" class="migrator" onclick="submit();">Migrate Now</a> @credits to <span style="font-weight:500">STorrents2020</span>@TorrentTrader.xyz');
   printf('<div style="padding-top:10px">Found <span style="font-weight:500">' . iterator_count($totaltorrents) . '</span> torrent files in <span style="font-weight:500">/uploads/</span></div>');
   if (is_string($_GET['complete'])):
       echo '<div style="margin:10px 0 10px 0;padding:10px;background:#242424;color:#FFF;border-radius:7px;text-align:left"><span style="font-weight:600;background:#C0C0C0;color:#242424;padding:0 5px 0 5px;border-radius:4px;margin-right:8px">' . iterator_count($totaltorrents) . '</span> torrents successfully imported as BLOB data.</div>';
   endif;
   printf('</form>');
end_frame();
stdfoot();
?>
migrate1.png
migrate1.png
migrate2.png
migrate2.png
TT Torrent to BLOB Migrater.zip
Download
2020-09-02 00:20:26
Post updated with final code for a perfect working migrator. This is 100% safe and can be dropped in anytime to your root /

- Detect private or external torrent by bdecoded data
- Removed any handling of info_hash (very important)

torrents-details.php

You can read file list, sizes and much more! Using this code and including the class if you haven't already

be sure to include `data` in your main query in torrents-details - near top ( torrents.name, torrents.descr, etc ... torrents.data, )

print("<table align='center' cellpadding='0' cellspacing='0' border='0' width='100%'><tr><th class='table_head' align='left'>File</th><th width='50' class='table_head'>Size</th></tr></table>");
$data = $row['data'];
$arr  = bdecode($data);
if ($arr !== false && array_key_exists('info', $arr)) {
   if (array_key_exists('files', $arr['info'])) {
       foreach ($arr['info']['files'] as $file) {
           if (array_key_exists('path', $file)) {
               printf("<span>%s</span>", implode('/', $file['path']));
               printf("<br/>");
           }
}
   } else if (array_key_exists('name', $arr['info'])) {
       printf("<span>%s</span>", $arr['info']['name']);
       printf("<br/>");
   }
}
2020-09-05 07:35:53
thank you for your time and work but where should we put the code and after which line of code :rolleyes:
2020-09-05 10:37:02
Thanks for asking niki, I have actually improved this code and extended it with more data to show, including private yes/no, announce urls etc. I will update post.

Readers: When posting this code, I did not yet have the rude awakening of multiple database crashes (good thing for InnoDB), turns out storing BLOB data in the same torrent table is horrible practice (all those connections / seek time), and will put the server to its knee's (for me 4 hours after sleep).

The solution is creating another table with relational link to the primary torrent table and referencing back ONLY the to the data column. I'll explain as I write the post. I use the blob data daily, no issues now. But that is important to know. Huge oversight.
2020-09-05 11:02:04
ok thanks for the answer
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 9
  • Members: 0
  • Guests online: 9
  • Comments: 3
  • Messages: 1,728