I've tried to upload several time torrent files but always the modul has cut something of the files:
before upload:
d8:announce47:http://www.xyz.net/announce.php18:azureus_propertiesd17:dht_backup_enabl... by15:Azureus/3.1.1.013:creation datei1223307191e8:encoding5:UTF-84:infod6:lengthi67628e4:name29:Interview Humanwirtschaft.pdf10:name.utf-829:Interview Humanwirtschaft.pdf12:piece lengthi32768e6:pieces60:ÈCÒGvúJ{l.ùw˙zµØvÖfiÁIÂ◊3õfi≤¨gl™´Ëe.p–áPÕŸ Ò€IW1·Êyfl 7:privatei0eee

after upload:
d8:announce47:http://www.www.xyz.net/announce.php4:infolee

Do you know what's wrong?

CommentFileSizeAuthor
#6 __ill.png20.48 KBgildedgod

Comments

xxm’s picture

Title: Bittorrent modul cuts torrent files » Bittorrent modul cut torrent files
gildedgod’s picture

Your torrent has not been parsed.

Your problem is similar to this ones: http://drupal.org/node/290093, http://drupal.org/node/284621, http://drupal.org/node/196931.

I have all of symptomes from this nodes in one tracker - mine ^^ :

  • message "Warning: array_key_exists(): The second argument should be either an array or object line 351" on submitting torrent
  • torrents only contain 0 files
  • torrents are being cut after upload to "d8:announce90:http://site_name/announce.php?passkey=%EB%DC%2B%F3%8F%05%C5%88NQ%1Di%81%CEV%92H%27u%D2e" instead of 10-20 kb of original size

I think there is only one problem - bt_torrent.module can not parse uploaded torrent files. Why? That is a question.

A place it stumbs is lines 342-343:

          $torrent = db_fetch_object(db_query("SELECT f.filepath FROM {files} f WHERE nid = %d", $node->nid));
          $torrent = bdecode_torrent($torrent->filepath);

After this $torrent must be an array with a lot of stuff:

      'announce' => 'announce url',
      'creation date' => 'creation date',
      'info' => array(
        'files' => 'files list',
        'name' => 'torrent name',
        'piece length' => 'length of each piece',
        'pieces' => 'The piece hashes',
      ),

But function bdecode_torrent() return nothing...

Now I'm investigating this problem.

Besides, there is another bug: torrent files can not be renewed when node is published. Every new upload of torrent file when an old one already exitsts occures error message.

gildedgod’s picture

Priority: Normal » Critical
gildedgod’s picture

Title: Bittorrent modul cut torrent files » In some cases module can't parse uploaded .torrent files
gildedgod’s picture

Finally I've found it.

The problem is here - in line 342:

          $torrent = db_fetch_object(db_query("SELECT f.filepath FROM {files} f WHERE nid = %d", $node->nid));

I have a CCK field named "Covers" with "Image" type for Torrent content.

So, when I added lines 343, 345:

          $torrent = db_fetch_object(db_query("SELECT f.filepath FROM {files} f WHERE nid = %d", $node->nid));
          $sss = $torrent->filepath;
          $torrent = bdecode_torrent($torrent->filepath);
          die("DEBUG: \n".print_r($torrent)."\n\n".$sss);

I had a result:

DEBUG: 1 files/covers/Ritsuka/1224650992508.jpg

So, the file that is being parsed by BitTorrent module is not my uploaded .torrent file, but is an image that i have uploaded as a cover.

There are two ways to solve this problem. First is to use MIME-types control (line 342):

          $torrent = db_fetch_object(db_query("SELECT f.filepath FROM {files} f WHERE nid = %d and filemime = 'application/x-bittorrent'", $node->nid));

But if your server does not support MIMEs recognition, you can easily use a LIKE statement:

          $torrent = db_fetch_object(db_query("SELECT f.filepath FROM {files} f WHERE nid = %d and filename LIKE '%.torrent'", $node->nid));

Drupal 5.12, CCK 1.7, BitTorrent 2.0-beta3

gildedgod’s picture

Title: In some cases module can't parse uploaded .torrent files » BitTorrent and CCK compatibility issue
StatusFileSize
new20.48 KB

1) There is another one query with same error in bt_torrent.module:

Line 484

          $torrent = db_fetch_object(db_query("SELECT f.filepath FROM {files} f WHERE nid = %d", $node->nid));

should also be changed to:

          $torrent = db_fetch_object(db_query("SELECT f.filepath FROM {files} f WHERE nid = %d and filename LIKE '%.torrent'", $node->nid));

2) Umpf... And there is another big problem with CCK "File" and "Image" fields and BitTorrent compatibility:

With this code (bt_torrent.module lines 153-154):

  $form['bt_options']['upload_wrapper'] += module_invoke('_upload', 'form', $node);
  $form['#attributes'] = array('enctype' => "multipart/form-data");

You invoke upload.module to make a job with uploading and updating .torrent files. First part of this job it makes great, but the second one... As you remember, because of using CCK type "Image" we have more than one file attached to node. So, we see more than one file in list:

http://drupal.org/files/issues/__ill.png

List of uploaded files is totally corrupted and neither update nor deleting of files can not be done.

We need another, standalone from upload.module form, yeah?

gildedgod’s picture

Category: support » bug
gildedgod’s picture

Title: BitTorrent and CCK Imagefield compatibility issue » BitTorrent and CCK compatibility issue

Solved

Condition: when you use CCK "image" field (imagefield module) with BitTorrent module (adding image field to Torrent node type) sometimes uploaded torrents are not parsed correctly.

Сause: uploaded images stored in “files” table (and, of course, in $node->files), so, when BitTorrent module retrieves the first file attached to node, it is not necessary a .torrent file.

Solution: use standalone FileField module to serve .torrent uploads.

1. Install FileField module.

2. Create file field named "field_torrent_file" with "multiple values" disabled and ".torrent" as extension filter value. Mark it as not neccessary.

3. Mark it "hidden" in node teaser and body.

4. Edit "bt_torrent.module"

  • Lines 148-154 :: Disable old upload form

    FROM:

     $form['bt_options']['upload_wrapper'] = array(
        '#prefix' => '<div id="attach-wrapper">',
        '#suffix' => '</div>',
      );
      
      $form['bt_options']['upload_wrapper'] += module_invoke('_upload', 'form', $node);
      $form['#attributes'] = array('enctype' => "multipart/form-data");
    

    TO:

     /* $form['bt_options']['upload_wrapper'] = array(
        '#prefix' => '<div id="attach-wrapper">',
        '#suffix' => '</div>',
      );
      
      $form['bt_options']['upload_wrapper'] += module_invoke('_upload', 'form', $node);
      $form['#attributes'] = array('enctype' => "multipart/form-data");*/
    



  • Lines 165-182 :: Replace bt_torrent_validate() function with another one

    FROM:

    function bt_torrent_validate($node) {
      if ($node->type == 'torrent') {
        if (!is_array($node->files) && strcmp($node->web_seeding_path, '') == 0 && !isset($node->nid)) {
          form_set_error('upload', t('A torrent file must be attached to the node <em>OR</em> a web-seeding path must be specified. Please attach a torrent or specify a path and try again.'));
        }
        elseif (is_array($node->files) && !(strcmp($node->web_seeding_path, '') == 0)) {
          form_set_error('upload', t('Please do not attach torrents to nodes that are utilizing web-seeding'));
        }
        elseif (is_array($node->files) && (strcmp($node->web_seeding_path, ''))) {
          if (!preg_match('/\.torrent$/i', $node->files['upload_0']['filename']) && is_valid_torrent(bdecode_torrent($node->files['upload_0']['filepath']))) {
            form_set_error('upload', t('Please only upload .torrent files'));
          }
        }
        elseif (!is_array($node->files) && !realpath(variable_get('bt_web_seed_dir', 'files/'. md5(drupal_get_private_key()) .'-web-seeding/') . $node->web_seeding_path) && !isset($node->nid)) {
          form_set_error('web_seeding_path', t('Please enter a valid path.'));
        }
      }
    } 
    

    TO:

    function bt_torrent_validate($node) {
      if ($node->type == 'torrent') {
        if (!is_array($node->field_torrent_file) && strcmp($node->web_seeding_path, '') == 0 && !isset($node->nid)) {
          form_set_error('upload', t('A torrent file must be attached to the node <em>OR</em> a web-seeding path must be specified. Please attach a torrent or specify a path and try again.'));
        }
        elseif (is_array($node->field_torrent_file) && !(strcmp($node->web_seeding_path, '') == 0)) {
          form_set_error('upload', t('Please do not attach torrents to nodes that are utilizing web-seeding'));
        }
        elseif (is_array($node->field_torrent_file) && (strcmp($node->web_seeding_path, ''))) {
          if (!preg_match('/\.torrent$/i', $node->field_torrent_file[0]["filename"]) && is_valid_torrent(bdecode_torrent($node->field_torrent_file[0]["filepath"]))) {
            form_set_error('upload', t('Please only upload .torrent files'));
          }
        }
        elseif (!is_array($node->files) && !realpath(variable_get('bt_web_seed_dir', 'files/'. md5(drupal_get_private_key()) .'-web-seeding/') . $node->web_seeding_path) && !isset($node->nid)) {
          form_set_error('web_seeding_path', t('Please enter a valid path.'));
        }
      }
    }
    



  • Lines 341-342 & 491-492 :: Now there is another place, where uploaded file info stored

    FROM:

              $torrent = db_fetch_object(db_query("SELECT f.filepath FROM {files} f WHERE nid = %d", $node->nid));
              $torrent = bdecode_torrent($torrent->filepath);
    

    TO:

            //  $torrent = db_fetch_object(db_query("SELECT f.filepath FROM {files} f WHERE nid = %d", $node->nid));
              $torrent = bdecode_torrent($node->field_torrent_file[0]["filepath"]);
    



    Be carefull! This code should be changed twice!


After all this changes you'll get a pretty standalone and fully customizable upload form (1), ability to configure path where .torrent files stores inside "files" folder (2) and, of course, working tracker =)

gildedgod’s picture

Title: BitTorrent and CCK compatibility issue » BitTorrent and CCK Imagefield compatibility issue
Assigned: Unassigned » gildedgod
Status: Active » Needs review
gildedgod’s picture

Title: BitTorrent and CCK compatibility issue » BitTorrent and CCK Imagefield compatibility issue

In addition to FileField usage: lines 360 & 507 also should be removed in bt_torrent.module

module_invoke('upload', 'delete', $node);
bradfordcp’s picture

Wow that was a lot to go through... I see your concerns with the torrent node type limiting the uploading of files as well as looking (and deleting in some cases) files that it should be ignoring. I am working on the D6 port right now and these changes will be worked in.

Thank you so much for your help!

liquixis’s picture

Status: Needs review » Closed (won't fix)

5.x version is longer not supported.