-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
158 lines (134 loc) · 2.87 KB
/
types.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
package library
import (
"fmt"
"math"
"sync"
"time"
"github.com/projectx13/projectx/xbmc"
)
// Status represents library bool statuses
type Status struct {
IsOverall bool
IsMovies bool
IsShows bool
IsEpisodes bool
IsTrakt bool
IsKodi bool
}
// Library represents library
type Library struct {
mu lMutex
// Stores all the unique IDs collected
UIDs []*UniqueIDs
Movies []*Movie
Shows []*Show
WatchedTrakt []uint64
Pending Status
Running Status
}
type lMutex struct {
UIDs sync.RWMutex
Movies sync.RWMutex
Shows sync.RWMutex
Trakt sync.RWMutex
}
// UniqueIDs represents all IDs for a library item
type UniqueIDs struct {
MediaType int `json:"media"`
Kodi int `json:"kodi"`
TMDB int `json:"tmdb"`
TVDB int `json:"tvdb"`
IMDB string `json:"imdb"`
Trakt int `json:"trakt"`
Playcount int `json:"playcount"`
}
// Movie represents Movie content type
type Movie struct {
ID int
Title string
File string
Year int
DateAdded time.Time
UIDs *UniqueIDs
XbmcUIDs *xbmc.UniqueIDs
Resume *Resume
}
// Show represents Show content type
type Show struct {
ID int
Title string
Year int
DateAdded time.Time
Seasons []*Season
Episodes []*Episode
UIDs *UniqueIDs
XbmcUIDs *xbmc.UniqueIDs
}
// Season represents Season content type
type Season struct {
ID int
Title string
Season int
Episodes int
UIDs *UniqueIDs
XbmcUIDs *xbmc.UniqueIDs
}
// Episode represents Episode content type
type Episode struct {
ID int
Title string
Season int
Episode int
File string
DateAdded time.Time
UIDs *UniqueIDs
XbmcUIDs *xbmc.UniqueIDs
Resume *Resume
}
// Resume shows watched progress information
type Resume struct {
Position float64 `json:"position"`
Total float64 `json:"total"`
}
// DBItem ...
type DBItem struct {
ID int `json:"id"`
State int `json:"state"`
Type int `json:"type"`
TVShowID int `json:"showid"`
}
type removedEpisode struct {
ID int
ShowID int
ShowName string
Season int
Episode int
}
// ToString ...
func (r *Resume) ToString() string {
if r.Position == 0 {
return ""
}
t1 := time.Now()
t2 := t1.Add(time.Duration(int(r.Position)) * time.Second)
diff := t2.Sub(t1)
return fmt.Sprintf("%d:%02d:%02d", int(diff.Hours()), int(math.Mod(diff.Minutes(), 60)), int(math.Mod(diff.Seconds(), 60)))
}
// Reset ...
func (r *Resume) Reset() {
log.Debugf("Resetting stored resume position")
r.Position = 0
r.Total = 0
}
// IsWatched returns watched state
func (e *Episode) IsWatched() bool {
return e.UIDs != nil && e.UIDs.Playcount != 0
}
// IsWatched returns watched state
func (s *Show) IsWatched() bool {
return s.UIDs != nil && s.UIDs.Playcount != 0
}
// IsWatched returns watched state
func (m *Movie) IsWatched() bool {
return m.UIDs != nil && m.UIDs.Playcount != 0
}