help with script

Jan 25, 2013 at 1:20 PM

I'm using the following to either continue seeding, or, stop & remove the .torrent file

I'm just not sure how to perform the Remove torrent command. Can you help? Sorry for the question, this is my first attempt at powershell scripting!

#Load UtorrentAPI and connect to Utorrent WebUI
$utorrentdll = 'P:/UTorrentAPI.dll'
[Reflection.Assembly]::LoadFile($utorrentdll) | Out-Null

#change connection string as appropriate
$utorrentclient = New-Object -TypeName UTorrentAPI.UTorrentClient -ArgumentList "http://localhost:37141/gui","ut","ut"

#get a list of all torrents
$torrentlist=$utorrentclient.Torrents

foreach ($torrent in $torrentlist)
{

#check for finished torrents with a label of "keep"
if ($torrent.Label -eq "keep" -and $torrent.RemainingBytes -eq "0")
{
#keeping this - place holder for other things
}

#check for finished torrents with a label that isn't "keep"
if ($torrent.Label -ne "keep" -and $torrent.RemainingBytes -eq "0")
{
#stop torrent and delete .torrent file

$thisTorrent = $torrent.Hash
$utorrentclient.Torrents.Remove($thisTorrent,Data)
#remove .torrent
}

}

Jan 30, 2013 at 11:56 AM

efPob,

I don't know much about Powershell so I'm afraid I can't help you with your script.

 

However, I can tell you that there is a bug with uTorrentClientAPI where the RemoveTorrent option (i.e. to remove the torrenfile) doesn't work.

(It returns an error in C# for example)

 

I'm not sure if it's a bug with the API itself or a bug with uTorrent program.

I'm using uTorrent 2.2.1 so it may not be an issue on other versions of uTorrent.

 

Good luck with that!

 

 

Coordinator
Jan 31, 2013 at 3:16 PM
Hi efPob,

It would be nice if you posted the error you were receiving. However, I suspect that you might be hitting an error because Remove expects an enum of TorrentRemovalOptions. I'm not sure if the literal can be coerced into an enum value. If you change the last lines to this, does it work?
#stop torrent and delete .torrent file

# $thisTorrent = $torrent.Hash <-- this line isn't really needed.  You can remove a torrent directly
$utorrentclient.Torrents.Remove($torrent, [UTorrentAPI.TorrentRemovalOptions]::Data)
#remove .torrent
FrancisChung, is there already a bug on the issue you described?

-Mike
Jan 31, 2013 at 4:03 PM
I think it's been there a while (according to the comments) and the reason why I might not have brought it up is because it might be a uTorrent 2.2.1 bug and not present on the later clients.
I believe it was only the TorrentRemovalOption of both Torrent and Data that was problematic.

I'm doing a workaround of deleting only the Data via uTorrentAPI and deleting the .Torrent file manually (& having to guess at the file name structure as I don't believe the name of the .Torrent file is stored anywhere)