roku

package module
v0.0.0-...-ec64929 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 7 Imported by: 6

README

roku

Roku External Control API package for Golang

Rick Roll the Roku(s)

Rick Roll all roku devices on the network that have YouTube installed.

dQw4w9WgXcQ is the contentID of "Never Gonna Give You Up" on YouTube

package main

import "github.com/picatz/roku"

func main() {
    devices, err := roku.Find(roku.DefaultWaitTime)

    if err != nil {
        panic(err)
    }

    for _, device := range devices {
        apps, err := device.Apps()

        if err != nil {
            panic(err)
        }

        for _, app := range apps {
            if app.ID == roku.YouTubeAppID {
                device.LaunchApp(app.ID, roku.Params{
                    "contentID": "dQw4w9WgXcQ",
                })
            }
        }
    }
}

Where's the remote(s)?

On supported devices, you can make the remote beep.

package main

import "github.com/picatz/roku"

func main() {
    devices, err := roku.Find(roku.DefaultWaitTime)

    if err != nil {
        panic(err)
    }

    for _, device := range devices {
        device.FindRemote()
     }
}

Documentation

Overview

Package roku is a External Control API package for Golang

Index

Examples

Constants

View Source
const (
	TVInput         = "tvinput."
	YouTubeAppID    = "837"
	NetflixAppID    = "12"
	PrimeVideoAppID = "13"
	HuluAppID       = "2285"
	PandoraAppID    = "28"
	SpotifyAppID    = "19977"
	ESPNAppID       = "34376"
	PlayOnRokuID    = "15985"
	HDMI1           = TVInput + "hdmi1"
	HDMI2           = TVInput + "hdmi2"
	HDMI3           = TVInput + "hdmi3"
	AV              = TVInput + "cvbs"
	LiveTV          = TVInput + "dtv"
	AppleTV         = "551012"
	Peacock         = "593099"
	HBOMax          = "61322"
	CBS             = "619667"
	DisneyPlus      = "291097"
	ParamountPlus   = "31440"
	Spotify         = "22297"
	CW              = "111255"
	ABC             = "73376"
	FoxSports       = "95307"
)

Found from querying App IDs once installed on a TV https://channelstore.roku.com/details/{AppID} will take you to the channel's page Note that this will redirect you to a URL of the form https://channelstore.roku.com/details/{WebID}/{AppName} where WebID also identifies the app but only via Roku's website (and not on your TV)

Variables

View Source
var (
	// ErrNoAppFound is the error returned when no applicaiton is found.
	ErrNoAppFound = errors.New("no app found")
	// ErrNoAppsFound is the error returned when there are no applications found.
	ErrNoAppsFound = errors.New("no apps found")
	// ErrNoRespBody is the error returned when there was no response body from
	// the roku device.
	ErrNoRespBody = errors.New("no response body")
	// ErrAppNotFound is the error returned when the target app. was not found.
	ErrAppNotFound = errors.New("Failed to find app")
)
View Source
var (
	// HomeKey reprents the "Home" button.
	HomeKey = "Home"
	// RevKey reprents the "Rev" button.
	RevKey = "Rev"
	// FwdKey reprents the "Fwd" button.
	FwdKey = "Fwd"
	// PlayKey reprents the "Play" button.
	PlayKey = "Play"
	// SelectKey reprents the "Select" button.
	SelectKey = "Select"
	// LeftKey reprents the "Left" button.
	LeftKey = "Left"
	// RightKey reprents the "Right" button.
	RightKey = "Right"
	// DownKey reprents the "Down" button.
	DownKey = "Down"
	// UpKey reprents the "Up" button.
	UpKey = "Up"
	// BackKey reprents the "Back" button.
	BackKey = "Back"
	// InstantReplayKey reprents the "InstantReplay" button.
	InstantReplayKey = "InstantReplay"
	// InfoKey reprents the "Info" button.
	InfoKey = "Info"
	// BackspaceKey reprents the "Backspace" button.
	BackspaceKey = "Backspace"
	// SearchKey reprents the "Search" button.
	SearchKey = "Search"
	// EnterKey reprents the "Enter" button.
	EnterKey = "Enter"
	// FindRemoteKey reprents the "FindRemote" button.
	FindRemoteKey = "FindRemote"
	// VolumeDownKey reprents the "VolumeDown" button.
	VolumeDownKey = "VolumeDown"
	// VolumeMuteKey reprents the "VolumeMute" button.
	VolumeMuteKey = "VolumeMute"
	// VolumeUpKey reprents the "VolumeUp" button.
	VolumeUpKey = "VolumeUp"
	// PowerOffKey reprents the "PowerOff" button.
	PowerOffKey = "PowerOff"
	// ChannelUpKey reprents the "ChannelUp" button.
	ChannelUpKey = "ChannelUp"
	// ChannelDownKey reprents the "ChannelDown" button.
	ChannelDownKey = "ChannelDown"
	// InputTunerKey reprents the "InputTuner" button.
	InputTunerKey = "InputTuner"
	// InputHDMI1Key reprents the "InputHDMI1" button.
	InputHDMI1Key = "InputHDMI1"
	// InputHDMI2Key reprents the "InputHDMI2" button.
	InputHDMI2Key = "InputHDMI2"
	// InputHDMI3Key reprents the "InputHDMI3" button.
	InputHDMI3Key = "InputHDMI3"
	// InputHDMI4Key reprents the "InputHDMI4" button.
	InputHDMI4Key = "InputHDMI4"
	// InputAV1Key reprents the "InputAV1" button.
	InputAV1Key = "InputAV1"
)
View Source
var DefaultWaitTime = 5

DefaultWaitTime is the default value (in seconds) to Find roku devices on the network.

Functions

func LiteralKey

func LiteralKey(key string) string

LiteralKey formats a given (plaintext/string) key for Keypress that helps simulate the on-screen keyboard for roku input.

Types

type App

type App struct {
	Name    string `xml:",chardata" json:"name,omitempty"`
	ID      string `xml:"id,attr" json:"id,omitempty"`
	Type    string `xml:"type,attr" json:"type,omitempty"`
	SubType string `xml:"subtype,attr" json:"sub_type,omitempty"`
	Version string `xml:"version,attr" json:"version,omitempty"`
}

App has all the information of an application. https://github.com/kinghrothgar/roku/blob/master/roku/roku.go#L63

type Apps

type Apps = []*App

Apps is a collection of one or more App(s)

type DeviceInfo

type DeviceInfo struct {
	XMLName                  xml.Name `xml:"device-info" json:"-"`
	Text                     string   `xml:",chardata" json:"text,omitempty"`
	Udn                      string   `xml:"udn" json:"udn,omitempty"`
	SerialNumber             string   `xml:"serial-number" json:"serial_number,omitempty"`
	DeviceID                 string   `xml:"device-id" json:"device_id,omitempty"`
	AdvertisingID            string   `xml:"advertising-id" json:"advertising_id,omitempty"`
	VendorName               string   `xml:"vendor-name" json:"vendor_name,omitempty"`
	ModelName                string   `xml:"model-name" json:"model_name,omitempty"`
	ModelNumber              string   `xml:"model-number" json:"model_number,omitempty"`
	ModelRegion              string   `xml:"model-region" json:"model_region,omitempty"`
	IsTv                     string   `xml:"is-tv" json:"is_tv,omitempty"`
	IsStick                  string   `xml:"is-stick" json:"is_stick,omitempty"`
	SupportsEthernet         string   `xml:"supports-ethernet" json:"supports_ethernet,omitempty"`
	WifiMac                  string   `xml:"wifi-mac" json:"wifi_mac,omitempty"`
	WifiDriver               string   `xml:"wifi-driver" json:"wifi_driver,omitempty"`
	EthernetMac              string   `xml:"ethernet-mac" json:"ethernet_mac,omitempty"`
	NetworkType              string   `xml:"network-type" json:"network_type,omitempty"`
	NetworkName              string   `xml:"network-name" json:"network_name,omitempty"`
	FriendlyDeviceName       string   `xml:"friendly-device-name" json:"friendly_device_name,omitempty"`
	FriendlyModelName        string   `xml:"friendly-model-name" json:"friendly_model_name,omitempty"`
	DefaultDeviceName        string   `xml:"default-device-name" json:"default_device_name,omitempty"`
	UserDeviceName           string   `xml:"user-device-name" json:"user_device_name,omitempty"`
	BuildNumber              string   `xml:"build-number" json:"build_number,omitempty"`
	SoftwareVersion          string   `xml:"software-version" json:"software_version,omitempty"`
	SoftwareBuild            string   `xml:"software-build" json:"software_build,omitempty"`
	SecureDevice             string   `xml:"secure-device" json:"secure_device,omitempty"`
	Language                 string   `xml:"language" json:"language,omitempty"`
	Country                  string   `xml:"country" json:"country,omitempty"`
	Locale                   string   `xml:"locale" json:"locale,omitempty"`
	TimeZoneAuto             string   `xml:"time-zone-auto" json:"time_zone_auto,omitempty"`
	TimeZone                 string   `xml:"time-zone" json:"time_zone,omitempty"`
	TimeZoneName             string   `xml:"time-zone-name" json:"time_zone_name,omitempty"`
	TimeZoneTz               string   `xml:"time-zone-tz" json:"time_zone_tz,omitempty"`
	TimeZoneOffset           string   `xml:"time-zone-offset" json:"time_zone_offset,omitempty"`
	ClockFormat              string   `xml:"clock-format" json:"clock_format,omitempty"`
	Uptime                   string   `xml:"uptime" json:"uptime,omitempty"`
	PowerMode                string   `xml:"power-mode" json:"power_mode,omitempty"`
	SupportsSuspend          string   `xml:"supports-suspend" json:"supports_suspend,omitempty"`
	SupportsFindRemote       string   `xml:"supports-find-remote" json:"supports_find_remote,omitempty"`
	FindRemoteIsPossible     string   `xml:"find-remote-is-possible" json:"find_remote_is_possible,omitempty"`
	SupportsAudioGuide       string   `xml:"supports-audio-guide" json:"supports_audio_guide,omitempty"`
	SupportsRva              string   `xml:"supports-rva" json:"supports_rva,omitempty"`
	DeveloperEnabled         string   `xml:"developer-enabled" json:"developer_enabled,omitempty"`
	KeyedDeveloperID         string   `xml:"keyed-developer-id" json:"keyed_developer_id,omitempty"`
	SearchEnabled            string   `xml:"search-enabled" json:"search_enabled,omitempty"`
	SearchChannelsEnabled    string   `xml:"search-channels-enabled" json:"search_channels_enabled,omitempty"`
	VoiceSearchEnabled       string   `xml:"voice-search-enabled" json:"voice_search_enabled,omitempty"`
	NotificationsEnabled     string   `xml:"notifications-enabled" json:"notifications_enabled,omitempty"`
	NotificationsFirstUse    string   `xml:"notifications-first-use" json:"notifications_first_use,omitempty"`
	SupportsPrivateListening string   `xml:"supports-private-listening" json:"supports_private_listening,omitempty"`
	HeadphonesConnected      string   `xml:"headphones-connected" json:"headphones_connected,omitempty"`
	SupportsEcsTextedit      string   `xml:"supports-ecs-textedit" json:"supports_ecs_textedit,omitempty"`
	SupportsEcsMicrophone    string   `xml:"supports-ecs-microphone" json:"supports_ecs_microphone,omitempty"`
	SupportsWakeOnWlan       string   `xml:"supports-wake-on-wlan" json:"supports_wake_on_wlan,omitempty"`
	HasPlayOnRoku            string   `xml:"has-play-on-roku" json:"has_play_on_roku,omitempty"`
	HasMobileScreensaver     string   `xml:"has-mobile-screensaver" json:"has_mobile_screensaver,omitempty"`
	SupportURL               string   `xml:"support-url" json:"support_url,omitempty"`
	GrandcentralVersion      string   `xml:"grandcentral-version" json:"grandcentral_version,omitempty"`
	TrcVersion               string   `xml:"trc-version" json:"trc_version,omitempty"`
	TrcChannelVersion        string   `xml:"trc-channel-version" json:"trc_channel_version,omitempty"`
	DavinciVersion           string   `xml:"davinci-version" json:"davinci_version,omitempty"`
}

DeviceInfo contains all the information about the roku device.

type Endpoint

type Endpoint struct {
	// contains filtered or unexported fields
}

Endpoint represents a roku device on the network.

func NewEndpoint

func NewEndpoint(url string) *Endpoint

New create a new endpoint struct, url needs to be in the format 'http://ENDPOINT:PORT/' eg http://192.168.0.100:8060/

func (*Endpoint) ActiveApp

func (e *Endpoint) ActiveApp() (*App, error)

ActiveApp returns the currently active App for an Endpoint.

func (*Endpoint) Apps

func (e *Endpoint) Apps() (Apps, error)

Apps returns the available applications for an Endpoint.

func (*Endpoint) DeviceInfo

func (e *Endpoint) DeviceInfo() (*DeviceInfo, error)

DeviceInfo returns the DeviceInfo for a roku device endpoint.

func (*Endpoint) FindRemote

func (e *Endpoint) FindRemote() error

FindRemote is a short-cut to the Keypress to find a roku remote control.

func (*Endpoint) Icon

func (e *Endpoint) Icon(id string) ([]byte, error)

Icon returns the image (PNG) for the given applicaton ID.

func (*Endpoint) Input

func (e *Endpoint) Input(params map[string]string, options *InputOptions) error

Input provides input functionality for a roku device.

func (*Endpoint) InstallApp

func (e *Endpoint) InstallApp(id string, params map[string]string) error

InstallApp attempts to install an application on the roku device.

func (*Endpoint) IsInstalledApp

func (e *Endpoint) IsInstalledApp(appID string) (bool, error)

IsInstalledApp checks if the device has a given application ID

func (*Endpoint) KeyDown

func (e *Endpoint) KeyDown(key string) error

KeyDown allows simulating pressing down on a button on the roku remote.

func (*Endpoint) KeyUp

func (e *Endpoint) KeyUp(key string) error

KeyUp allows simulating releasing a button on the roku remote.

func (*Endpoint) Keypress

func (e *Endpoint) Keypress(key string) error

Keypress allows simulating hitting a button on the roku remote.

func (*Endpoint) LaunchApp

func (e *Endpoint) LaunchApp(id string, params map[string]string) error

LaunchApp starts an application on the roku device.

func (*Endpoint) PlayVideo

func (e *Endpoint) PlayVideo(uri string) error

PlayVideo wraps Input for the Play On Roku app. to play a custom video.

func (*Endpoint) Search

func (e *Endpoint) Search(params map[string]string) error

Search provides a search functionality for a roku device.

func (*Endpoint) String

func (e *Endpoint) String() string

type Endpoints

type Endpoints = []*Endpoint

Endpoints is a collection of roku devices.

func Find

func Find(seconds int) (endpoints Endpoints, err error)

Find sends out a SSDP request on the network, looking for Roku devices that can be connected to.

Example
devices, err := Find(2)

if err != nil {
	panic(err)
}

fmt.Println(len(devices))
Output:
1

type InputOptions

type InputOptions struct {
	AppID string
}

InputOptions holds optional values for the "Input" method.

type Params

type Params = map[string]string

Params is a key-value pairing for customizing certain API calls.

Directories

Path Synopsis
cmd
roku command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL