mirror of
https://github.com/JackDallas/Premiumizearr.git
synced 2026-01-04 11:53:29 +01:00
Compare commits
27 Commits
2ecd9665b5
...
v1.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c3d0dc8c4 | ||
|
|
35dd81c204 | ||
|
|
4512262e73 | ||
|
|
ef1cb2978d | ||
|
|
25b8431f7e | ||
|
|
0008b80df4 | ||
|
|
c80fc3149d | ||
|
|
00bf4e1966 | ||
|
|
419854a757 | ||
|
|
e19b49c9c8 | ||
|
|
6c0c53d029 | ||
|
|
ba9476cb34 | ||
|
|
27534fe932 | ||
|
|
73622eda17 | ||
|
|
3dff845fd2 | ||
|
|
74c49799eb | ||
|
|
d19606c4dd | ||
|
|
f1d66d9532 | ||
|
|
5d02813066 | ||
|
|
226b2067ff | ||
|
|
27037a9621 | ||
|
|
fd371c38d9 | ||
|
|
26c9a5e07a | ||
|
|
dfe64f0c56 | ||
|
|
8f112500cc | ||
|
|
395083f32f | ||
|
|
8dd342a7a5 |
18
.github/workflows/build.yml
vendored
18
.github/workflows/build.yml
vendored
@@ -9,6 +9,7 @@ on:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -28,7 +29,7 @@ jobs:
|
||||
|
||||
- name: Build
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
if: ! startsWith(github.ref, 'refs/tags/')
|
||||
if: startsWith(github.ref, 'refs/tags/') == false
|
||||
with:
|
||||
distribution: goreleaser
|
||||
version: latest
|
||||
@@ -36,6 +37,12 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Release
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
@@ -44,4 +51,11 @@ jobs:
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
|
||||
- name: Upload assets
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: artifacts
|
||||
path: dist/
|
||||
|
||||
@@ -48,6 +48,8 @@ nfpms:
|
||||
# Defaults to `ProjectName`.
|
||||
package_name: premiumizearr
|
||||
|
||||
bindir: /opt/premiumizearrd
|
||||
|
||||
# Your app's vendor.
|
||||
# Default is empty.
|
||||
vendor: Jack Dallas.
|
||||
@@ -75,6 +77,33 @@ nfpms:
|
||||
contents:
|
||||
# Basic file that applies to all packagers
|
||||
- src: build/static/*
|
||||
dst: /usr/local/bin/static/
|
||||
dst: /opt/premiumizearrd/static/
|
||||
- src: init/premiumizearrd.service
|
||||
dst: /etc/systemd/system/
|
||||
dst: /etc/systemd/system/premiumizearrd.service
|
||||
scripts:
|
||||
postinstall: "scripts/postinstall.sh"
|
||||
|
||||
dockers:
|
||||
-
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
|
||||
image_templates:
|
||||
- "ghcr.io/jackdallas/premiumizearr:{{ .Tag }}"
|
||||
- "ghcr.io/jackdallas/premiumizearr:v{{ .Major }}"
|
||||
- "ghcr.io/jackdallas/premiumizearr:v{{ .Major }}.{{ .Minor }}"
|
||||
- "ghcr.io/jackdallas/premiumizearr:latest"
|
||||
|
||||
skip_push: auto
|
||||
use: docker
|
||||
|
||||
build_flag_templates:
|
||||
- "--pull"
|
||||
- "--label=org.opencontainers.image.created={{.Date}}"
|
||||
- "--label=org.opencontainers.image.title={{.ProjectName}}"
|
||||
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
|
||||
- "--label=org.opencontainers.image.version={{.Version}}"
|
||||
- "--platform=linux/amd64"
|
||||
|
||||
extra_files:
|
||||
- build/static/
|
||||
|
||||
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM ubuntu:latest
|
||||
|
||||
RUN apt update && \
|
||||
apt install openssl -y && \
|
||||
apt install ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /opt/app/
|
||||
|
||||
COPY premiumizearrd /opt/app/
|
||||
COPY build/static /opt/app/static
|
||||
|
||||
EXPOSE 8182
|
||||
|
||||
ENTRYPOINT [ "/opt/app/premiumizearrd" ]
|
||||
80
README.md
80
README.md
@@ -1,11 +1,81 @@
|
||||
# premiumizearr
|
||||
# Premiumizearr
|
||||
|
||||
## Features
|
||||
|
||||
- Monitor blackhole directory to push `.magnet` and `.nzb` to Premiumize.me
|
||||
- Monitor and download Premiumize.me transfers
|
||||
- Mark transfers as failed in sonarr
|
||||
- Monitor and download Premiumize.me transfers (web ui on default port 8182)
|
||||
- Mark transfers as failed in Radarr & Sonarr
|
||||
|
||||
## Up Next
|
||||
## Support the project by using my invite code
|
||||
|
||||
- Radarr support
|
||||
[Invite Code](https://www.premiumize.me/ref/446038083)
|
||||
|
||||
## Install
|
||||
|
||||
[Grab the latest release artifact links here](https://github.com/JackDallas/Premiumizearr/releases/)
|
||||
|
||||
### Binary
|
||||
|
||||
```
|
||||
wget https://github.com/JackDallas/Premiumizearr/releases/download/x.x.x/Premiumizearr_x.x.x_linux_amd64.tar.gz
|
||||
tar xf Premiumizearr_x.x.x.x_linux_amd64.tar.gz
|
||||
cd Premiumizearr_x.x.x.x_linux_amd64
|
||||
sudo mkdir /opt/premiumizearrd/
|
||||
sudo cp -r premiumizearrd static/ /opt/premiumizearrd/
|
||||
sudo cp premiumizearrd /etc/systemd/system/
|
||||
sudo systemctl-reload
|
||||
sudo systemctl enable premiumizearrd.service
|
||||
sudo systemctl start premiumizearrd.service
|
||||
```
|
||||
|
||||
### deb file
|
||||
|
||||
```
|
||||
wget https://github.com/JackDallas/Premiumizearr/releases/download/x.x.x/premiumizearr_x.x.x._linux_amd64.deb
|
||||
sudo dpkg -i premiumizearr_x.x.x.x_linux_amd64.deb
|
||||
```
|
||||
|
||||
### Docker
|
||||
|
||||
[Docker images are listed here](https://github.com/jackdallas/Premiumizearr/pkgs/container/premiumizearr)
|
||||
|
||||
`docker run ghcr.io/jackdallas/premiumizearr:latest /host/config.yaml:/opt/app/config.yaml -v /host/downloads:/downloads -v /host/blackhole:/blackhole`
|
||||
|
||||
You'll need to then point your config at `/blackhole` and `/downloads` (config explained more below)
|
||||
|
||||
## Setup
|
||||
|
||||
### Premiumizearrd
|
||||
|
||||
Edit the config file at `/opt/premiumizearrd/config.yml`
|
||||
|
||||
`Arrs:` A list of *Arr clients you wish to connect to in the format`
|
||||
|
||||
```
|
||||
- Name: "Sonarr 1"
|
||||
URL: http://127.0.0.1:8989
|
||||
APIKey: xxxxxxx
|
||||
Type: Sonarr
|
||||
```
|
||||
|
||||
Note: Type is either `Sonarr` or `Radarr` with a capital letter
|
||||
|
||||
`PremiumizemeAPIKey` API key for your [premiumize.me](https://www.premiumize.me) account
|
||||
|
||||
`BlackholeDirectory` Path to Directory the Arr's will put magnet/torrent/nzb files in
|
||||
|
||||
`DownloadsDirectory` Path for Premiumizearr to download media files to, that the Arr's watch for new media
|
||||
|
||||
`UnzipDirectory` Path for Premiumizearr to use to temporarily unzip downloads before moving, leave blank and a path in temp will me made
|
||||
|
||||
`bindIP` IP the web server binds to
|
||||
|
||||
`bindPort` Port the web server binds to
|
||||
|
||||
### Sonarr/Radarr
|
||||
|
||||
- Go to your Arr's `Download Client` settings page
|
||||
|
||||
- Add a new Torrent Blackhole client, set the `Torrent Folder` to the previously set `BlackholeDirectory` location, set the `Watch Folder` to the previously set `DownloadsDirectory` location
|
||||
|
||||
- Add a new Usenet Blackhole client, set the `Nzb Folder` to the previously set `BlackholeDirectory` location, set the `Watch Folder` to the previously set `DownloadsDirectory` location
|
||||
|
||||
@@ -2,8 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/jackdallas/premiumizearr/internal/arr"
|
||||
@@ -11,6 +9,7 @@ import (
|
||||
"github.com/jackdallas/premiumizearr/internal/service"
|
||||
"github.com/jackdallas/premiumizearr/internal/web_service"
|
||||
"github.com/jackdallas/premiumizearr/pkg/premiumizeme"
|
||||
"github.com/orandin/lumberjackrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golift.io/starr"
|
||||
"golift.io/starr/radarr"
|
||||
@@ -33,15 +32,43 @@ func main() {
|
||||
lvl = log.InfoLevel
|
||||
}
|
||||
log.SetLevel(lvl)
|
||||
hook, err := lumberjackrus.NewHook(
|
||||
&lumberjackrus.LogFile{
|
||||
Filename: "/opt/premiumizearrd/premiumizearr.general.log",
|
||||
MaxSize: 100,
|
||||
MaxBackups: 1,
|
||||
MaxAge: 1,
|
||||
Compress: false,
|
||||
LocalTime: false,
|
||||
},
|
||||
log.InfoLevel,
|
||||
&log.TextFormatter{},
|
||||
&lumberjackrus.LogFileOpts{
|
||||
log.InfoLevel: &lumberjackrus.LogFile{
|
||||
Filename: "/opt/premiumizearrd/premiumizearr.info.log",
|
||||
MaxSize: 100,
|
||||
MaxBackups: 1,
|
||||
MaxAge: 1,
|
||||
Compress: false,
|
||||
LocalTime: false,
|
||||
},
|
||||
log.ErrorLevel: &lumberjackrus.LogFile{
|
||||
Filename: "/opt/premiumizearrd/premiumizearr.error.log",
|
||||
MaxSize: 100, // optional
|
||||
MaxBackups: 1, // optional
|
||||
MaxAge: 1, // optional
|
||||
Compress: false, // optional
|
||||
LocalTime: false, // optional
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
logFile, err := os.OpenFile("premiumizearr.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
} else {
|
||||
log.SetOutput(io.MultiWriter(logFile, os.Stdout))
|
||||
panic(err)
|
||||
}
|
||||
|
||||
log.Info("")
|
||||
log.AddHook(hook)
|
||||
|
||||
log.Info("---------- Starting premiumizearr daemon ----------")
|
||||
log.Info("")
|
||||
|
||||
@@ -59,23 +86,31 @@ func main() {
|
||||
|
||||
premiumizearr_client := premiumizeme.NewPremiumizemeClient(config.PremiumizemeAPIKey)
|
||||
|
||||
starr_config_sonarr := starr.New(config.SonarrAPIKey, config.SonarrURL, 0)
|
||||
starr_config_radarr := starr.New(config.RadarrAPIKey, config.RadarrURL, 0)
|
||||
arrs := []arr.IArr{}
|
||||
|
||||
sonarr_wrapper := arr.SonarrArr{
|
||||
Client: sonarr.New(starr_config_sonarr),
|
||||
History: nil,
|
||||
LastUpdate: time.Now(),
|
||||
}
|
||||
radarr_wrapper := arr.RadarrArr{
|
||||
Client: radarr.New(starr_config_radarr),
|
||||
History: nil,
|
||||
LastUpdate: time.Now(),
|
||||
}
|
||||
|
||||
arrs := []arr.IArr{
|
||||
&sonarr_wrapper,
|
||||
&radarr_wrapper,
|
||||
for _, arr_config := range config.Arrs {
|
||||
switch arr_config.Type {
|
||||
case "Sonarr":
|
||||
config := starr.New(arr_config.APIKey, arr_config.URL, 0)
|
||||
wrapper := arr.SonarrArr{
|
||||
Name: arr_config.Name,
|
||||
Client: sonarr.New(config),
|
||||
History: nil,
|
||||
LastUpdate: time.Now(),
|
||||
}
|
||||
arrs = append(arrs, &wrapper)
|
||||
case "Radarr":
|
||||
config := starr.New(arr_config.APIKey, arr_config.URL, 0)
|
||||
wrapper := arr.RadarrArr{
|
||||
Name: arr_config.Name,
|
||||
Client: radarr.New(config),
|
||||
History: nil,
|
||||
LastUpdate: time.Now(),
|
||||
}
|
||||
arrs = append(arrs, &wrapper)
|
||||
default:
|
||||
log.Error("Unknown arr type: %s, not adding Arr %s", arr_config.Type, arr_config.Name)
|
||||
}
|
||||
}
|
||||
|
||||
transfer_manager := service.NewTransferManagerService(premiumizearr_client, &arrs, &config)
|
||||
|
||||
16
config.yaml
Normal file
16
config.yaml
Normal file
@@ -0,0 +1,16 @@
|
||||
PremiumizemeAPIKey: xxxxxxxxx
|
||||
Arrs:
|
||||
- Name: ""
|
||||
URL: http://localhost:8989
|
||||
APIKey: xxxxxxxxx
|
||||
Type: Sonarr
|
||||
- Name: ""
|
||||
URL: http://localhost:7878
|
||||
APIKey: xxxxxxxxx
|
||||
Type: Radarr
|
||||
BlackholeDirectory: ""
|
||||
DownloadsDirectory: ""
|
||||
UnzipDirectory: ""
|
||||
bindIP: 0.0.0.0
|
||||
bindPort: "8182"
|
||||
WebRoot: ""
|
||||
@@ -1,9 +0,0 @@
|
||||
PremiumizemeAPIKey: ""
|
||||
SonarrURL: http://localhost:8989
|
||||
SonarrAPIKey: ""
|
||||
RadarrURL: http://localhost:7878
|
||||
RadarrAPIKey: ""
|
||||
BlackholeDirectory: ""
|
||||
DownloadsDirectory: ""
|
||||
bindIP: 0.0.0.0
|
||||
bindPort: "8182"
|
||||
3
go.mod
3
go.mod
@@ -6,12 +6,15 @@ require (
|
||||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/fsnotify/fsnotify v1.5.1
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/orandin/lumberjackrus v1.0.1
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
golift.io/starr v0.13.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.0.0 // indirect
|
||||
golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d // indirect
|
||||
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||
)
|
||||
|
||||
6
go.sum
6
go.sum
@@ -1,3 +1,5 @@
|
||||
github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
|
||||
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||
@@ -7,6 +9,8 @@ github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||
github.com/orandin/lumberjackrus v1.0.1 h1:7ysDQ0MHD79zIFN9/EiDHjUcgopNi5ehtxFDy8rUkWo=
|
||||
github.com/orandin/lumberjackrus v1.0.1/go.mod h1:xYLt6H8W93pKnQgUQaxsApS0Eb4BwHLOkxk5DVzf5H0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
@@ -48,5 +52,7 @@ golift.io/starr v0.13.0 h1:LoihBAH3DQ0ikPNHTVg47tUU+475mzbr1ahMcY5gdno=
|
||||
golift.io/starr v0.13.0/go.mod h1:IZIzdT5/NBdhM08xAEO5R1INgGN+Nyp4vCwvgHrbKVs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
Description=Premiumizearr Daemon
|
||||
After=network.target
|
||||
[Service]
|
||||
User=$USER
|
||||
Group=$USER
|
||||
User=1000
|
||||
Group=1000
|
||||
UMask=0002
|
||||
Type=simple
|
||||
ExecStart=/opt/premiumizearrd/premiumizearrd
|
||||
|
||||
@@ -18,6 +18,7 @@ type IArr interface {
|
||||
}
|
||||
|
||||
type SonarrArr struct {
|
||||
Name string
|
||||
ClientMutex sync.Mutex
|
||||
Client *sonarr.Sonarr
|
||||
HistoryMutex sync.Mutex
|
||||
@@ -29,6 +30,7 @@ type SonarrArr struct {
|
||||
}
|
||||
|
||||
type RadarrArr struct {
|
||||
Name string
|
||||
ClientMutex sync.Mutex
|
||||
Client *radarr.Radarr
|
||||
HistoryMutex sync.Mutex
|
||||
|
||||
@@ -4,7 +4,8 @@ import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
@@ -14,20 +15,37 @@ var (
|
||||
ErrFailedToFindConfigFile = errors.New("failed to find config file")
|
||||
)
|
||||
|
||||
//ArrType enum for Sonarr/Radarr
|
||||
type ArrType string
|
||||
|
||||
const (
|
||||
Sonarr ArrType = "Sonarr"
|
||||
Radarr ArrType = "Radarr"
|
||||
)
|
||||
|
||||
type ArrConfig struct {
|
||||
Name string `yaml:"Name"`
|
||||
URL string `yaml:"URL"`
|
||||
APIKey string `yaml:"APIKey"`
|
||||
Type ArrType `yaml:"Type"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
PremiumizemeAPIKey string `yaml:"PremiumizemeAPIKey"`
|
||||
|
||||
SonarrURL string `yaml:"SonarrURL"`
|
||||
SonarrAPIKey string `yaml:"SonarrAPIKey"`
|
||||
|
||||
RadarrURL string `yaml:"RadarrURL"`
|
||||
RadarrAPIKey string `yaml:"RadarrAPIKey"`
|
||||
Arrs []ArrConfig `yaml:"Arrs"`
|
||||
|
||||
BlackholeDirectory string `yaml:"BlackholeDirectory"`
|
||||
DownloadsDirectory string `yaml:"DownloadsDirectory"`
|
||||
|
||||
UnzipDirectory string `yaml:"UnzipDirectory"`
|
||||
|
||||
BindIP string `yaml:"bindIP"`
|
||||
BindPort string `yaml:"bindPort"`
|
||||
|
||||
WebRoot string `yaml:"WebRoot"`
|
||||
|
||||
SimultaneousDownloads int `yaml:"SimultaneousDownloads"`
|
||||
}
|
||||
|
||||
func loadConfigFromDisk() (Config, error) {
|
||||
@@ -43,20 +61,40 @@ func loadConfigFromDisk() (Config, error) {
|
||||
return config, ErrInvalidConfigFile
|
||||
}
|
||||
|
||||
config = versionUpdateConfig(config)
|
||||
|
||||
data, err := yaml.Marshal(config)
|
||||
if err == nil {
|
||||
//Save config to disk to add missing fields
|
||||
ioutil.WriteFile("config.yaml", data, 0644)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func versionUpdateConfig(config Config) Config {
|
||||
// 1.1.3
|
||||
if config.SimultaneousDownloads == 0 {
|
||||
config.SimultaneousDownloads = 5
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
func createDefaultConfig() error {
|
||||
config := Config{
|
||||
PremiumizemeAPIKey: "",
|
||||
SonarrURL: "http://localhost:8989",
|
||||
SonarrAPIKey: "",
|
||||
RadarrURL: "http://localhost:7878",
|
||||
RadarrAPIKey: "",
|
||||
BlackholeDirectory: "",
|
||||
DownloadsDirectory: "",
|
||||
BindIP: "0.0.0.0",
|
||||
BindPort: "8182",
|
||||
PremiumizemeAPIKey: "xxxxxxxxx",
|
||||
Arrs: []ArrConfig{
|
||||
{URL: "http://localhost:8989", APIKey: "xxxxxxxxx", Type: Sonarr},
|
||||
{URL: "http://localhost:7878", APIKey: "xxxxxxxxx", Type: Radarr},
|
||||
},
|
||||
BlackholeDirectory: "",
|
||||
DownloadsDirectory: "",
|
||||
UnzipDirectory: "",
|
||||
BindIP: "0.0.0.0",
|
||||
BindPort: "8182",
|
||||
WebRoot: "",
|
||||
SimultaneousDownloads: 5,
|
||||
}
|
||||
|
||||
file, err := yaml.Marshal(config)
|
||||
@@ -92,10 +130,28 @@ func LoadOrCreateConfig(altConfigLocation string) (Config, error) {
|
||||
return config, ErrInvalidConfigFile
|
||||
}
|
||||
}
|
||||
//Clean up url
|
||||
if strings.HasSuffix(config.SonarrURL, ("/")) {
|
||||
config.SonarrURL = config.SonarrURL[:len(config.SonarrURL)-1]
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func (c *Config) GetTempBaseDir() string {
|
||||
if c.UnzipDirectory != "" {
|
||||
return path.Dir(c.UnzipDirectory)
|
||||
}
|
||||
return path.Join(os.TempDir(), "premiumizearrd")
|
||||
}
|
||||
|
||||
func (c *Config) GetTempDir() (string, error) {
|
||||
// Create temp dir in os temp location
|
||||
tempDir := c.GetTempBaseDir()
|
||||
|
||||
err := os.MkdirAll(tempDir, os.ModePerm)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
dir, err := ioutil.TempDir(tempDir, "unzip-")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (dw *DirectoryWatcherService) Watch() {
|
||||
dw.downloadsFolderID = utils.GetDownloadsFolderIDFromPremiumizeme(dw.premiumizemeClient)
|
||||
|
||||
log.Info("Clearing tmp directory...")
|
||||
tempDir := utils.GetTempBaseDir()
|
||||
tempDir := dw.config.GetTempBaseDir()
|
||||
err := os.RemoveAll(tempDir)
|
||||
if err != nil {
|
||||
log.Errorf("Error clearing tmp directory %s", tempDir)
|
||||
@@ -146,7 +146,7 @@ func (dw *DirectoryWatcherService) processUploads() {
|
||||
log.Trace("File already uploaded, removing from Disk")
|
||||
os.Remove(filePath)
|
||||
default:
|
||||
log.Error(err)
|
||||
log.Error("Error creating transfer: %s", err)
|
||||
}
|
||||
} else {
|
||||
dw.status = "Okay"
|
||||
|
||||
@@ -77,7 +77,7 @@ func (manager *TransferManagerService) TaskUpdateTransfersList() {
|
||||
log.Debug("Running Task UpdateTransfersList")
|
||||
transfers, err := manager.premiumizemeClient.GetTransfers()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error("Error getting transfers: %s", err.Error())
|
||||
return
|
||||
}
|
||||
manager.updateTransfers(transfers)
|
||||
@@ -107,15 +107,20 @@ func (manager *TransferManagerService) TaskUpdateTransfersList() {
|
||||
|
||||
func (manager *TransferManagerService) TaskCheckPremiumizeDownloadsFolder() {
|
||||
log.Debug("Running Task CheckPremiumizeDownloadsFolder")
|
||||
items, err := manager.premiumizemeClient.ListFolder(manager.downloadsFolderID)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, item := range items {
|
||||
log.Debugf("Processing completed item: %s", item.Name)
|
||||
go manager.HandleFinishedItem(item, manager.config.DownloadsDirectory)
|
||||
if len(manager.transfers) < manager.config.SimultaneousDownloads {
|
||||
items, err := manager.premiumizemeClient.ListFolder(manager.downloadsFolderID)
|
||||
if err != nil {
|
||||
log.Error("Error listing downloads folder: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
for _, item := range items {
|
||||
log.Debugf("Processing completed item: %s", item.Name)
|
||||
go manager.HandleFinishedItem(item, manager.config.DownloadsDirectory)
|
||||
}
|
||||
} else {
|
||||
log.Debug("Hit download cap, skipping task")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,13 +183,13 @@ func (manager *TransferManagerService) HandleFinishedItem(item premiumizeme.Item
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error("Error generating download link: %s", err)
|
||||
manager.removeDownload(item.Name)
|
||||
return
|
||||
}
|
||||
log.Trace("Downloading: ", link)
|
||||
|
||||
tempDir, err := utils.GetTempDir()
|
||||
tempDir, err := manager.config.GetTempDir()
|
||||
if err != nil {
|
||||
log.Errorf("Could not create temp dir: %s", err)
|
||||
manager.removeDownload(item.Name)
|
||||
@@ -230,7 +235,7 @@ func (manager *TransferManagerService) HandleFinishedItem(item premiumizeme.Item
|
||||
err = manager.premiumizemeClient.DeleteFolder(item.ID)
|
||||
if err != nil {
|
||||
manager.removeDownload(item.Name)
|
||||
log.Error(err)
|
||||
log.Error("Error deleting folder on premiumuze.me: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@ import (
|
||||
"archive/zip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -23,21 +21,6 @@ func StripDownloadTypesExtention(fileName string) string {
|
||||
return fileName
|
||||
}
|
||||
|
||||
func GetTempBaseDir() string {
|
||||
return path.Join(os.TempDir(), "premiumizearrd")
|
||||
}
|
||||
|
||||
func GetTempDir() (string, error) {
|
||||
// Create temp dir in os temp location
|
||||
tempDir := GetTempBaseDir()
|
||||
err := os.Mkdir(tempDir, os.ModePerm)
|
||||
dir, err := ioutil.TempDir(tempDir, "unzip-")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
// https://golangcode.com/unzip-files-in-go/
|
||||
func Unzip(src string, dest string) error {
|
||||
r, err := zip.OpenReader(src)
|
||||
|
||||
@@ -25,8 +25,6 @@ type IndexTemplates struct {
|
||||
|
||||
var indexBytes []byte
|
||||
|
||||
const webRoot = "premiumizearr"
|
||||
|
||||
type server struct {
|
||||
transferManager *service.TransferManagerService
|
||||
directoryWatcherService *service.DirectoryWatcherService
|
||||
@@ -40,7 +38,7 @@ func StartWebServer(transferManager *service.TransferManagerService, directoryWa
|
||||
}
|
||||
|
||||
var ibytes bytes.Buffer
|
||||
err = tmpl.Execute(&ibytes, &IndexTemplates{webRoot})
|
||||
err = tmpl.Execute(&ibytes, &IndexTemplates{config.WebRoot})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -53,18 +51,24 @@ func StartWebServer(transferManager *service.TransferManagerService, directoryWa
|
||||
spa := spaHandler{
|
||||
staticPath: "static",
|
||||
indexPath: "index.html",
|
||||
webRoot: config.WebRoot,
|
||||
}
|
||||
|
||||
r := mux.NewRouter()
|
||||
|
||||
log.Infof("Creating route: %s", webRoot+"/api/transfers")
|
||||
r.HandleFunc("/"+webRoot+"/api/transfers", s.TransfersHandler)
|
||||
transferPath := "/api/transfers"
|
||||
downloadsPath := "/api/downloads"
|
||||
blackholePath := "/api/blackhole"
|
||||
|
||||
log.Infof("Creating route: %s", webRoot+"/api/downloads")
|
||||
r.HandleFunc("/"+webRoot+"/api/downloads", s.DownloadsHandler)
|
||||
if config.WebRoot != "" {
|
||||
transferPath = path.Join(config.WebRoot, transferPath)
|
||||
downloadsPath = path.Join(config.WebRoot, downloadsPath)
|
||||
blackholePath = path.Join(config.WebRoot, blackholePath)
|
||||
}
|
||||
|
||||
log.Infof("Creating route: %s", webRoot+"/api/blackhole")
|
||||
r.HandleFunc("/"+webRoot+"/api/blackhole", s.BlackholeHandler)
|
||||
r.HandleFunc(transferPath, s.TransfersHandler)
|
||||
r.HandleFunc(downloadsPath, s.DownloadsHandler)
|
||||
r.HandleFunc(blackholePath, s.BlackholeHandler)
|
||||
|
||||
r.PathPrefix("/").Handler(spa)
|
||||
|
||||
@@ -163,6 +167,7 @@ func (s *server) BlackholeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
type spaHandler struct {
|
||||
staticPath string
|
||||
indexPath string
|
||||
webRoot string
|
||||
}
|
||||
|
||||
func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -175,8 +180,9 @@ func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
path = strings.Replace(path, webRoot, "", 1)
|
||||
|
||||
if h.webRoot != "" {
|
||||
path = strings.Replace(path, h.webRoot, "", 1)
|
||||
}
|
||||
// prepend the path with the path to the static directory
|
||||
path = filepath.Join(h.staticPath, path)
|
||||
|
||||
|
||||
6
scripts/postinstall.sh
Normal file
6
scripts/postinstall.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
chown -R 1000:1000 /opt/premiumizearrd/
|
||||
systemctl enable premiumizearrd.service
|
||||
systemctl daemon-reload
|
||||
systemctl start premiumizearrd.service
|
||||
6978
web/package-lock.json
generated
6978
web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -6,13 +6,13 @@
|
||||
|
||||
<title>Premiumizearr</title>
|
||||
|
||||
<link rel='icon' type='image/png' href='/favicon.png'>
|
||||
<link rel='stylesheet' href='/{{.RootPath}}/bundle.css'>
|
||||
<link rel='icon' type='image/png' href='./{{.RootPath}}/favicon.png'>
|
||||
<link rel='stylesheet' href='./{{.RootPath}}/bundle.css'>
|
||||
<!-- Material Icons -->
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
||||
<!-- Roboto -->
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700" />
|
||||
<script defer src='/{{.RootPath}}/bundle.js'></script>
|
||||
<script defer src='./{{.RootPath}}/bundle.js'></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
let dlSpeed = 0;
|
||||
|
||||
let webRoot = new URL(window.location.href).pathname;
|
||||
let webRoot = window.location.href;
|
||||
|
||||
function parseDLSpeedFromMessage(m) {
|
||||
if (m == "Loading..." || m == undefined) return 0;
|
||||
@@ -37,7 +37,7 @@
|
||||
case "GB":
|
||||
return speed * 1024 * 1024 * 1024;
|
||||
default:
|
||||
console.log("Unknown unit: " + unit);
|
||||
console.log("Unknown unit: " + unit + " in message '" + m + "'");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@
|
||||
{ key: "name", value: "Name", sort: false },
|
||||
]}
|
||||
{webRoot}
|
||||
APIpath="/api/blackhole"
|
||||
APIpath="api/blackhole"
|
||||
zebra={true}
|
||||
totalName="In Queue: "
|
||||
/>
|
||||
@@ -122,7 +122,7 @@
|
||||
]}
|
||||
updateTimeSeconds={2}
|
||||
{webRoot}
|
||||
APIpath="/api/downloads"
|
||||
APIpath="api/downloads"
|
||||
zebra={true}
|
||||
totalName="Downloading: "
|
||||
/>
|
||||
@@ -140,7 +140,7 @@
|
||||
{ key: "message", value: "Message", sort: false },
|
||||
]}
|
||||
{webRoot}
|
||||
APIpath="/api/transfers"
|
||||
APIpath="api/transfers"
|
||||
zebra={true}
|
||||
{dataToRows}
|
||||
/>
|
||||
|
||||
@@ -61,7 +61,7 @@ module.exports = {
|
||||
devServer: {
|
||||
hot: true,
|
||||
proxy: {
|
||||
'/api': 'https://projectmouseion.com/premiumizearr/api'
|
||||
'/api': 'https://yourinstance.com/api'
|
||||
}
|
||||
},
|
||||
optimization: {
|
||||
|
||||
Reference in New Issue
Block a user