Documentation ¶
Overview ¶
Package youtube implements a minimal client for the YouTube Lounge API which allows to connect and play videos on a remote "screen" (YouTube on TV app). The API is not public so this code CAN BREAK AT ANY TIME.
The implementation derives from the work of various people I found on the web that saved me hours of reverse engineering. I'd like to list and thank them here:
https://0x41.cf/automation/2021/03/02/google-assistant-youtube-smart-tvs.html https://github.com/thedroidgeek/youtube-cast-automation-api https://github.com/mutantmonkey/youtube-remote https://bugs.xdavidhu.me/google/2021/04/05/i-built-a-tv-that-plays-all-of-your-private-youtube-videos https://github.com/aykevl/plaincast https://github.com/ur1katz/casttube
Index ¶
Constants ¶
const ( // Origin header value for HTTP requests to YouTube services. Origin = "https://www.youtube.com" // YouTube application name registered in the DIAL register. // See http://www.dial-multiscreen.org/dial-registry/namespace-database DialAppName = "YouTube" )
Variables ¶
This section is empty.
Functions ¶
func ExtractScreenId ¶ added in v0.2.0
ExtractScreenId extracts the screen id of a YouTube TV app from the xml tag <additionalData> fetched with a GET request on the Application-URL (see DIAL protocol and dial.GetAppInfo()).
Types ¶
type Remote ¶
type Remote struct { ScreenId string // id of the screen (tv app) we are connected (or connecting) to. Name string // name displayed on the screen at connection time. LoungeToken string // token for Lounge API requests. Expiration int64 // LoungeToken expiration timestamp in milliseconds. SId string // session id? it can expire very often so we fetch it at each Play() or Add(). GSessionId string // another session id? google session id? we fetch it along with SId. // these fields are present ONLY if connected with code (ConnectWithCode()). DeviceId string // uuid of the device we are connected to. ScreenName string // name of the screen we are connected to. // contains filtered or unexported fields }
Remote holds Lounge session tokens of a connected screen (tv app) and allows to play videos on it until Expiration.
func Connect ¶
Connect connects to a screen (tv app) identified by screenId through the Lounge API. name will be displayed on the screen at connection time. Returns a Remote that can be used to play video on that screen.
func ConnectWithCode ¶ added in v1.2.0
ConnectWithCode is like Connect(), but uses a pairing code (generated by the tv app) to get ScreenId and LoungeToken.
func (*Remote) Add ¶ added in v1.1.0
Add requests the Lounge API to add videos to the queue without changing what's currently playing on the tv app. Accepts both video urls and video ids.
func (*Remote) Play ¶
Play requests the Lounge API to play immediately the first video on the tv app and to enqueue the others. Accepts both video urls and video ids.
func (*Remote) RefreshToken ¶
RefreshToken gets a new LoungeToken for the screenId. Should be used when the token has Expired().
func (*Remote) SetLocalAddr ¶ added in v1.4.0
SetLocalAddr sets the local address the Remote instance must use for network operations.