PoshCode Archive  Artifact [1249ddeef5]

Artifact 1249ddeef5763fb0d45cad0ca01b56bab376042570d2a71c28f6082d21b3829a:

  • File magnet-to-transmission.ps1 — part of check-in [575cb32fc0] at 2018-06-10 14:14:02 on branch trunk — The following script shows how to send a magnet link to a remote transmission daemon. Don’t forget to replace the $addr, $port, $user and $pass variables at the top before using it. (user: meekmaak size: 1653)

# encoding: utf-8
# api: powershell
# title: magnet to transmission
# description: The following script shows how to send a magnet link to a remote transmission daemon. Don’t forget to replace the $addr, $port, $user and $pass variables at the top before using it.
# version: 0.1
# author: meekmaak
# license: CC0
# x-poshcode-id: 6361
# x-archived: 2016-05-30T23:51:39
# x-published: 2016-05-28T12:10:00
#
#
[CmdletBinding()]
Param(
   [Parameter(Mandatory=$True)]
   [string]$magnetlink
)

#--------------------------------------------------------------------------
# replace the following items with your transmission remote settings
$addr="192.168.178.25"
$port="8111"
$user="admin"
$pass="admin"
#--------------------------------------------------------------------------

$uri="http://$($addr):$($port)/transmission/rpc"
$PWord = ConvertTo-SecureString –String $pass –AsPlainText -Force

# alternative to prompt for user/pass, use:
# $cred=Get-Credential
$cred = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $user, $PWord

try
{
	Invoke-RestMethod -Uri $uri -Credential $cred -ErrorAction SilentlyContinue
}
catch
{
}

$response=$error[0].ErrorDetails.Message
$sessionid=$response | Select-String -pattern 'X-Transmission-Session-Id\: (?<sessid>[a-zA-Z0-9]*)' | Foreach {$_.Matches.Groups[1].Value } 

#create body using backticks to escape double quotes
$body = "{`"method`":`"torrent-add`",`"arguments`":{`"filename`":`"$magnetlink`"}}"

Invoke-RestMethod -Uri $uri -Headers @{"X-Transmission-Session-Id"=$sessionid} -Credential $cred -Method Post -Body $body