Jump to content

Windows/wine to linux resume.dat conversion script


The Mighty Buzzard

Recommended Posts

New version and I thought I'd give it its own post this time. It's still not by any means what I'd call finished code but it's a little more useful if you're running both the alpha and a wine/windows version.

What this script does is takes the resume.dat you specify on the command line (from the wine version, a mounted windows partition, usb drive, whatever..), reads all the entries, converts the paths to the ones you specify in %basedirs, and writes out a new resume.dat to the current directory.

If you already have a resume.dat in the current directory, it will read that first, back it up, add the windows/wine version entries to the existing ones, and write out the combined file. In essence, it meshes any torrents you have in the windows/wine version with any you have in the linux version.

If you have any problems getting the following code to work, you really don't know enough to be messing with it. Please don't ask for support.

#!/usr/bin/perl 
# This is a VERY basic script to help those converting from using utorrent under wine
# to migrate to the new linux port. It's likely buggy as all hell and will probably set
# your house on fire. Back your shat up before playing with it.
use Convert::Bencode qw(bencode bdecode);

# Change these to suit your needs. from => to in %basedirs.
# Yes, I'm a lazyass and just used . to match the annoying dos path bits rather than
# explicitly matching them.
my %basedirs = (
'...windows.profiles.bob.Desktop.torrents' => '/home/bob/Desktop/torrents',
'...storage.temp' => '/home/bob/Desktop/torrents/temp'
);

unless(defined $ARGV[0])
{
print "usage: ./syncpaths.pl <path to windows/wine resume.dat>\n";
exit;
}

my $resume_dat_win = $ARGV[0];
my $resume_dat_lin = 'resume.dat';

open(RESUMEW, "< $resume_dat_win")
or die $!;
my $win_contents = do { local $/; <RESUMEW> };
close RESUMEW;
my $win_decoded = bdecode($win_contents);

my %linhash;

if(open(RESUMEL, "< $resume_dat_lin"))
{
my $lin_contents = do { local $/; <RESUMEL> };
close RESUMEL;
my $lin_decoded = bdecode($lin_contents);

open(BAK, "> $resume_dat_lin-".time.(rand(10000) % 10000).".bak");
print BAK $lin_contents;
close BAK;

foreach my $key (keys(%{$lin_decoded}))
{
next if $key eq '.fileguard';
$linhash{$key} = ${$lin_decoded}{$key};
}
}
else
{
warn "$!\nno worries yet, you don't necessarily need a $resume_dat_lin for utserver to run this script\n";
}

foreach my $key (keys(%{$win_decoded})) {
next if $key eq '.fileguard';
my $fixedkey = $key;

foreach my $dir (keys %basedirs)
{
$fixedkey =~ s/$dir/$basedirs{$dir}/i;
}

$fixedkey =~ s/\\/\//g;
next if defined $linhash{$fixedkey};

$linhash{$fixedkey} = ${$win_decoded}{$key};
foreach my $dir (keys %basedirs)
{
$linhash{$fixedkey}{path} =~ s/$dir/$basedirs{$dir}/i;
}
$linhash{$fixedkey}{path} =~ s/\\/\//g;
}

open(FIXED, "> $resume_dat_lin")
or die $!;
print FIXED bencode(\%linhash);
close FIXED;

Link to comment
Share on other sites

  • 3 years later...

I tried out this perl script but I found I needed to make some modifiecations to get it to work. Here's what I changed and what steps I took to get it to work so that when I started utserver it would continue downloading what was in process on windows:

 

1. Code mod (skip this if you don't care... modified script is at the bottom of this post):

In addition to skipping '.fileguard', I needed to skip 'rec' as well. Otherwise it crashes saying not a hash, because the rec key has a hash reference not direct hash (it was either an array ref or hash ref I can't recall).

so change the perl script such that any line like this:

next if $key eq '.fileguard';

change to

next if $key eq '.fileguard' | $key eq 'rec';

 

2. Code mod (skip this if you don't care... modified script is at the bottom of this post):

In addition to converting the 'path' key in the file, I also change the 'rootdir' key. I'll just post the full modified perl script at the end.

 

3.  Be sure to use 4 backslashes for every one windows backslash when setting up the basedirs near the top of the perl script (also don't put slash on ends). For my case, on windows my download dir is S:\torrents, but accessed from linux via  /mnt/sdrive/torrents. So I set this in the script for basedirs:

my %basedirs = (
    'S:\\\\torrents' => '/mnt/sdrive/torrents'
);

note that I didn't use the tmp directory at all. Not sure what that was for. The directories you are specifying here are where your current windows download torrent (the one or more you're trying to resume) is downloading to. (I only had 1 in process so not sure if works with multiple current in process downloads or not).

 

4. Before you actually start the server, run the perlscript on your resume.dat file. First, find this file in your windows utorrent settings folder and copy it over to where your're working on linux. Call it res.dat (not resume.dat). I didn't have a linux resume.dat file to worry about merging (which the script does) so I just made sure there was no resume.dat file in the folder where the res.dat file is (where you just copied it to). Run the perl script above passing the res.dat file as argument:

perl fixtor.pl res.dat

The script if succesful will create resume.dat. Put this file in the folder you specified as argument to utserver.

 

5.

When you run utserver you specify an argument to it called -settingspath. I just kept this the same as where I installed utserver:

/mnt/sdrive/linux/utorrent-server-alpha-v3_3/utserver -settingspath /mnt/sdrive/linux/utorrent-server-alpha-v3_3

 

I made a little script to start up utserver and launch the firefox utclient. I looks like this:

/mnt/sdrive/linux/utorrent-server-alpha-v3_3/utserver -settingspath /mnt/sdrive/linux/utorrent-server-alpha-v3_3 &
firefox http://localhost:8080/gui/web/index.html

 

That's it. It should work for you hopefully as it did me!

 

If you have any trouble, use Dumper in perl to dump out the hash autovivication contents:

use Data::Dumper qw(Dumper);     #add this at the beginning of the script near the other use statement

then down near the bottom of the script, you can do:

print Dumper %linhash;

or

print Dumper %{$win_decoded};

to see what the structure looks like

 

Here's my modified perl script version. Put it in a file called fixtor.pl or whatever.

I'll note changed lines with ######### above them:


See code next post.

Link to comment
Share on other sites

#!/usr/bin/perl

# This is a VERY basic script to help those converting from using utorrent under wine

# to migrate to the new linux port. It's likely buggy as all hell and will probably set

# your house on fire. Back your shat up before playing with it.

#use Convert::Bencode qw(bencode bdecode);

use Bencode qw(bencode bdecode);

################ utility for dumping out the contents of the hash contents

use Data::Dumper qw(Dumper);

# Change these to suit your needs. from => to in %basedirs.

# Yes, I'm a lazyass and just used . to match the annoying dos path bits rather than

# explicitly matching them.

################### in my case, on windows my download dir is S:\torrents, but accessed from linux via /mnt/sdrive/torrents

my %basedirs = (

'S:\\\\torrents' => '/mnt/sdrive/torrents'

);

unless(defined $ARGV[0])

{

print "usage: ./syncpaths.pl <path to windows/wine resume.dat>\n";

exit;

}

my $resume_dat_win = $ARGV[0];

my $resume_dat_lin = 'resume.dat';

open(RESUMEW, "< $resume_dat_win")

or die $!;

my $win_contents = do { local $/; <RESUMEW> };

close RESUMEW;

my $win_decoded = bdecode($win_contents);

my %linhash;

if(open(RESUMEL, "< $resume_dat_lin"))

{

my $lin_contents = do { local $/; <RESUMEL> };

close RESUMEL;

my $lin_decoded = bdecode($lin_contents);

open(BAK, "> $resume_dat_lin-".time.(rand(10000) % 10000).".bak");

print BAK $lin_contents;

close BAK;

foreach my $key (keys(%{$lin_decoded}))

{

############## avoid the rec key other wise crash

next if $key eq '.fileguard' | $key eq 'rec';

$linhash{$key} = ${$lin_decoded}{$key};

}

}

else

{

warn "$!\nno worries yet, you don't necessarily need a $resume_dat_lin for utserver to run this script\n";

}

################## uncomment to see what's in the res.dat file

#print Dumper %{$win_decoded};

foreach my $key (keys(%{$win_decoded})) {

################## avoid the rec key otherwise crash

next if $key eq '.fileguard' | $key eq 'rec';

my $fixedkey = $key;

foreach my $dir (keys %basedirs)

{

$fixedkey =~ s/$dir/$basedirs{$dir}/i;

}

$fixedkey =~ s/\\/\//g;

next if defined $linhash{$fixedkey};

$linhash{$fixedkey} = ${$win_decoded}{$key};

foreach my $dir (keys %basedirs)

{

$linhash{$fixedkey}{path} =~ s/$dir/$basedirs{$dir}/i;

####################### this also sets the rootdir in the file, not just the path

$linhash{$fixedkey}{rootdir} =~ s/$dir/$basedirs{$dir}/i;

}

$linhash{$fixedkey}{path} =~ s/\\/\//g;

####################### rootdir

$linhash{$fixedkey}{rootdir} =~ s/\\/\//g;

}

################## this will print out the modified file before it is written out to resume.dat

print Dumper %linhash;

open(FIXED, "> $resume_dat_lin")

or die $!;

print FIXED bencode(\%linhash);

close FIXED;

Link to comment
Share on other sites

  • 3 weeks later...

HI great script.

I was lazy when moving from windows to linux.

I basically just copied the resume.dat file to the linux server after I changed all the download and torrent directories etc. I also created the watch directory.

I then stopped all the downloads and copied all the .torrent files to the watch directory and they all started up without problems.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...