Page 1 of 1

Add downloads from a directory

Posted: 06 Mar 2007, 19:25
by bubbalibre
Hi,

I'm trying to add this feature : add a download from a directory (/home/user/torrents).

It could be use to quickly add torrents previously downloaded and, mainly, restore the downloads after an ftd crash. :wink:

It's quite simple from the ui point of view. I've added a new button to the interface and here is what I have in mind :

Code: Select all

$restore_downloads = $_POST['restore_downloads'];
$user_torrents = '/home/'.$_SESSION['user'].'/torrents/';
if($restore_downloads == 'Restore' && file_exists($user_torrents)) {
    $uuid = $_POST['uuid'];
    $files = glob($user_torrents.'*.torrent');
    foreach($files as $url) {
         $dl->add_download($_SESSION['user'], $url, $uuid);
    }
}
The problem is that ftd is intended to download itself the torrent file. Is there a way to start a download from a local file instead of a url, as I'm trying to ?

Posted: 06 Mar 2007, 20:17
by TheEagleCD
nice work! :)

I was actually tossing around the same idea with my flatmate the other day as the torrent client on his linux desktop machine also looks at a directory on his drive in regular intervals to check for new .torrent files

hope that you can get it to work, but I fear that maybe ftd doesn't support local torrents...

Posted: 08 Mar 2007, 05:37
by bubbalibre
Okay, I'm getting closer.

First I tried using the apache's userdir directive. I modified the file /etc/apache2/mods-available/userdir.conf:

Code: Select all

<IfModule mod_userdir.c>
        UserDir www
        UserDir disabled root

        <Directory /home/*/www/>
                AllowOverride FileInfo AuthConfig Limit
                Options -Indexes SymLinksIfOwnerMatch IncludesNoExec
                Order deny,allow
                Deny from all
                Allow from 192.168.0.0/255.255.255.0
        </Directory>
</IfModule>
So if I create a www directory into my home, I can acces it from every computer on my network with an url.

Then I created a subdirectory called torrents and modified my previous script:

Code: Select all

$restore_downloads = $_POST['restore_downloads'];
$user_torrents = '/home/'.$_SESSION['user'].'/www/torrents/';
if($restore_downloads == 'Restore' && file_exists($user_torrents)) {
    $files = glob($user_torrents.'*.torrent');
    echo '<fieldset><legend>Restoring</legend>'."\n".'<p>'."\n";
    foreach($files as $file) {
        $uuid = uniqid('ftd');
        $url = 'http://localhost/~'.$_SESSION['user'].'/torrents/'.basename($file);
        $response = $dl->add_download($_SESSION['user'], $url, $uuid);
        echo basename($file,'.torrent').': '.$response.'<br/>'."\n";
    }
    echo '</p>'."\n".'</fieldset>';
}
It worked once, but most of the time ftd crashes. I tried to delay each execution with a Sleep(1); but it didn't work.

Any idea ?

Posted: 08 Mar 2007, 05:50
by bubbalibre
Right now I've got 3 ftd processes running (and 3 torrents). But the interface doesn't show any...

A few question about the Downloader class:
  • # the add_download() function seems to send a proper response : "1" (true). Am I right ?

    # what's the $policy for in that same function ?
    I saw the constants init and guess that's to close the torrent right after downloading or hidding the download from the interface. Could the policy turn somehow into hidden state ?

Posted: 08 Mar 2007, 06:12
by bubbalibre
I am an idiot !

It's working (with some ftd crashes, but not that much). I restricted the access to the user's www directory from the local network, and tried to access it from localhost...

Replacing the $url attribution with

Code: Select all

$url = 'http://'.$_SERVER['SERVER_ADDR'].'/~'.$_SESSION['user'].'/torrents/'.basename($file);
and it works fine.

Posted: 08 Mar 2007, 06:21
by tor
Hi,

I must say that using http://localhost for this is quite clever :)

Regarding the crashes of ftd. There is one easy way to crash ftd. That is to start the same download twice. That might be a cause of it?

Other than that we are of course interested in finding out any crashes since they are quite fatal for the system.

If you have the time and experience we would love some backtraces of this.

If you can, install the gdb package. And then run ftd in that.

As root:

Stop ftd

Code: Select all

/etc/init.d/ftd stop
Start gdb with ftd:

Code: Select all

gdb /usr/sbin/ftd
Tell gdb to run ftd in foreground:

Code: Select all

set args -f
Start ftd:

Code: Select all

run
Then use the download manager as usual until ftd crashes. Then go back to the terminal, which should hopefully give some info on the crash. Tell gdb to print a stack trace:

Code: Select all

bt
Copy and paste as much as possible in a mail or private message to us :)

/Tor

Posted: 08 Mar 2007, 06:44
by bubbalibre
Hi Tor,

Gdb is running... I'll send any piece of interesting information. For most of the crashes occur when I'm tried to stop or cancel a download, I think this will not happen for a while.
tor wrote:Regarding the crashes of ftd. There is one easy way to crash ftd. That is to start the same download twice. That might be a cause of it?
I have to say yes. I aimed to use the torrents folder to restart downloading after a crash, but also to add new downloads... without removing the previous ones. This way I was hoping to find an easy way to get torrents from private torrents : just a drag'n drop and a push on a button. Will this be possible in the next versions ?

Thanks for the tip anyway.

Posted: 12 Mar 2007, 07:03
by tor
bubbalibre wrote:A few question about the Downloader class:
  • # the add_download() function seems to send a proper response : "1" (true). Am I right ?
Absolutely, add_download returns true if the command succeeded false otherwise.
bubbalibre wrote:# what's the $policy for in that same function ?
I saw the constants init and guess that's to close the torrent right after downloading or hidding the download from the interface. Could the policy turn somehow into hidden state ?
The policy is how the download should be handled and presented. Where

DLP_NONE is the default do nothing.
DLP_AUTOREMOVE is remove download when completed
DLP_HIDDEN is "don't show this download in UI".

Policies can also be combined so one could add a download not showing in UI and to be automatically removed when completed by doing a bitwise or of the wanted policies.

Code: Select all

$dl->add_download("user","url","uuid",DLP_AUTOREMOVE|DLP_HIDDEN)
/Tor

Posted: 12 Mar 2007, 13:05
by bubbalibre
Thanks for the tip.