-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ _testmain.go | |
*.exe | ||
*.test | ||
*.prof | ||
/gotubecast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 Florian Hülsmann | ||
Copyright (c) 2016 Florian Hülsmann <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# gotubecast | ||
DIY YouTube TV | ||
gotubecast is a small Go program which you can use to make your own YouTube TV player. | ||
|
||
It connects to the YouTube Leanback API and generates a text stream providing pairing codes, video IDs, | ||
play/pause/seek/volume change commands etc. It doesn't have any dependencies and runs on any of the platforms supported by golang. | ||
For example, use it on a Raspberry Pi in combination with youtube-dl and omxplayer for a DIY Chromecast clone or make a YouTube TV | ||
extension for your favorite media center software. | ||
|
||
Work in progress. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"io/ioutil" | ||
"net/url" | ||
"encoding/json" | ||
) | ||
|
||
type LoungeTokenScreenList struct { | ||
Screens []LoungeTokenScreenItem | ||
} | ||
|
||
type LoungeTokenScreenItem struct { | ||
ScreenId string | ||
LoungeToken string | ||
Expiration uint64 | ||
} | ||
|
||
func main() { | ||
// screen id: | ||
resp, err := http.Get("https://www.youtube.com/api/lounge/pairing/generate_screen_id") | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
defer resp.Body.Close() | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
} | ||
screenId := string(body) | ||
fmt.Println("screen_id", screenId) | ||
|
||
// lounge token: | ||
resp, err = http.PostForm("https://www.youtube.com/api/lounge/pairing/get_lounge_token_batch", url.Values{"screen_ids": {screenId}}) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
defer resp.Body.Close() | ||
body, err = ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
} | ||
tokenObj := new(LoungeTokenScreenList) | ||
err = json.Unmarshal(body, &tokenObj) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
tokenScreenItem := tokenObj.Screens[0] | ||
fmt.Println("lounge_token", tokenScreenItem.LoungeToken, tokenScreenItem.Expiration / 1000) | ||
|
||
// pairing code: | ||
resp, err = http.PostForm("https://www.youtube.com/api/lounge/pairing/get_pairing_code?ctx=pair", url.Values{ | ||
"access_type": {"permanent"}, | ||
"app": {"golang-test-838"}, | ||
"lounge_token": {tokenScreenItem.LoungeToken}, | ||
"screen_id": {tokenScreenItem.ScreenId}, | ||
"screen_name": {"Golang Test TV"}, | ||
}) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
} | ||
defer resp.Body.Close() | ||
body, err = ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
} | ||
pairCode := string(body) | ||
fmt.Printf("pairing_code %s-%s-%s-%s\n", pairCode[0:3], pairCode[3:6], pairCode[6:9], pairCode[9:12]) | ||
} |