Skip to content

Instantly share code, notes, and snippets.

@jeremija
Last active March 23, 2020 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremija/09976b0e5d71429571588f4b328c2a25 to your computer and use it in GitHub Desktop.
Save jeremija/09976b0e5d71429571588f4b328c2a25 to your computer and use it in GitHub Desktop.

Sends HTTP File to AppleTV for Playback

go get github.com/jeremija/appletv
appletv [apple-tv-host:port] [http-url-to-play]

Running from source:

git clone https://gist.github.com/jeremija/09976b0e5d71429571588f4b328c2a25/edit appletv
cd appletv
go run main.go [apple-tv-host:port] [http-url-to-play]

Example:

go run main.go 192.168.1.2:7000 http://path/to/file.mp4

The Connection: keep-alive header is necessary for playback to work.

package main
import (
"fmt"
"net/http"
"os"
"strings"
"time"
)
func main() {
fmt.Println("starting...")
appleTVAddr := os.Args[1]
remoteHTTPFileURL := os.Args[2]
body := `Content-Location: ` + remoteHTTPFileURL + `
Start-Position: 0.00001
`
r, err := http.NewRequest("POST", "http://"+appleTVAddr+"/play", strings.NewReader(body))
if err != nil {
panic(err)
}
r.Header.Set("User-Agent", "iTunes/11.0.5 (Macintosh; OS X 10.8.4) AppleWebKit/536.30.1")
// r.Header.Set("Accept-Encoding", "gzip, deflate")
r.Header.Set("Connection", "keep-alive")
r.Header.Set("Accept", "*/*")
r.Header.Set("Content-Type", "text/parameters")
var client http.Client
res, err := client.Do(r)
if err != nil {
panic(err)
}
fmt.Println(res.Proto, res.Status)
for h, values := range res.Header {
for _, value := range values {
fmt.Println(h+":", value)
}
}
time.Sleep(10 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment