-
Notifications
You must be signed in to change notification settings - Fork 0
/
playcount.go
124 lines (100 loc) · 3.55 KB
/
playcount.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
package playcount
import (
"fmt"
"sync"
"github.com/cespare/xxhash"
)
const (
// TVDBScraper ...
TVDBScraper = iota
// TMDBScraper ...
TMDBScraper
// TraktScraper ...
TraktScraper
// IMDBScraper ...
IMDBScraper
)
const (
// MovieType ...
MovieType = iota
// ShowType ...
ShowType
// SeasonType ...
SeasonType
// EpisodeType ...
EpisodeType
)
// Watched stores all "watched" items
var (
// Mu is a global lock for Playcount package
Mu = sync.RWMutex{}
// Watched contains uint64 hashed bools
Watched = []uint64{}
)
// WatchedState just a simple bool with Int() conversion
type WatchedState bool
func searchForKey(k uint64) WatchedState {
Mu.RLock()
defer Mu.RUnlock()
for _, v := range Watched {
if v == k {
return true
}
}
return false
}
// GetWatchedMovieByTMDB checks whether item is watched
func GetWatchedMovieByTMDB(id int) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%d", MovieType, TMDBScraper, id)))
}
// GetWatchedMovieByIMDB checks whether item is watched
func GetWatchedMovieByIMDB(id string) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%s", MovieType, IMDBScraper, id)))
}
// GetWatchedMovieByTrakt checks whether item is watched
func GetWatchedMovieByTrakt(id int) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%d", MovieType, TraktScraper, id)))
}
// GetWatchedShowByTMDB checks whether item is watched
func GetWatchedShowByTMDB(id int) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%d", ShowType, TMDBScraper, id)))
}
// GetWatchedShowByTVDB checks whether item is watched
func GetWatchedShowByTVDB(id int) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%d", ShowType, TVDBScraper, id)))
}
// GetWatchedShowByTrakt checks whether item is watched
func GetWatchedShowByTrakt(id int) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%d", ShowType, TraktScraper, id)))
}
// GetWatchedSeasonByTMDB checks whether item is watched
func GetWatchedSeasonByTMDB(id int, season int) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%d_%d", SeasonType, TMDBScraper, id, season)))
}
// GetWatchedSeasonByTVDB checks whether item is watched
func GetWatchedSeasonByTVDB(id int, season, episode int) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%d_%d", SeasonType, TVDBScraper, id, season)))
}
// GetWatchedSeasonByTrakt checks whether item is watched
func GetWatchedSeasonByTrakt(id int, season int) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%d_%d", SeasonType, TraktScraper, id, season)))
}
// GetWatchedEpisodeByTMDB checks whether item is watched
func GetWatchedEpisodeByTMDB(id int, season, episode int) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%d_%d_%d", EpisodeType, TMDBScraper, id, season, episode)))
}
// GetWatchedEpisodeByTVDB checks whether item is watched
func GetWatchedEpisodeByTVDB(id int, season, episode int) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%d_%d_%d", EpisodeType, TVDBScraper, id, season, episode)))
}
// GetWatchedEpisodeByTrakt checks whether item is watched
func GetWatchedEpisodeByTrakt(id int, season, episode int) (ret WatchedState) {
return searchForKey(xxhash.Sum64String(fmt.Sprintf("%d_%d_%d_%d_%d", EpisodeType, TraktScraper, id, season, episode)))
}
// Int converts bool to int
func (w WatchedState) Int() (r int) {
if w {
r = 1
}
return
}