-
Notifications
You must be signed in to change notification settings - Fork 3
/
slingdvr.go
95 lines (79 loc) · 1.6 KB
/
slingdvr.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
package main
import (
"flag"
"fmt"
"time"
"github.com/davecgh/go-spew/spew"
)
var async = flag.Bool("async", true, "Records DVR programs at a later time")
func main() {
flag.Parse()
if err := ReadConfig(); err != nil {
panic(err)
}
if *dumpSchedule {
if showings, err := FetchSchedule(); err == nil {
fmt.Printf("URL: %s\n", scheduleUrl())
spew.Printf("%#v\n", showings)
return
} else {
panic(err)
}
} else if *dumpRecs {
if showings, err := FetchRecs(); err == nil {
fmt.Printf("URL: %s\n", recUrl())
spew.Printf("%#v\n", showings)
return
} else {
panic(err)
}
}
if *forceTime != "" {
// TODO hack, isn't concurrency-safe
go func() {
const timeMultiple = 1
for {
time.Sleep(timeMultiple * time.Second)
*forceTime = timeNow().Add(timeMultiple * time.Second).Format(time.RFC3339)
}
}()
}
if !*async {
recordC := make(chan Showing)
refreshScheduleC := make(chan struct{})
go func() {
if err := Scheduler(recordC, refreshScheduleC); err != nil {
panic(err)
}
}()
go func() {
if err := Recorder(recordC); err != nil {
panic(err)
}
}()
for {
time.Sleep(15 * 60 * time.Second)
refreshScheduleC <- struct{}{}
}
} else {
allRecs := make(chan Showing)
recReqs := make(chan RecRequest)
go func() {
if err := SendNewRecs(allRecs); err != nil {
panic(err)
}
}()
go func() {
if err := SendRecReqs(recReqs, allRecs); err != nil {
panic(err)
}
}()
go func() {
if err := AsyncRecorder(recReqs); err != nil {
panic(err)
}
}()
// Block forever
<-make(chan struct{})
}
}