-
Notifications
You must be signed in to change notification settings - Fork 0
/
rec_cmd.go
71 lines (60 loc) · 1.43 KB
/
rec_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
package radikocast
import (
"flag"
"fmt"
"log"
"os"
"strings"
"github.com/mitchellh/cli"
)
type recCommand struct {
ui cli.Ui
}
func (c *recCommand) Run(args []string) int {
var stationID, start, areaID, bucket, format string
f := flag.NewFlagSet("rec", flag.ContinueOnError)
f.StringVar(&stationID, "id", "", "id")
f.StringVar(&start, "start", "", "start")
f.StringVar(&start, "s", "", "start")
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
}
c.ui.Output("Now downloading.. ")
err := RecAndUploadProgram(stationID, start, areaID, bucket, format)
if err != nil {
c.ui.Error(err.Error())
return 1
}
c.ui.Output(fmt.Sprintf("Completed!"))
return 0
}
func (c *recCommand) Synopsis() string {
return "Record a radiko program"
}
func (c *recCommand) Help() string {
return strings.TrimSpace(`
Usage: radikocast rec [options]
Record a radiko program.
Options:
-id=name Station id
-start,s=201610101000 Start time
-area,a=name Area id
-bucket=bucketname S3 bucket name
`)
}
func fileSize(path string) int64 {
fi, err := os.Stat(path)
if err != nil {
log.Fatal(err)
}
return fi.Size()
}