BitTorrent and CCK Imagefield compatibility issue
xxm - October 6, 2008 - 16:40
| Project: | BitTorrent |
| Version: | 5.x-2.0-beta3 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | gildedgod |
| Status: | won't fix |
Description
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_enablei1ee7:comment0:13:comment.utf-80:10:created 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?

#1
#2
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 ^^ :
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:
<?php$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.
#3
#4
#5
Finally I've found it.
The problem is here - in line 342:
<?php$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:
<?php$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.jpgSo, 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):
<?php$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:
<?php$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
#6
1) There is another one query with same error in bt_torrent.module:
Line 484
<?php$torrent = db_fetch_object(db_query("SELECT f.filepath FROM {files} f WHERE nid = %d", $node->nid));
?>
should also be changed to:
<?php$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):
<?php$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?
#7
#8
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"
FROM:
<?php
$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:
<?php
/* $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");*/
?>
FROM:
<?phpfunction 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:
<?phpfunction 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.'));
}
}
}
?>
FROM:
<?php$torrent = db_fetch_object(db_query("SELECT f.filepath FROM {files} f WHERE nid = %d", $node->nid));
$torrent = bdecode_torrent($torrent->filepath);
?>
TO:
<?php// $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 =)
#9
#10
In addition to FileField usage: lines 360 & 507 also should be removed in bt_torrent.module
<?phpmodule_invoke('upload', 'delete', $node);
?>
#11
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!
#12
5.x version is longer not supported.