Adding Magnet URL from Text-based File

General support for problems installing or using Deluge
Post Reply
bzowk
New User
New User
Posts: 3
Joined: Mon May 29, 2017 3:57 am

Adding Magnet URL from Text-based File

Post by bzowk »

Hey Guys -

I currently use Deluge in Windows - well, the thin client - deluged running in the background as I typically access it via the web interface. I also use NZBHydra2 frequently which is hosted on a different system. As I cannot add torrent search results directly, I have it set up to save selected results to a Black Hole folder. Unfortunately, many of these are magnets - not torrents - therefore save the result as a "*.MAGNET" file which is simply a text file containing the magnet's URL.

While it would be ideal for Deluge to be able to automatically add these files such as it does .torrents, I'm sure that support won't come soon. Therefore, I'm trying to write a script which may be able to add it. The only thing is that I cannot find a way to add a magnet URL with Deluge using a command line.

Any suggestions?

Potential Methods
Below are a couple of methods I thought may work and explain what I'm trying to do
- Find Way for Deluge AutoAdd to Add .MAGNET Files (The way it does .torrent files)
1. Easy - just write a script to move .MAGNET files to folder Deluge currently monitors

- Script to add Magnet Using Deluge CLI in Windows (if such exists)
1. Monitor BlackHole folder for new .MAGNET files
2. Move any new .MAGNET to system hosting Deluge
3. Set variable to URL in .MAGNET
4. Use Deluge's CLI to add URL with a specific label (so it saves to a specific path)

- Script Using "Remote Torrent Adder" Chrome Plugin (If no Deluge CLI for Windows exists)
1. Monitor BlackHole folder for new .MAGNET files
2. Move any new .MAGNET to system hosting Deluge
3. Set variable to URL in .MAGNET
4. Silently open URL in Chrome tab (which should in turn automatically add it to Deluge)
bzowk
New User
New User
Posts: 3
Joined: Mon May 29, 2017 3:57 am

Re: Adding Magnet URL from Text-based File

Post by bzowk »

Nevermind... I figured it out on my own :)

If anyone else is interested, below is the script. Once started, it monitors the folder "D:\Blackhole" for ".magnet" files (each containing a magnet URL.) Once one is added, it saves the content (URL) to a variable, adds the URL to Deluged, then deletes the .magnet file. To unmonitor the folder, execute "Unregister-Event MagnetMonitor" in PowerShell.

Code: Select all

$folder = "D:\Blackhole"
$filter = "*.MAGNET"
$Watcher = New-Object IO.FileSystemWatcher $folder, $filter -Property @{ 
    IncludeSubdirectories = $false
    NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
}
$onCreated = Register-ObjectEvent $Watcher Created -SourceIdentifier MagnetMonitor -Action {
   $path = $Event.SourceEventArgs.FullPath
   $name = $Event.SourceEventArgs.Name
   $changeType = $Event.SourceEventArgs.ChangeType
   $timeStamp = $Event.TimeGenerated

#Save file contents to variable
$content = [IO.File]::ReadAllText("$path")

#Delete File
Remove-Item –path $path

#Add to Deluge
start-process "C:\Program Files (x86)\Deluge\deluge-console.exe" -ArgumentList "add $content"
}
Enjoy!
Post Reply