feat(download-clients): add transmission (#350)

This commit is contained in:
Ludvig Lundgren 2022-07-10 18:01:58 +02:00 committed by GitHub
parent b03edbfc87
commit 7eefeb54c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 200 additions and 21 deletions

3
go.mod
View file

@ -15,6 +15,7 @@ require (
github.com/go-chi/chi v1.5.4 github.com/go-chi/chi v1.5.4
github.com/gorilla/sessions v1.2.1 github.com/gorilla/sessions v1.2.1
github.com/gosimple/slug v1.12.0 github.com/gosimple/slug v1.12.0
github.com/hekmon/transmissionrpc/v2 v2.0.1
github.com/lib/pq v1.10.4 github.com/lib/pq v1.10.4
github.com/mattn/go-shellwords v1.0.12 github.com/mattn/go-shellwords v1.0.12
github.com/moistari/rls v0.2.6 github.com/moistari/rls v0.2.6
@ -44,7 +45,9 @@ require (
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect github.com/gosimple/unidecode v1.0.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hekmon/cunits/v2 v2.1.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect github.com/huandu/xstrings v1.3.2 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect

6
go.sum
View file

@ -275,10 +275,16 @@ github.com/gosuri/uilive v0.0.0-20170323041506-ac356e6e42cd/go.mod h1:qkLSc0A5EX
github.com/gosuri/uilive v0.0.3/go.mod h1:qkLSc0A5EXSP6B04TrN4oQoxqFI7A8XvoXSlJi8cwk8= github.com/gosuri/uilive v0.0.3/go.mod h1:qkLSc0A5EXSP6B04TrN4oQoxqFI7A8XvoXSlJi8cwk8=
github.com/gosuri/uiprogress v0.0.0-20170224063937-d0567a9d84a1/go.mod h1:C1RTYn4Sc7iEyf6j8ft5dyoZ4212h8G1ol9QQluh5+0= github.com/gosuri/uiprogress v0.0.0-20170224063937-d0567a9d84a1/go.mod h1:C1RTYn4Sc7iEyf6j8ft5dyoZ4212h8G1ol9QQluh5+0=
github.com/gosuri/uiprogress v0.0.1/go.mod h1:C1RTYn4Sc7iEyf6j8ft5dyoZ4212h8G1ol9QQluh5+0= github.com/gosuri/uiprogress v0.0.1/go.mod h1:C1RTYn4Sc7iEyf6j8ft5dyoZ4212h8G1ol9QQluh5+0=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hekmon/cunits/v2 v2.1.0 h1:k6wIjc4PlacNOHwKEMBgWV2/c8jyD4eRMs5mR1BBhI0=
github.com/hekmon/cunits/v2 v2.1.0/go.mod h1:9r1TycXYXaTmEWlAIfFV8JT+Xo59U96yUJAYHxzii2M=
github.com/hekmon/transmissionrpc/v2 v2.0.1 h1:WkILCEdbNy3n/N/w7mi449waMPdH2AA1THyw7TfnN/w=
github.com/hekmon/transmissionrpc/v2 v2.0.1/go.mod h1:+s96Pkg7dIP3h2PT3fzhXPvNb3OdLryh5J8PIvQg3aA=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo= github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo=
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=

View file

@ -48,6 +48,9 @@ func (s *service) RunAction(action *domain.Action, release domain.Release) ([]st
case domain.ActionTypeQbittorrent: case domain.ActionTypeQbittorrent:
rejections, err = s.qbittorrent(*action, release) rejections, err = s.qbittorrent(*action, release)
case domain.ActionTypeTransmission:
rejections, err = s.transmission(*action, release)
case domain.ActionTypeRadarr: case domain.ActionTypeRadarr:
rejections, err = s.radarr(*action, release) rejections, err = s.radarr(*action, release)

View file

@ -0,0 +1,70 @@
package action
import (
"context"
"github.com/autobrr/autobrr/internal/domain"
"github.com/autobrr/autobrr/pkg/errors"
"github.com/hekmon/transmissionrpc/v2"
)
func (s *service) transmission(action domain.Action, release domain.Release) ([]string, error) {
s.log.Debug().Msgf("action Transmission: %v", action.Name)
var err error
// get client for action
client, err := s.clientSvc.FindByID(context.TODO(), action.ClientID)
if err != nil {
s.log.Error().Stack().Err(err).Msgf("error finding client: %v", action.ClientID)
return nil, err
}
if client == nil {
return nil, errors.New("could not find client by id: %v", action.ClientID)
}
var rejections []string
if release.TorrentTmpFile == "" {
err = release.DownloadTorrentFile()
if err != nil {
s.log.Error().Err(err).Msgf("could not download torrent file for release: %v", release.TorrentName)
return nil, err
}
}
tbt, err := transmissionrpc.New(client.Host, client.Username, client.Password, &transmissionrpc.AdvancedConfig{
HTTPS: client.TLS,
Port: uint16(client.Port),
})
if err != nil {
return nil, errors.Wrap(err, "error logging into client: %v", client.Host)
}
b64, err := transmissionrpc.File2Base64(release.TorrentTmpFile)
if err != nil {
return nil, errors.Wrap(err, "cant encode file %v into base64", release.TorrentTmpFile)
}
payload := transmissionrpc.TorrentAddPayload{
MetaInfo: &b64,
}
if action.SavePath != "" {
payload.DownloadDir = &action.SavePath
}
if action.Paused {
payload.Paused = &action.Paused
}
// Prepare and send payload
torrent, err := tbt.TorrentAdd(context.TODO(), payload)
if err != nil {
return nil, errors.Wrap(err, "could not add torrent %v to client: %v", release.TorrentTmpFile, client.Host)
}
s.log.Info().Msgf("torrent with hash %v successfully added to client: '%v'", torrent.HashString, client.Name)
return rejections, nil
}

View file

@ -47,15 +47,16 @@ type Action struct {
type ActionType string type ActionType string
const ( const (
ActionTypeTest ActionType = "TEST" ActionTypeTest ActionType = "TEST"
ActionTypeExec ActionType = "EXEC" ActionTypeExec ActionType = "EXEC"
ActionTypeQbittorrent ActionType = "QBITTORRENT" ActionTypeQbittorrent ActionType = "QBITTORRENT"
ActionTypeDelugeV1 ActionType = "DELUGE_V1" ActionTypeDelugeV1 ActionType = "DELUGE_V1"
ActionTypeDelugeV2 ActionType = "DELUGE_V2" ActionTypeDelugeV2 ActionType = "DELUGE_V2"
ActionTypeWatchFolder ActionType = "WATCH_FOLDER" ActionTypeTransmission ActionType = "TRANSMISSION"
ActionTypeWebhook ActionType = "WEBHOOK" ActionTypeWatchFolder ActionType = "WATCH_FOLDER"
ActionTypeRadarr ActionType = "RADARR" ActionTypeWebhook ActionType = "WEBHOOK"
ActionTypeSonarr ActionType = "SONARR" ActionTypeRadarr ActionType = "RADARR"
ActionTypeLidarr ActionType = "LIDARR" ActionTypeSonarr ActionType = "SONARR"
ActionTypeWhisparr ActionType = "WHISPARR" ActionTypeLidarr ActionType = "LIDARR"
ActionTypeWhisparr ActionType = "WHISPARR"
) )

View file

@ -46,11 +46,12 @@ type BasicAuth struct {
type DownloadClientType string type DownloadClientType string
const ( const (
DownloadClientTypeQbittorrent DownloadClientType = "QBITTORRENT" DownloadClientTypeQbittorrent DownloadClientType = "QBITTORRENT"
DownloadClientTypeDelugeV1 DownloadClientType = "DELUGE_V1" DownloadClientTypeDelugeV1 DownloadClientType = "DELUGE_V1"
DownloadClientTypeDelugeV2 DownloadClientType = "DELUGE_V2" DownloadClientTypeDelugeV2 DownloadClientType = "DELUGE_V2"
DownloadClientTypeRadarr DownloadClientType = "RADARR" DownloadClientTypeTransmission DownloadClientType = "TRANSMISSION"
DownloadClientTypeSonarr DownloadClientType = "SONARR" DownloadClientTypeRadarr DownloadClientType = "RADARR"
DownloadClientTypeLidarr DownloadClientType = "LIDARR" DownloadClientTypeSonarr DownloadClientType = "SONARR"
DownloadClientTypeWhisparr DownloadClientType = "WHISPARR" DownloadClientTypeLidarr DownloadClientType = "LIDARR"
DownloadClientTypeWhisparr DownloadClientType = "WHISPARR"
) )

View file

@ -1,6 +1,7 @@
package download_client package download_client
import ( import (
"context"
"time" "time"
"github.com/autobrr/autobrr/internal/domain" "github.com/autobrr/autobrr/internal/domain"
@ -12,6 +13,7 @@ import (
"github.com/autobrr/autobrr/pkg/whisparr" "github.com/autobrr/autobrr/pkg/whisparr"
delugeClient "github.com/gdm85/go-libdeluge" delugeClient "github.com/gdm85/go-libdeluge"
"github.com/hekmon/transmissionrpc/v2"
) )
func (s *service) testConnection(client domain.DownloadClient) error { func (s *service) testConnection(client domain.DownloadClient) error {
@ -22,6 +24,9 @@ func (s *service) testConnection(client domain.DownloadClient) error {
case domain.DownloadClientTypeDelugeV1, domain.DownloadClientTypeDelugeV2: case domain.DownloadClientTypeDelugeV1, domain.DownloadClientTypeDelugeV2:
return s.testDelugeConnection(client) return s.testDelugeConnection(client)
case domain.DownloadClientTypeTransmission:
return s.testTransmissionConnection(client)
case domain.DownloadClientTypeRadarr: case domain.DownloadClientTypeRadarr:
return s.testRadarrConnection(client) return s.testRadarrConnection(client)
@ -114,6 +119,31 @@ func (s *service) testDelugeConnection(client domain.DownloadClient) error {
return nil return nil
} }
func (s *service) testTransmissionConnection(client domain.DownloadClient) error {
tbt, err := transmissionrpc.New(client.Host, client.Username, client.Password, &transmissionrpc.AdvancedConfig{
HTTPS: client.TLS,
Port: uint16(client.Port),
})
if err != nil {
return errors.Wrap(err, "error logging into client: %v", client.Host)
}
ok, version, _, err := tbt.RPCVersion(context.TODO())
if err != nil {
return errors.Wrap(err, "error getting rpc info: %v", client.Host)
}
if !ok {
return errors.Wrap(err, "error getting rpc info: %v", client.Host)
}
s.log.Debug().Msgf("test client connection for Transmission: got version: %v", version)
s.log.Debug().Msgf("test client connection for Transmission: success")
return nil
}
func (s *service) testRadarrConnection(client domain.DownloadClient) error { func (s *service) testRadarrConnection(client domain.DownloadClient) error {
r := radarr.New(radarr.Config{ r := radarr.New(radarr.Config{
Hostname: client.Host, Hostname: client.Host,

View file

@ -176,6 +176,11 @@ export const DownloadClientTypeOptions: RadioFieldsetOption[] = [
description: "Add torrents directly to Deluge 2", description: "Add torrents directly to Deluge 2",
value: "DELUGE_V2" value: "DELUGE_V2"
}, },
{
label: "Transmission",
description: "Add torrents directly to Transmission",
value: "TRANSMISSION"
},
{ {
label: "Radarr", label: "Radarr",
description: "Send to Radarr and let it decide", description: "Send to Radarr and let it decide",
@ -202,6 +207,7 @@ export const DownloadClientTypeNameMap: Record<DownloadClientType | string, stri
"DELUGE_V1": "Deluge v1", "DELUGE_V1": "Deluge v1",
"DELUGE_V2": "Deluge v2", "DELUGE_V2": "Deluge v2",
"QBITTORRENT": "qBittorrent", "QBITTORRENT": "qBittorrent",
"TRANSMISSION": "Transmission",
"RADARR": "Radarr", "RADARR": "Radarr",
"SONARR": "Sonarr", "SONARR": "Sonarr",
"LIDARR": "Lidarr", "LIDARR": "Lidarr",
@ -216,6 +222,7 @@ export const ActionTypeOptions: RadioFieldsetOption[] = [
{ label: "qBittorrent", description: "Add torrents directly to qBittorrent", value: "QBITTORRENT" }, { label: "qBittorrent", description: "Add torrents directly to qBittorrent", value: "QBITTORRENT" },
{ label: "Deluge", description: "Add torrents directly to Deluge", value: "DELUGE_V1" }, { label: "Deluge", description: "Add torrents directly to Deluge", value: "DELUGE_V1" },
{ label: "Deluge v2", description: "Add torrents directly to Deluge 2", value: "DELUGE_V2" }, { label: "Deluge v2", description: "Add torrents directly to Deluge 2", value: "DELUGE_V2" },
{ label: "Transmission", description: "Add torrents directly to Transmission", value: "TRANSMISSION" },
{ label: "Radarr", description: "Send to Radarr and let it decide", value: "RADARR" }, { label: "Radarr", description: "Send to Radarr and let it decide", value: "RADARR" },
{ label: "Sonarr", description: "Send to Sonarr and let it decide", value: "SONARR" }, { label: "Sonarr", description: "Send to Sonarr and let it decide", value: "SONARR" },
{ label: "Lidarr", description: "Send to Lidarr and let it decide", value: "LIDARR" }, { label: "Lidarr", description: "Send to Lidarr and let it decide", value: "LIDARR" },
@ -230,6 +237,7 @@ export const ActionTypeNameMap = {
"DELUGE_V1": "Deluge v1", "DELUGE_V1": "Deluge v1",
"DELUGE_V2": "Deluge v2", "DELUGE_V2": "Deluge v2",
"QBITTORRENT": "qBittorrent", "QBITTORRENT": "qBittorrent",
"TRANSMISSION": "Transmission",
"RADARR": "Radarr", "RADARR": "Radarr",
"SONARR": "Sonarr", "SONARR": "Sonarr",
"LIDARR": "Lidarr", "LIDARR": "Lidarr",

View file

@ -13,8 +13,7 @@ import { toast } from "react-hot-toast";
import Toast from "../../components/notifications/Toast"; import Toast from "../../components/notifications/Toast";
import { useToggle } from "../../hooks/hooks"; import { useToggle } from "../../hooks/hooks";
import { DeleteModal } from "../../components/modals"; import { DeleteModal } from "../../components/modals";
import { NumberFieldWide, PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "../../components/inputs/input_wide"; import { NumberFieldWide, PasswordFieldWide, SwitchGroupWide, TextFieldWide, RadioFieldsetWide } from "../../components/inputs";
import { RadioFieldsetWide } from "../../components/inputs/radio";
import DownloadClient from "../../screens/settings/DownloadClient"; import DownloadClient from "../../screens/settings/DownloadClient";
interface InitialValuesSettings { interface InitialValuesSettings {
@ -137,6 +136,33 @@ function FormFieldsQbit() {
); );
} }
function FormFieldsTransmission() {
const {
values: { tls }
} = useFormikContext<InitialValues>();
return (
<Fragment>
<TextFieldWide name="host" label="Host" help="Eg. client.domain.ltd, domain.ltd/client, domain.ltd"/>
<NumberFieldWide name="port" label="Port" help="Port for Transmission"/>
<div className="py-6 px-6 space-y-6 sm:py-0 sm:space-y-0 sm:divide-y sm:divide-gray-200 dark:divide-gray-700">
<SwitchGroupWide name="tls" label="TLS"/>
{tls && (
<Fragment>
<SwitchGroupWide name="tls_skip_verify" label="Skip TLS verification (insecure)"/>
</Fragment>
)}
</div>
<TextFieldWide name="username" label="Username"/>
<PasswordFieldWide name="password" label="Password"/>
</Fragment>
);
}
export interface componentMapType { export interface componentMapType {
[key: string]: React.ReactElement; [key: string]: React.ReactElement;
} }
@ -145,6 +171,7 @@ export const componentMap: componentMapType = {
DELUGE_V1: <FormFieldsDefault/>, DELUGE_V1: <FormFieldsDefault/>,
DELUGE_V2: <FormFieldsDefault/>, DELUGE_V2: <FormFieldsDefault/>,
QBITTORRENT: <FormFieldsQbit/>, QBITTORRENT: <FormFieldsQbit/>,
TRANSMISSION: <FormFieldsTransmission/>,
RADARR: <FormFieldsArr/>, RADARR: <FormFieldsArr/>,
SONARR: <FormFieldsArr/>, SONARR: <FormFieldsArr/>,
LIDARR: <FormFieldsArr/>, LIDARR: <FormFieldsArr/>,
@ -221,7 +248,7 @@ function FormFieldsRules() {
export const rulesComponentMap: componentMapType = { export const rulesComponentMap: componentMapType = {
DELUGE_V1: <FormFieldsRulesBasic/>, DELUGE_V1: <FormFieldsRulesBasic/>,
DELUGE_V2: <FormFieldsRulesBasic/>, DELUGE_V2: <FormFieldsRulesBasic/>,
QBITTORRENT: <FormFieldsRules/> QBITTORRENT: <FormFieldsRules/>,
}; };
interface formButtonsProps { interface formButtonsProps {

View file

@ -819,6 +819,35 @@ function FilterActionsItem({ action, clients, idx, remove }: FilterActionsItemPr
</div> </div>
</div> </div>
); );
case "TRANSMISSION":
return (
<div>
<div className="mt-6 grid grid-cols-12 gap-6">
<DownloadClientSelect
name={`actions.${idx}.client_id`}
action={action}
clients={clients}
/>
<div className="col-span-12 sm:col-span-6">
<TextField
name={`actions.${idx}.save_path`}
label="Save path"
columns={6}
/>
</div>
</div>
<div className="mt-6 grid grid-cols-12 gap-6">
<div className="col-span-6">
<SwitchGroup
name={`actions.${idx}.paused`}
label="Add paused"
/>
</div>
</div>
</div>
);
case "RADARR": case "RADARR":
case "SONARR": case "SONARR":
case "LIDARR": case "LIDARR":

View file

@ -2,6 +2,7 @@ type DownloadClientType =
"QBITTORRENT" | "QBITTORRENT" |
"DELUGE_V1" | "DELUGE_V1" |
"DELUGE_V2" | "DELUGE_V2" |
"TRANSMISSION" |
"RADARR" | "RADARR" |
"SONARR" | "SONARR" |
"LIDARR" | "LIDARR" |