forked from scakemyer/quasar
-
Notifications
You must be signed in to change notification settings - Fork 43
/
resume.go
59 lines (48 loc) · 1.08 KB
/
resume.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
package uid
import (
"fmt"
"math"
"time"
)
// 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
}
// GetMovieResume returns Resume info for kodi id
func GetMovieResume(kodiID int) *Resume {
mu := l.GetMutex(MoviesMutex)
mu.RLock()
defer mu.RUnlock()
for _, m := range l.Movies {
if m.UIDs.Kodi == kodiID {
return m.Resume
}
}
return nil
}
// GetEpisodeResume returns Resume info for kodi id
func GetEpisodeResume(kodiID int) *Resume {
mu := l.GetMutex(ShowsMutex)
mu.RLock()
defer mu.RUnlock()
for _, existingShow := range l.Shows {
for _, existingEpisode := range existingShow.Episodes {
if existingEpisode.UIDs.Kodi == kodiID {
return existingEpisode.Resume
}
}
}
return nil
}