From f9722fd27945870cea2607be2bf31d81439a5e23 Mon Sep 17 00:00:00 2001 From: Nick Bisby Date: Wed, 30 Jan 2019 22:56:15 -0600 Subject: [PATCH] Actually play a movie --- .gitignore | 1 + components/{helloworld.xml => signin.xml} | 17 +----- components/videoplayer.xml | 15 +++++ source/Main.brs | 21 ++++--- source/VideoPlayer.brs | 67 +++++++++++++++++++++++ 5 files changed, 96 insertions(+), 25 deletions(-) rename components/{helloworld.xml => signin.xml} (57%) create mode 100644 components/videoplayer.xml create mode 100644 source/VideoPlayer.brs diff --git a/.gitignore b/.gitignore index 96c805ad..b0b4bd75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.svg jellyfin-roku.zip +source/globals.brs diff --git a/components/helloworld.xml b/components/signin.xml similarity index 57% rename from components/helloworld.xml rename to components/signin.xml index 525b7c5b..10e60363 100644 --- a/components/helloworld.xml +++ b/components/signin.xml @@ -1,14 +1,6 @@ - - + + diff --git a/source/Main.brs b/source/Main.brs index 4f0b1e21..49de69e9 100644 --- a/source/Main.brs +++ b/source/Main.brs @@ -1,21 +1,19 @@ -'************************************************************* -'** Hello World example -'** Copyright (c) 2015 Roku, Inc. All rights reserved. -'** Use of the Roku Platform is subject to the Roku SDK Licence Agreement: -'** https://docs.roku.com/doc/developersdk/en-us -'************************************************************* - sub Main() - print "in showChannelSGScreen" 'Indicate this is a Roku SceneGraph application' + globals() + screen = CreateObject("roSGScreen") m.port = CreateObject("roMessagePort") screen.setMessagePort(m.port) + 'todo - pick the scene based on if we need a server already + first_scene = "ServerSelect" 'Create a scene and load a component' - scene = screen.CreateScene("ServerSelect") + m.scene = screen.CreateScene("VideoScene") screen.show() + player = VideoPlayer(get_var("video_id")) + while(true) msg = wait(0, m.port) msgType = type(msg) @@ -25,3 +23,8 @@ sub Main() end while end sub + +function get_var(key as String) + return GetGlobalAA().Lookup(key) +end function + diff --git a/source/VideoPlayer.brs b/source/VideoPlayer.brs new file mode 100644 index 00000000..e77d1687 --- /dev/null +++ b/source/VideoPlayer.brs @@ -0,0 +1,67 @@ +function VideoPlayer(id) + + content = VideoContent(id) + + video = m.scene.findNode("VideoPlayer") + + video.AddHeader("X-Emby-Authorization", build_auth()) + if content.protocol = "https" then + video.setCertificatesFile("common:/certs/ca-bundle.crt") + end if + + video.content = content + + video.setFocus(true) + video.control = "play" + + return video + +end function + + +function VideoContent(id) as object + content = createObject("RoSGNode", "ContentNode") + + content.title = "Loading..." + meta = VideoMetaData(id) + content.title = meta.Name + + protocol = get_var("protocol") + hostname = get_var("hostname") + content.url = Substitute("{0}://{1}/emby/Videos/{2}/stream.mp4", protocol, hostname, id) + content.protocol = "https" + + return content + +end function + + +function VideoMetaData(id) + protocol = get_var("protocol") + hostname = get_var("hostname") + user_id = get_var("user_id") + url = Substitute("{0}://{1}/emby/Users/{2}/Items/{3}", protocol, hostname, user_id, id) + + + req = createObject("roUrlTransfer") + req.setCertificatesFile("common:/certs/ca-bundle.crt") + req.setUrl(url) + req.AddHeader("X-Emby-Authorization", build_auth()) + + json = ParseJson(req.GetToString()) + + return json +end function + +function build_auth() as String + auth = "MediaBrowser" + auth = auth + " Client=" + Chr(34) + "Jellyfin Roku" + Chr(34) + auth = auth + ", Device=" + Chr(34) + "Roku Model" + Chr(34) + auth = auth + ", DeviceId=" + Chr(34) + "12345" + Chr(34) + auth = auth + ", Version=" + Chr(34) + "10.1.0" + Chr(34) + + auth = auth + ", UserId=" + Chr(34) + get_var("user_id") + Chr(34) + auth = auth + ", Token=" + Chr(34) + get_var("user_token") + Chr(34) + return auth +end function +