forked from scakemyer/quasar
-
Notifications
You must be signed in to change notification settings - Fork 43
/
duplicate.go
112 lines (90 loc) · 2.2 KB
/
duplicate.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
package uid
import (
"strconv"
"github.com/anacrolix/missinggo/perf"
)
//
// Duplicate handling
//
// IsDuplicateMovie checks if movie exists in the library
func IsDuplicateMovie(tmdbID string) bool {
mu := l.GetMutex(UIDsMutex)
mu.RLock()
defer mu.RUnlock()
defer perf.ScopeTimer()()
query, _ := strconv.Atoi(tmdbID)
for _, u := range l.UIDs {
if u.TMDB != 0 && u.MediaType == MovieType && u.TMDB == query {
return true
}
}
return false
}
// IsDuplicateMovieByInt checks if movie exists in the library
func IsDuplicateMovieByInt(tmdbID int) bool {
mu := l.GetMutex(UIDsMutex)
mu.RLock()
defer mu.RUnlock()
defer perf.ScopeTimer()()
for _, u := range l.UIDs {
if u.TMDB != 0 && u.MediaType == MovieType && u.TMDB == tmdbID {
return true
}
}
return false
}
// IsDuplicateShow checks if show exists in the library
func IsDuplicateShow(tmdbID string) bool {
mu := l.GetMutex(UIDsMutex)
mu.RLock()
defer mu.RUnlock()
defer perf.ScopeTimer()()
query, _ := strconv.Atoi(tmdbID)
for _, u := range l.UIDs {
if u.TMDB != 0 && u.MediaType == ShowType && u.TMDB == query {
return true
}
}
return false
}
// IsDuplicateShowByInt checks if show exists in the library
func IsDuplicateShowByInt(tmdbID int) bool {
mu := l.GetMutex(UIDsMutex)
mu.RLock()
defer mu.RUnlock()
defer perf.ScopeTimer()()
for _, u := range l.UIDs {
if u.TMDB != 0 && u.MediaType == ShowType && u.TMDB == tmdbID {
return true
}
}
return false
}
// IsDuplicateEpisode checks if episode exists in the library
func IsDuplicateEpisode(tmdbShowID int, seasonNumber int, episodeNumber int) bool {
mu := l.GetMutex(ShowsMutex)
mu.RLock()
defer mu.RUnlock()
defer perf.ScopeTimer()()
for _, s := range l.Shows {
if tmdbShowID != s.UIDs.TMDB {
continue
}
for _, e := range s.Episodes {
if e.Season == seasonNumber && e.Episode == episodeNumber {
return true
}
}
}
return false
}
// IsAddedToLibrary checks if specific TMDB exists in the library
func IsAddedToLibrary(id string, mediaType MediaItemType) (isAdded bool) {
defer perf.ScopeTimer()()
if mediaType == MovieType {
return IsDuplicateMovie(id)
} else if mediaType == ShowType {
return IsDuplicateShow(id)
}
return false
}