-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathbrowse_live.go
53 lines (43 loc) · 976 Bytes
/
browse_live.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
package radigo
import (
"flag"
"fmt"
"os/exec"
"strings"
"github.com/mitchellh/cli"
"github.com/yyoshiki41/go-radiko"
)
type browseLiveCommand struct {
ui cli.Ui
}
func (c *browseLiveCommand) Run(args []string) int {
var stationID string
f := flag.NewFlagSet("browse-live", flag.ContinueOnError)
f.StringVar(&stationID, "id", "", "id")
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
}
url := radiko.GetLiveURL(stationID)
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 *browseLiveCommand) Synopsis() string {
return "Browse radiko.jp live"
}
func (c *browseLiveCommand) Help() string {
return strings.TrimSpace(`
Usage: radigo browse-live [options]
Browse radiko.jp live
Options:
-id=name Station id
`)
}