-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrec_schedule_cmd.go
77 lines (65 loc) · 1.62 KB
/
rec_schedule_cmd.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
package radikocast
import (
"flag"
"fmt"
"strings"
"time"
"github.com/mitchellh/cli"
)
type recScheduleCommand struct {
ui cli.Ui
}
func (c *recScheduleCommand) Run(args []string) int {
var stationID, day, at, areaID, bucket, format string
f := flag.NewFlagSet("rec_schedule", flag.ContinueOnError)
f.StringVar(&stationID, "id", "", "id")
f.StringVar(&day, "day", "", "day")
f.StringVar(&at, "at", "", "at")
f.StringVar(&areaID, "area", "", "area")
f.StringVar(&areaID, "a", "", "area")
f.StringVar(&bucket, "bucket", "", "bucket")
f.StringVar(&format, "format", "mp3", "format")
f.Usage = func() { c.ui.Error(c.Help()) }
if err := f.Parse(args); err != nil {
return 1
}
if stationID == "" {
c.ui.Error("StationID is empty.")
return 1
}
if day == "" {
c.ui.Error("day is empty")
return 1
}
if at == "" {
c.ui.Error("at is empty")
return 1
}
start, err := findLastProgram(day, at, time.Now())
if err != nil {
c.ui.Error(fmt.Sprintf("Bad day or at: %v", err))
return 1
}
c.ui.Output("Now downloading.. ")
err = RecAndUploadProgram(stationID, start, areaID, bucket, format)
if err != nil {
c.ui.Error(fmt.Sprintf("Failed to rec: %s", err))
return 1
}
c.ui.Output(fmt.Sprintf("Completed!"))
return 0
}
func (c *recScheduleCommand) Synopsis() string {
return "Record a radiko program"
}
func (c *recScheduleCommand) Help() string {
return strings.TrimSpace(`
Usage: radikocast rec [options]
Record a radiko program.
Options:
-id=name Station id
-day=day_expression Day expression (ex. monday)
-area,a=name Area id
-bucket=bucketname S3 bucket name
`)
}