For my own use on a Windows XP machine I've packaged the script into an executable using the PAR packaging module and then configure Firefox to run .torrent files with it.
Probably this will be useful to others as well.
I've only tested it on the DS101g+ Firmware Version 2.0.3 - 0460, but assuming the web menus are the same, it should work on any other Synology device. (Or can be made to work.)
- Code: Select all
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
use Getopt::Long;
use Data::Dumper;
use Pod::Usage;
my $url = undef;
my $login = undef;
my $password = undef;
my $location = undef;
my $is_torrent = undef;
my ($help, $man) = undef;
my $result = GetOptions(
'url|u=s' => \$url,
'login|l=s' => \$login,
'password|p=s' => \$password,
'file|f=s' => \$location,
'is_torrent|t' => \$is_torrent,
'help|h' => \$help,
'man|m' => \$man,
);
if ($help || $man) {
pod2usage(-verbose => 1);
}
check_opt();
my $mech = WWW::Mechanize->new();
$mech->get($url);
$mech->get($url.$mech->{'links'}->[0]->[0]);
my $form = $mech->form_name('form');
$form->{'inputs'}->[0]->{'current'} = 1;
$form->{'inputs'}->[1]->{'value'} = $login;
$form->{'inputs'}->[2]->{'value'} = $password;
$mech->submit($form);
$mech->{'content'} =~ /download_management.cgi\?id=([^\"]+)\"/;
my $id = $1;
unless ($id) {
die('Failed to parse session id');
}
$mech->get($url."download/downloadtaskadd.cgi?id=$id");
$form = $mech->form_name('uploadForm');
if ($is_torrent) {
$mech->set_visible( [
'radio' => 'torrent',
] );
$form->{'inputs'}->[3]->file($location);
} else {
$mech->set_visible( [
'radio' => 'url',
] );
$form->{'inputs'}->[2]->value($location);
}
$mech->submit($form);
if ($mech->{'content'} =~ /The settings have been completed successfully/) {
print "'$login' successfully queued file '$location'\n";
} else {
if ($mech->{'content'} =~ /Data can not be applied/) {
if ($mech->{'content'} =~ /The URL should start with http/) {
print "Adding download '$location' to queue for user '$login' failed\n";
die("--is_torrent flag must be specified for queueing torrent files");
} else {
print "Adding download '$location' to queue for user '$login' failed\n";
print Dumper $mech;
die();
}
} else {
print "Adding download '$location' to queue for user '$login' failed\n";
print Dumper $mech;
die();
}
}
sub check_opt {
unless ($login) {die "Must provide login name with --login flag";}
unless ($password) {die "Must provide password with --password flag";}
unless ($url) {die "Must provide URL of diskstation with --url flag";}
unless ($location) {die "Must provide URL or path to torrent file with --file flag";}
unless ($url =~ /\/$/) {
$url .= "/";
}
}
__END__
=head1 NAME
diskstation_download.pl - Add files to diskstatin download service queue
=head1 SYNOPSIS
diskstation_download.pl --login login --password password --url http://diskstation:5000 --file /path/to/some_torrent_file.torrent --is_torrent 1
=head1 DESCRIPTION
This script allows adding download tasks to the diskstation download service queue without using the download redirector by automatic submission through the diskstation's web interface.
It supports queueing of both FTP/HTTP downloads and torrents.
Tested to work with Synology DS101g+
Firmware Version 2.0.3 - 0460
=head1 OPTIONS
=over 4
=item --login STRING
User login
=item --password STRING
User password
=item --url STRING
Diskstation web interface URL (eg: http://diskstation:5000)
=item --file STRING
URL/path to file to download
=item --is_torrent INT
Flag to specify whether file to queue is a torrent file (0 = no, 1 = yes)
=back
=head1 AUTHORS
Brett Whitty E<lt>spambw@gmail.comE<gt>
=cut


