-
Notifications
You must be signed in to change notification settings - Fork 0
/
radarr.go
114 lines (100 loc) · 3 KB
/
radarr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package letswatch
import (
"encoding/json"
"errors"
"io/ioutil"
"strconv"
"github.com/drewstinnett/go-letterboxd"
"github.com/rs/zerolog/log"
"golift.io/starr/radarr"
)
type RadarrService interface {
QualityProfiles() ([]*radarr.QualityProfile, error)
QualityProfileWithName(string) (*radarr.QualityProfile, error)
AddTag(string) (int, error)
MustAddTag(string) int
MoviesWithTMDBID(int64) ([]*radarr.Movie, error)
AddMovie(*radarr.AddMovieInput) (*radarr.AddMovieOutput, error)
MovieInputWithLetterboxdFilm(*letterboxd.Film) (*radarr.AddMovieInput, error)
}
type RadarrServiceOp struct {
client *Client
radarrClient *radarr.Radarr
}
type RadarrMovie struct {
ID float64 `json:"id,omitempty"`
Title string `json:"title,omitempty"`
CleanTitle string `json:"clean_title,omitempty"`
IMDBID string `json:"imdb_id,omitempty"`
ReleaseYear int `json:"release_year,string,omitempty"`
Adult bool `json:"adult,omitempty"`
}
func (svc *RadarrServiceOp) AddMovie(mi *radarr.AddMovieInput) (*radarr.AddMovieOutput, error) {
return svc.radarrClient.AddMovie(mi)
}
func (svc *RadarrServiceOp) MoviesWithTMDBID(id int64) ([]*radarr.Movie, error) {
return svc.radarrClient.GetMovie(id)
}
func (svc *RadarrServiceOp) QualityProfileWithName(n string) (*radarr.QualityProfile, error) {
profiles, err := svc.QualityProfiles()
if err != nil {
return nil, err
}
for _, p := range profiles {
if p.Name == n {
return p, nil
}
}
return nil, errors.New("No profile with that name found")
}
func (svc *RadarrServiceOp) QualityProfiles() ([]*radarr.QualityProfile, error) {
return svc.radarrClient.GetQualityProfiles()
}
func (svc *RadarrServiceOp) AddTag(t string) (int, error) {
return svc.radarrClient.AddTag(t)
}
func (svc *RadarrServiceOp) MustAddTag(t string) int {
i, err := svc.AddTag(t)
if err != nil {
log.Warn().Err(err).Str("tag", t).Msg("Error getting tag")
panic(err)
}
return i
}
func (svc *RadarrServiceOp) MovieInputWithLetterboxdFilm(item *letterboxd.Film) (*radarr.AddMovieInput, error) {
// Figure out tmdb id in a usable format
tmdbID, err := strconv.ParseInt(item.ExternalIDs.TMDB, 10, 64)
if err != nil {
return nil, err
}
profile, err := svc.QualityProfileWithName(svc.client.Config.RadarrQuality)
if err != nil {
return nil, err
}
tagID := svc.MustAddTag("letswatch-supplement")
mi := &radarr.AddMovieInput{
Title: item.Title,
Year: item.Year,
TmdbID: tmdbID,
QualityProfileID: profile.ID,
RootFolderPath: svc.client.Config.RadarrPath,
Monitored: true,
Tags: []int{tagID},
AddOptions: &radarr.AddMovieOptions{
SearchForMovie: true,
},
}
return mi, nil
}
func ParseRadarrMovies(data []byte) ([]RadarrMovie, error) {
var movies []RadarrMovie
err := json.Unmarshal(data, &movies)
return movies, err
}
func ParseRadarrMoviesWithFile(fileP string) ([]RadarrMovie, error) {
data, err := ioutil.ReadFile(fileP)
if err != nil {
return nil, err
}
return ParseRadarrMovies(data)
}