-
Notifications
You must be signed in to change notification settings - Fork 33
/
browse.go
63 lines (53 loc) · 1.24 KB
/
browse.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
package radigo
import (
"flag"
"fmt"
"os/exec"
"strings"
"time"
"github.com/mitchellh/cli"
"github.com/yyoshiki41/go-radiko"
)
type browseCommand struct {
ui cli.Ui
}
func (c *browseCommand) Run(args []string) int {
var stationID, start string
f := flag.NewFlagSet("browse", flag.ContinueOnError)
f.StringVar(&stationID, "id", "", "id")
f.StringVar(&start, "start", "", "start")
f.StringVar(&start, "s", "", "start")
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
}
startTime, err := time.ParseInLocation(datetimeLayout, start, location)
if err != nil {
c.ui.Error(fmt.Sprintf(
"Invalid start time format: %s", start))
return 1
}
url := radiko.GetTimeshiftURL(stationID, startTime)
cmd := exec.Command("open", url)
if err := cmd.Run(); err != nil {
c.ui.Error(fmt.Sprintf(
"Failed to open browser: %s", err))
}
return 0
}
func (c *browseCommand) Synopsis() string {
return "Browse radiko.jp"
}
func (c *browseCommand) Help() string {
return strings.TrimSpace(`
Usage: radigo browse [options]
Browse radiko.jp
Options:
-id=name Station id
-start,s=201610101000 Start time
`)
}