-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
64 lines (53 loc) · 1.09 KB
/
main.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
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/gongo/go-airplay"
)
var (
// exitCode to terminate.
exitCode = 0
)
func main() {
app := cli.NewApp()
app.Name = "air"
app.Version = Version
app.Usage = "Command-line AirPlay client for Apple TV"
app.Author = "Tomohiro TAIRA"
app.Email = "[email protected]"
app.Action = func(c *cli.Context) {
paths := c.Args()
if !paths.Present() {
fmt.Fprintf(os.Stderr, "Incorrect usage.\nRun `air <path>`\n")
exitCode = 1
return
}
if err := Play(paths); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
exitCode = 1
return
}
}
app.Run(os.Args)
os.Exit(exitCode)
}
// Play plays the recieved paths of media files to the Apple TV.
func Play(paths []string) error {
var err error
// Initialize an AirPlay client device.
client, err := airplay.FirstClient()
if err != nil {
return err
}
for _, path := range paths {
url, err := Open(path)
if err != nil {
fmt.Fprintf(os.Stderr, "Skipped %s. because %s.\n", path, err)
continue
}
ch := client.Play(url)
<-ch
}
return err
}