mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(download-clients): add transmission (#350)
This commit is contained in:
parent
b03edbfc87
commit
7eefeb54c1
11 changed files with 200 additions and 21 deletions
3
go.mod
3
go.mod
|
@ -15,6 +15,7 @@ require (
|
|||
github.com/go-chi/chi v1.5.4
|
||||
github.com/gorilla/sessions v1.2.1
|
||||
github.com/gosimple/slug v1.12.0
|
||||
github.com/hekmon/transmissionrpc/v2 v2.0.1
|
||||
github.com/lib/pq v1.10.4
|
||||
github.com/mattn/go-shellwords v1.0.12
|
||||
github.com/moistari/rls v0.2.6
|
||||
|
@ -44,7 +45,9 @@ require (
|
|||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/gorilla/securecookie v1.1.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/hekmon/cunits/v2 v2.1.0 // indirect
|
||||
github.com/huandu/xstrings v1.3.2 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
|
||||
|
|
6
go.sum
6
go.sum
|
@ -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/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/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.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/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/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo=
|
||||
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
|
||||
|
|
|
@ -48,6 +48,9 @@ func (s *service) RunAction(action *domain.Action, release domain.Release) ([]st
|
|||
case domain.ActionTypeQbittorrent:
|
||||
rejections, err = s.qbittorrent(*action, release)
|
||||
|
||||
case domain.ActionTypeTransmission:
|
||||
rejections, err = s.transmission(*action, release)
|
||||
|
||||
case domain.ActionTypeRadarr:
|
||||
rejections, err = s.radarr(*action, release)
|
||||
|
||||
|
|
70
internal/action/transmission.go
Normal file
70
internal/action/transmission.go
Normal 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
|
||||
}
|
|
@ -52,6 +52,7 @@ const (
|
|||
ActionTypeQbittorrent ActionType = "QBITTORRENT"
|
||||
ActionTypeDelugeV1 ActionType = "DELUGE_V1"
|
||||
ActionTypeDelugeV2 ActionType = "DELUGE_V2"
|
||||
ActionTypeTransmission ActionType = "TRANSMISSION"
|
||||
ActionTypeWatchFolder ActionType = "WATCH_FOLDER"
|
||||
ActionTypeWebhook ActionType = "WEBHOOK"
|
||||
ActionTypeRadarr ActionType = "RADARR"
|
||||
|
|
|
@ -49,6 +49,7 @@ const (
|
|||
DownloadClientTypeQbittorrent DownloadClientType = "QBITTORRENT"
|
||||
DownloadClientTypeDelugeV1 DownloadClientType = "DELUGE_V1"
|
||||
DownloadClientTypeDelugeV2 DownloadClientType = "DELUGE_V2"
|
||||
DownloadClientTypeTransmission DownloadClientType = "TRANSMISSION"
|
||||
DownloadClientTypeRadarr DownloadClientType = "RADARR"
|
||||
DownloadClientTypeSonarr DownloadClientType = "SONARR"
|
||||
DownloadClientTypeLidarr DownloadClientType = "LIDARR"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package download_client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
|
@ -12,6 +13,7 @@ import (
|
|||
"github.com/autobrr/autobrr/pkg/whisparr"
|
||||
|
||||
delugeClient "github.com/gdm85/go-libdeluge"
|
||||
"github.com/hekmon/transmissionrpc/v2"
|
||||
)
|
||||
|
||||
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:
|
||||
return s.testDelugeConnection(client)
|
||||
|
||||
case domain.DownloadClientTypeTransmission:
|
||||
return s.testTransmissionConnection(client)
|
||||
|
||||
case domain.DownloadClientTypeRadarr:
|
||||
return s.testRadarrConnection(client)
|
||||
|
||||
|
@ -114,6 +119,31 @@ func (s *service) testDelugeConnection(client domain.DownloadClient) error {
|
|||
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 {
|
||||
r := radarr.New(radarr.Config{
|
||||
Hostname: client.Host,
|
||||
|
|
|
@ -176,6 +176,11 @@ export const DownloadClientTypeOptions: RadioFieldsetOption[] = [
|
|||
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",
|
||||
|
@ -202,6 +207,7 @@ export const DownloadClientTypeNameMap: Record<DownloadClientType | string, stri
|
|||
"DELUGE_V1": "Deluge v1",
|
||||
"DELUGE_V2": "Deluge v2",
|
||||
"QBITTORRENT": "qBittorrent",
|
||||
"TRANSMISSION": "Transmission",
|
||||
"RADARR": "Radarr",
|
||||
"SONARR": "Sonarr",
|
||||
"LIDARR": "Lidarr",
|
||||
|
@ -216,6 +222,7 @@ export const ActionTypeOptions: RadioFieldsetOption[] = [
|
|||
{ label: "qBittorrent", description: "Add torrents directly to qBittorrent", value: "QBITTORRENT" },
|
||||
{ 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: "Transmission", description: "Add torrents directly to Transmission", value: "TRANSMISSION" },
|
||||
{ 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: "Lidarr", description: "Send to Lidarr and let it decide", value: "LIDARR" },
|
||||
|
@ -230,6 +237,7 @@ export const ActionTypeNameMap = {
|
|||
"DELUGE_V1": "Deluge v1",
|
||||
"DELUGE_V2": "Deluge v2",
|
||||
"QBITTORRENT": "qBittorrent",
|
||||
"TRANSMISSION": "Transmission",
|
||||
"RADARR": "Radarr",
|
||||
"SONARR": "Sonarr",
|
||||
"LIDARR": "Lidarr",
|
||||
|
|
|
@ -13,8 +13,7 @@ import { toast } from "react-hot-toast";
|
|||
import Toast from "../../components/notifications/Toast";
|
||||
import { useToggle } from "../../hooks/hooks";
|
||||
import { DeleteModal } from "../../components/modals";
|
||||
import { NumberFieldWide, PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "../../components/inputs/input_wide";
|
||||
import { RadioFieldsetWide } from "../../components/inputs/radio";
|
||||
import { NumberFieldWide, PasswordFieldWide, SwitchGroupWide, TextFieldWide, RadioFieldsetWide } from "../../components/inputs";
|
||||
import DownloadClient from "../../screens/settings/DownloadClient";
|
||||
|
||||
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 {
|
||||
[key: string]: React.ReactElement;
|
||||
}
|
||||
|
@ -145,6 +171,7 @@ export const componentMap: componentMapType = {
|
|||
DELUGE_V1: <FormFieldsDefault/>,
|
||||
DELUGE_V2: <FormFieldsDefault/>,
|
||||
QBITTORRENT: <FormFieldsQbit/>,
|
||||
TRANSMISSION: <FormFieldsTransmission/>,
|
||||
RADARR: <FormFieldsArr/>,
|
||||
SONARR: <FormFieldsArr/>,
|
||||
LIDARR: <FormFieldsArr/>,
|
||||
|
@ -221,7 +248,7 @@ function FormFieldsRules() {
|
|||
export const rulesComponentMap: componentMapType = {
|
||||
DELUGE_V1: <FormFieldsRulesBasic/>,
|
||||
DELUGE_V2: <FormFieldsRulesBasic/>,
|
||||
QBITTORRENT: <FormFieldsRules/>
|
||||
QBITTORRENT: <FormFieldsRules/>,
|
||||
};
|
||||
|
||||
interface formButtonsProps {
|
||||
|
|
|
@ -809,6 +809,35 @@ function FilterActionsItem({ action, clients, idx, remove }: FilterActionsItemPr
|
|||
/>
|
||||
</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 "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
|
||||
|
|
1
web/src/types/Download.d.ts
vendored
1
web/src/types/Download.d.ts
vendored
|
@ -2,6 +2,7 @@ type DownloadClientType =
|
|||
"QBITTORRENT" |
|
||||
"DELUGE_V1" |
|
||||
"DELUGE_V2" |
|
||||
"TRANSMISSION" |
|
||||
"RADARR" |
|
||||
"SONARR" |
|
||||
"LIDARR" |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue