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
Webseed Generator (Auto)
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / V4 / Support & Suggestions

2021-04-01 00:50:07
This is a automation mod we developed to scan /webseeds/ and automatically add torrent to system and initiate webseed dictionary key 'url-lists'. Pending support for 'httpseeds'.

The plan is to use this and mass import files at each clean interval. Much easier to put up releases automatically, by just dropping files into /webseeds/ and it takes care of the rest.

This script relies on PHP 8 features that reduce a lot of overhead for me, like str_contains(), rather than pointing several array key conditional lookups for just 1 string to match.

I didn't apply the new functions for $version as it already works very well with no slow-down.

<?
/*
Switch-Torrents Webseed/HTTPseed Generator - April 1, 2021
Implements Torrent signing
Implements "GetRight" style HTTP/FTP seeding
->  transmission-create
->  ut-signing-tool

Version 1.0.1 (April 2, 2021):
- CLI: Single-quoted command parameters (transmission-create) to be on safe side
- Process: Updated temporary torrent filename with md5 hash to avoid iteration processing conflicts (file overlapping)
- Process: Update torrent database row with +1 unchoked seed
- Process: Get release version from filename [v0.0.0]

Version 1.0.2 (April 4, 2021):
- Process: Category INT value by file extension type
- Process: Determine DLC by dictionary path array keys: [0][1]

*/
require_once '../site.php';
require_once '../classes/class.bencoding.php';
$db->connect();
site_header();
error_reporting(E_ALL);
$dir = new DirectoryIterator('webseeds/');
foreach ($dir as $fileinfo) {
   if (!$fileinfo->isDot()) {
       $passkey = 'YOUR_PASSKEY'; // default passkey
       $tmpname = md5('webseed') . '.torrent'; // temporary filename
       exec("transmission-create -o 'webseeds/$tmpname' -p 1 -c '$CONFIG[site_title]' -s 1024 -t '$CONFIG[base_url_nossl]/announce?passkey=$passkey' 'webseeds/$fileinfo'", $result);
       print_r($result);
       $fp   = fopen('webseeds/' . $tmpname, 'rb');
       $data = '';
       while (!feof($fp)) {
           $data .= fread($fp, 8192);
       }
       fclose($fp);
       $arr    = bdecode($data);
       $infobc = bencode($arr['info']);
       if ($infobc === false) {
           $db->query_params('INSERT INTO log (added, txt) VALUES(NOW(), :log)', array(
               'log' => 'Webseed: Bencoding error'
           ));
       }
       // Get release version
       $version = str_replace(']' . substr($fileinfo, -4, strpos($fileinfo, '.')), '', substr(strstr($fileinfo, '[v'), 2));
       // Determine DLC included
       if ($arr !== false && array_key_exists('files', $arr['info'])) {
           foreach ($arr['info']['files'] as $file) {
               if (array_key_exists('path', $file)) {
                   $dlc = false;
                   if (str_contains($file['path'][0], 'DLC') || str_contains($file['path'][1], 'DLC')) { // PHP 8
                       $dlc = true;
                   }
               }
               // Determine category by file extension - PHP 8
               if (str_contains($file['path'][0], 'xci')) {
                   $category = 47;
               } else if (str_contains($file['path'][0], 'nsz')) {
                   $category = 48;
               } else if (str_contains($file['path'][0], 'nsp')) {
                   $category = 1;
               }
           }
       }
       // Generate info hash
       $info_hash  = sha1($infobc);
       $total_size = 0;
       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'];
       }
       // Check duplicate info hash
       $res = $db->query_params('SELECT torrent_id FROM torrents WHERE info_hash = :info_hash', array(
           'info_hash' => $info_hash
       ));
       if ($row = $res->fetch()) {
           continue;
       }
       // BEP 19 - WebSeed - HTTP/FTP Seeding (GetRight style)
       if ($fileinfo->isFile()) {
           $arr['url-list'] = sprintf('%s/webseeds/%s', $CONFIG['base_url_nossl'], $fileinfo); // single file
       } else if ($fileinfo->isDir()) {
           $arr['url-list'] = sprintf('%s/webseeds/%s/', $CONFIG['base_url_nossl'], substr($fileinfo, 0, strpos($fileinfo, '.'))); // multi-file
       }
       // BEP 25 - Torrent Signing
       sign_torrent($fileinfo, 0, bencode($arr));
       $data = file_get_contents('../signing/signed.torrent');
       // Save to database
       $torrent_id = $db->query_params('INSERT INTO torrents (user_id, name, descr, webseed, anon, info_hash, size, tags, version, dlc, youtube, freeleech, cover1, image1, image2, category, cert_signed) VALUES (:user_id, :name, :description, :webseed, :anonymous, :info_hash, :total_size, :tags, :version, :dlc, :youtube, :freeleech, :cover1, :image1, :image2, :category, :cert_signed)', array(
           'user_id' => 1,
           'name' => substr($fileinfo, 0, strpos($fileinfo, '.')),
           'description' => substr($fileinfo, 0, strpos($fileinfo, '.')),
           'webseed' => 1,
           'anonymous' => 0,
           'info_hash' => $info_hash,
           'total_size' => $total_size,
           'tags' => 'Webseed, Auto',
           'version' => $version,
           'dlc' => ($dlc ? 'Yes' : 'No'),
           'youtube' => '',
           'freeleech' => 0,
           'cover1' => 'switch_cover_none.png',
           'image1' => 'nocover.png',
           'image2' => 'nocover.png',
           'category' => intval($category),
           'cert_signed' => 'signed'
       ), 'torrent_id') or die('Error inserting webseed torrent');
       $db->query_params('INSERT INTO torrents_blob (torrent_id, user_id, data) VALUES (:last_id, :user_id, :data)', array(
           'last_id' => $torrent_id,
           'data' => $data,
           'user_id' => 1
       ));
       if ($torrent_id) {
           $db->query_params('INSERT INTO log (added, txt) VALUES(NOW(), :log)', array(
               'log' => sprintf("Webseed imported \"%s\" ID: %s", $fileinfo, $torrent_id)
           ));
           // Update torrent with 1 unchoked seed
           $db->query_params('UPDATE torrents SET seeders = 1 WHERE torrent_id = :torrent_id', array(
               'torrent_id' => $torrent_id
           ));
           // Remove temporary file
           unlink('webseeds/' . $tmpname);
           
           break; // testing this
       }
   }
}
site_footer();
Last edited by STorrents2020 on 2021-04-04 21:24:14
2021-04-04 21:17:36
Generator is COMPLETE! Works perfectly!
2021-05-24 17:01:34
can you tell you a little more!
it replaces the torrent import !?
Thank you
2021-05-24 20:03:10
what are these functions and tables

sign_torrent($fileinfo, 0, bencode($arr));
bencode($arr)
torrents_blob table
Last edited by M-jay warn on 2021-05-24 20:03:21
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: 3
  • Members: 0
  • Guests online: 3
  • Comments: 3
  • Messages: 1,728