-
Notifications
You must be signed in to change notification settings - Fork 0
/
find.go
170 lines (136 loc) · 2.87 KB
/
find.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package library
import (
"errors"
)
//
// Library searchers
//
// GetLibraryMovie finds Movie from library
func GetLibraryMovie(kodiID int) *Movie {
l.mu.Movies.Lock()
defer l.mu.Movies.Unlock()
for _, m := range l.Movies {
if m.UIDs.Kodi == kodiID {
return m
}
}
return nil
}
// GetLibraryShow finds Show from library
func GetLibraryShow(kodiID int) *Show {
l.mu.Shows.RLock()
defer l.mu.Shows.RUnlock()
// query := strconv.Itoa(kodiID)
for _, s := range l.Shows {
if s.UIDs.Kodi == kodiID {
return s
}
}
return nil
}
// GetLibrarySeason finds Show/Season from library
func GetLibrarySeason(kodiID int) (*Show, *Season) {
l.mu.Shows.RLock()
defer l.mu.Shows.RUnlock()
for _, s := range l.Shows {
for _, se := range s.Seasons {
if se.UIDs.Kodi == kodiID {
return s, se
}
}
}
return nil, nil
}
// GetLibraryEpisode finds Show/Episode from library
func GetLibraryEpisode(kodiID int) (*Show, *Episode) {
l.mu.Shows.RLock()
defer l.mu.Shows.RUnlock()
for _, s := range l.Shows {
for _, e := range s.Episodes {
if e.UIDs.Kodi == kodiID {
return s, e
}
}
}
return nil, nil
}
// GetMovieByTMDB ...
func GetMovieByTMDB(id int) (*Movie, error) {
l.mu.Movies.RLock()
defer l.mu.Movies.RUnlock()
for _, m := range l.Movies {
if m != nil && m.UIDs.TMDB == id {
return m, nil
}
}
return nil, errors.New("Not found")
}
// GetMovieByIMDB ...
func GetMovieByIMDB(id string) (*Movie, error) {
l.mu.Movies.RLock()
defer l.mu.Movies.RUnlock()
for _, m := range l.Movies {
if m != nil && m.UIDs.IMDB == id {
return m, nil
}
}
return nil, errors.New("Not found")
}
// GetShowByTMDB ...
func GetShowByTMDB(id int) (*Show, error) {
l.mu.Shows.RLock()
defer l.mu.Shows.RUnlock()
for _, s := range l.Shows {
if s != nil && s.UIDs.TMDB == id {
return s, nil
}
}
return nil, errors.New("Not found")
}
// findShowByKodi ...
func findShowByKodi(id int) (*Show, error) {
for _, s := range l.Shows {
if s != nil && s.UIDs.Kodi == id {
return s, nil
}
}
return nil, errors.New("Not found")
}
// findShowByTMDB ...
func findShowByTMDB(id int) (*Show, error) {
for _, s := range l.Shows {
if s != nil && s.UIDs.TMDB == id {
return s, nil
}
}
return nil, errors.New("Not found")
}
// findShowByIMDB ...
func findShowByIMDB(id string) (*Show, error) {
for _, s := range l.Shows {
if s != nil && s.UIDs.IMDB == id {
return s, nil
}
}
return nil, errors.New("Not found")
}
// GetShowByIMDB ...
func GetShowByIMDB(id string) (*Show, error) {
l.mu.Shows.RLock()
defer l.mu.Shows.RUnlock()
for _, s := range l.Shows {
if s != nil && s.UIDs.IMDB == id {
return s, nil
}
}
return nil, errors.New("Not found")
}
// GetEpisode ...
func (s *Show) GetEpisode(season, episode int) *Episode {
for _, e := range s.Episodes {
if e.Season == season && e.Episode == episode {
return e
}
}
return nil
}