initial commit
This commit is contained in:
commit
0eadc5da55
37 files changed
+1286
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import "pkg:/source/utils/Utils.bs"
|
||||
|
||||
sub Init()
|
||||
m.rowList = m.top.FindNode("rowList")
|
||||
m.rowList.SetFocus(true)
|
||||
m.top.ObserveField("visible", "onVisibleChange")
|
||||
end sub
|
||||
|
||||
sub OnVisibleChange() ' invoked when GridScreen change visibility
|
||||
if m.top.visible = true
|
||||
m.rowList.SetFocus(true) ' set focus to rowList if GridScreen visible
|
||||
end if
|
||||
end sub
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="GridScreen" extends="Group" initialFocus="RowList">
|
||||
<script type="text/brightscript" uri="GridScreen.brs" />
|
||||
<interface>
|
||||
<field id="content" type="node" alias="RowList.content" />
|
||||
<field id="rowItemSelected" type="intarray" alwaysnotify="true" alias="RowList.rowItemSelected" />
|
||||
<field id="jumpToRowItem" type="intarray" alias="RowList.jumpToRowItem" />
|
||||
</interface>
|
||||
<children>
|
||||
<RowList
|
||||
itemComponentName="RowListItemComponent"
|
||||
id="rowList"
|
||||
translation="[50,50]"
|
||||
numRows="2"
|
||||
rowitemSize="[[320,180]]"
|
||||
rowItemSpacing="[[20,0]]"
|
||||
itemSize="[1160,270]"
|
||||
rowLabelOffset="[[50,20]]"
|
||||
focusXOffset="[50]"
|
||||
showRowLabel="[true]"
|
||||
rowFocusAnimationStyle="floatingfocus"
|
||||
/>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,26 @@
|
||||
sub Init()
|
||||
m.top.backgroundColor = "0x1c1c1c"
|
||||
m.loadingIndicator = m.top.FindNode("loadingIndicator")
|
||||
InitScreenStack()
|
||||
ShowGridScreen()
|
||||
RunContentTask()
|
||||
end sub
|
||||
|
||||
' The OnKeyEvent() function receives remote control key events
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
result = false
|
||||
if press
|
||||
' handle "back" key press
|
||||
if key = "back"
|
||||
numberOfScreens = m.screenStack.Count()
|
||||
' close top screen if there are two or more screens in the screen stack
|
||||
if numberOfScreens > 1
|
||||
CloseScreen(invalid)
|
||||
result = true
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
' The OnKeyEvent() function must return true if the component handled the event,
|
||||
' or false if it did not handle the event.
|
||||
return result
|
||||
end function
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="MainScene" extends="Scene">
|
||||
<script type="text/brightscript" uri="MainScene.brs" />
|
||||
<script type="text/brightscript" uri="UILogic/VideoPlayerLogic.brs" />
|
||||
<script type="text/brightscript" uri="UILogic/ScreenStackLogic.brs" />
|
||||
<script type="text/brightscript" uri="UILogic/ContentTaskLogic.brs" />
|
||||
<script type="text/brightscript" uri="UILogic/VideoDetailsTaskLogic.brs" />
|
||||
<script type="text/brightscript" uri="UILogic/GridScreenLogic.brs" />
|
||||
<children>
|
||||
<!-- LoadingIndicator should be visible only in case of waiting for content -->
|
||||
<Label
|
||||
id="loadingIndicator"
|
||||
text="Loading..."
|
||||
width="1280"
|
||||
height="720"
|
||||
translation="[0, 0]"
|
||||
horizAlign="center"
|
||||
vertAlign="center"
|
||||
visible="false"
|
||||
font="font:MediumBoldSystemFont"
|
||||
/>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,15 @@
|
||||
import "pkg:/source/utils/Utils.bs"
|
||||
|
||||
sub OnContentSet()
|
||||
content = m.top.itemContent
|
||||
|
||||
if content <> invalid
|
||||
m.top.FindNode("titleLabel").text = content.title
|
||||
m.top.FindNode("poster").uri = content.hdPosterUrl
|
||||
if content.length <> invalid and content.length <> 0
|
||||
m.top.FindNode("durationLabel").text = RokuYoutube.Utils.GetFormattedTime(content.length)
|
||||
else
|
||||
m.top.FindNode("durationRect").visible = false
|
||||
end if
|
||||
end if
|
||||
end sub
|
||||
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="RowListItemComponent" extends="Group" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">
|
||||
<interface>
|
||||
<field id="itemContent" type="node" onChange="OnContentSet" />
|
||||
</interface>
|
||||
<script type="text/brightscript" uri="RowListItemComponent.brs" />
|
||||
<children>
|
||||
<Poster
|
||||
id="poster"
|
||||
loadDisplayMode="scaleToFit"
|
||||
width="320"
|
||||
height="180"
|
||||
loadWidth="320"
|
||||
loadHeight="180"
|
||||
/>
|
||||
<Rectangle
|
||||
id="durationRect"
|
||||
width="60"
|
||||
height="25"
|
||||
color="0x000000"
|
||||
opacity="0.8"
|
||||
translation="[260, 145]"
|
||||
>
|
||||
<Label
|
||||
width="60"
|
||||
height="25"
|
||||
id="durationLabel"
|
||||
horizAlign="center"
|
||||
vertAlign="center"
|
||||
font="font:SmallestSystemFont"
|
||||
inheritParentOpacity="true"
|
||||
/>
|
||||
</Rectangle>
|
||||
<Label
|
||||
id="titleLabel"
|
||||
width="320"
|
||||
height="25"
|
||||
font="font:SmallestSystemFont"
|
||||
translation="[0, 200]"
|
||||
/>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,13 @@
|
||||
sub RunContentTask()
|
||||
m.contentTask = CreateObject("roSGNode", "MainLoaderTask")
|
||||
|
||||
m.contentTask.ObserveField("content", "OnMainContentLoaded")
|
||||
m.contentTask.control = "run"
|
||||
m.loadingIndicator.visible = true
|
||||
end sub
|
||||
|
||||
sub OnMainContentLoaded()
|
||||
m.GridScreen.SetFocus(true)
|
||||
m.loadingIndicator.visible = false
|
||||
m.GridScreen.content = m.contentTask.content
|
||||
end sub
|
||||
@@ -0,0 +1,20 @@
|
||||
sub ShowGridScreen()
|
||||
m.GridScreen = CreateObject("roSGNode", "GridScreen")
|
||||
m.GridScreen.ObserveField("rowItemSelected", "OnGridScreenItemSelected")
|
||||
ShowScreen(m.GridScreen)
|
||||
end sub
|
||||
|
||||
sub OnGridScreenItemSelected(event as object)
|
||||
grid = event.GetRoSGNode()
|
||||
|
||||
selectedPair = event.GetData()
|
||||
selectedRow = selectedPair[0]
|
||||
selectedRowItem = selectedPair[1]
|
||||
|
||||
rowContent = grid.content.GetChild(selectedRow)
|
||||
itemContent = rowContent.GetChild(selectedRowItem)
|
||||
|
||||
videoId = itemContent.id
|
||||
|
||||
RunVideoDetailsTask(videoId)
|
||||
end sub
|
||||
@@ -0,0 +1,34 @@
|
||||
sub InitScreenStack()
|
||||
m.screenStack = []
|
||||
end sub
|
||||
|
||||
sub ShowScreen(node as object)
|
||||
prev = m.screenStack.Peek() ' take current screen from screen stack but don't delete it
|
||||
if prev <> invalid
|
||||
prev.visible = false ' hide current screen if it exist
|
||||
end if
|
||||
' show new screen
|
||||
m.top.AppendChild(node)
|
||||
node.visible = true
|
||||
node.SetFocus(true)
|
||||
m.screenStack.Push(node) ' add new screen to the screen stack
|
||||
end sub
|
||||
|
||||
sub CloseScreen(node as object)
|
||||
if node = invalid or (m.screenStack.Peek() <> invalid and m.screenStack.Peek().IsSameNode(node))
|
||||
last = m.screenStack.Pop() ' remove screen from screenStack
|
||||
last.visible = false ' hide screen
|
||||
m.top.RemoveChild(node) ' remove screen from scene
|
||||
|
||||
' take previous screen and make it visible
|
||||
prev = m.screenStack.Peek()
|
||||
if prev <> invalid
|
||||
prev.visible = true
|
||||
prev.SetFocus(true)
|
||||
end if
|
||||
end if
|
||||
end sub
|
||||
|
||||
function GetCurrentScreen()
|
||||
return m.screenStack.Peek()
|
||||
end function
|
||||
@@ -0,0 +1,12 @@
|
||||
sub RunVideoDetailsTask(videoId)
|
||||
m.videoDetailsTask = CreateObject("roSGNode", "VideoDetailsLoaderTask")
|
||||
m.videoDetailsTask.setField("videoid", videoId)
|
||||
m.videoDetailsTask.ObserveField("content", "OnVideoDetailsLoaded")
|
||||
m.videoDetailsTask.control = "run"
|
||||
m.loadingIndicator.visible = true ' show loading indicator while content is loading
|
||||
end sub
|
||||
|
||||
sub OnVideoDetailsLoaded()
|
||||
m.loadingIndicator.visible = false
|
||||
ShowVideoScreen(m.videoDetailsTask.content.metadata, m.videoDetailsTask.content.sponsorblock)
|
||||
end sub
|
||||
@@ -0,0 +1,87 @@
|
||||
sub ShowVideoScreen(videoMetadata as object, videoSponsorBlock as object)
|
||||
m.videoPlayer = CreateObject("roSGNode", "Video")
|
||||
rowNode = CreateObject("roSGNode", "ContentNode")
|
||||
|
||||
rowNode.url = videoMetadata.formatStreams[videoMetadata.formatStreams.Count() - 1].url
|
||||
SetCaptions(videoMetadata, m.videoPlayer, rowNode)
|
||||
m.videoPlayer.content = rowNode
|
||||
|
||||
ShowScreen(m.videoPlayer)
|
||||
m.videoPlayer.control = "play"
|
||||
m.videoPlayer.ObserveField("state", "OnVideoPlayerStateChange")
|
||||
m.videoPlayer.ObserveField("visible", "OnVideoVisibleChange")
|
||||
|
||||
if videoSponsorBlock <> invalid
|
||||
newFields = {}
|
||||
newFields["sponsorblock"] = videoSponsorBlock
|
||||
m.videoPlayer.addFields(newFields)
|
||||
m.videoPlayer.seekMode = "accurate"
|
||||
m.videoPlayer.ObserveField("position", "OnVideoPositionChange")
|
||||
end if
|
||||
|
||||
end sub
|
||||
|
||||
sub SetCaptions(videoMetadata as object, videoPlayer as object, contentNode as object)
|
||||
' TODO: check if we have caption settings ON
|
||||
' TODO: read favorate language from system settings
|
||||
' TODO: populate list of caption tracks
|
||||
if videoMetadata.captions.Count() = 0
|
||||
return
|
||||
end if
|
||||
videoPlayer.globalCaptionMode = "ON"
|
||||
contentNode.ClosedCaptions = True
|
||||
selectedCaption = videoMetadata.captions[0]
|
||||
|
||||
' Use favorite caption langauage, or the first one
|
||||
for each caption in videoMetadata.captions
|
||||
if caption.language_code = "en"
|
||||
selectedCaption = caption
|
||||
exit for
|
||||
end if
|
||||
end for
|
||||
|
||||
contentNode.SubtitleConfig = {
|
||||
ShowSubtitle: 1,
|
||||
TrackName: "https://invidious.esmailelbob.xyz" + selectedCaption.url
|
||||
}
|
||||
end sub
|
||||
|
||||
sub OnVideoPlayerStateChange()
|
||||
state = m.videoPlayer.state
|
||||
|
||||
if state = "error" or state = "finished"
|
||||
CloseScreen(m.videoPlayer)
|
||||
end if
|
||||
end sub
|
||||
|
||||
sub OnVideoVisibleChange()
|
||||
if m.videoPlayer.visible = false and m.top.visible = true
|
||||
m.videoPlayer.control = "stop"
|
||||
|
||||
m.videoPlayer.content = invalid
|
||||
screen = GetCurrentScreen()
|
||||
screen.SetFocus(true)
|
||||
end if
|
||||
end sub
|
||||
|
||||
sub OnVideoPositionChange()
|
||||
SkipSponsorBlockSections()
|
||||
end sub
|
||||
|
||||
sub SkipSponsorBlockSections()
|
||||
segments = m.videoPlayer.getField("sponsorblock")
|
||||
for each segment in segments
|
||||
if segment["actionType"] = "skip"
|
||||
segmentRange = segment["segment"]
|
||||
segmentStart = segmentRange[0]
|
||||
segmentEnd = segmentRange[1]
|
||||
currentPosition = m.videoPlayer.position
|
||||
if (segmentStart < currentPosition) and ((segmentEnd - 1) > currentPosition)
|
||||
' TODO: if segmentEnd is at the end of the video, close video
|
||||
m.videoPlayer.seek = segmentEnd
|
||||
print("Skiping section:" + segment["category"])
|
||||
return
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
end sub
|
||||
@@ -0,0 +1,57 @@
|
||||
import "pkg:/source/services/Invidious.bs"
|
||||
|
||||
sub Init()
|
||||
' set the name of the function in the Task node component to be executed when the state field changes to RUN
|
||||
' in our case this method executed after the following cmd: m.contentTask.control = "run"(see Init method in MainScene)
|
||||
m.top.functionName = "GetContent"
|
||||
end sub
|
||||
|
||||
sub GetContent()
|
||||
rootChildren = []
|
||||
|
||||
trendingJson = RokuYoutube.Services.Invidious.GetTrending()
|
||||
trending = GetCategoryContent("Trending", trendingJson)
|
||||
if trending <> invalid
|
||||
rootChildren.Push(trending)
|
||||
end if
|
||||
|
||||
popularJson = RokuYoutube.Services.Invidious.GetPopular()
|
||||
popular = GetCategoryContent("Popular", popularJson)
|
||||
if popular <> invalid
|
||||
rootChildren.Push(popular)
|
||||
end if
|
||||
|
||||
' set up a root ContentNode to represent rowList on the GridScreen
|
||||
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||
contentNode.Update({
|
||||
children: rootChildren
|
||||
}, true)
|
||||
' populate content field with root content node.
|
||||
' Observer(see OnMainContentLoaded in MainScene.brs) is invoked at that moment
|
||||
m.top.content = contentNode
|
||||
end sub
|
||||
|
||||
function GetCategoryContent(category as string, json as object) as object
|
||||
if json <> invalid
|
||||
row = {}
|
||||
row.title = category
|
||||
row.children = []
|
||||
for each item in json ' parse items and push them to row
|
||||
itemData = GetItemData(item)
|
||||
row.children.Push(itemData)
|
||||
end for
|
||||
return row
|
||||
end if
|
||||
end function
|
||||
|
||||
function GetItemData(video as object) as object
|
||||
item = {}
|
||||
|
||||
item.title = video.title
|
||||
item.description = video.description
|
||||
item.hdPosterURL = video.videoThumbnails[0].url
|
||||
item.releaseDate = video.publishedText
|
||||
item.id = video.videoId
|
||||
item.length = video.lengthSeconds
|
||||
return item
|
||||
end function
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="MainLoaderTask" extends="Task">
|
||||
<interface>
|
||||
<field id="content" type="node" />
|
||||
</interface>
|
||||
|
||||
<script type="text/brightscript" uri="MainLoaderTask.brs" />
|
||||
</component>
|
||||
@@ -0,0 +1,33 @@
|
||||
import "pkg:/source/services/SponsorBlock.bs"
|
||||
import "pkg:/source/services/Invidious.bs"
|
||||
|
||||
sub Init()
|
||||
' set the name of the function in the Task node component to be executed when the state field changes to RUN
|
||||
' in our case this method executed after the following cmd: m.contentTask.control = "run"(see Init method in MainScene)
|
||||
m.top.functionName = "GetVideoContent"
|
||||
end sub
|
||||
|
||||
sub GetVideoContent()
|
||||
metadata = GetVideoMetadata()
|
||||
sponsorBlock = GetVideoSponsorBlock()
|
||||
|
||||
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||
content = {}
|
||||
content["metadata"] = metadata
|
||||
content["sponsorblock"] = sponsorBlock
|
||||
|
||||
contentNode.addFields(content)
|
||||
m.top.content = contentNode
|
||||
end sub
|
||||
|
||||
function GetVideoMetadata()
|
||||
videoId = m.top.getField("videoid")
|
||||
|
||||
return RokuYoutube.Services.Invidious.GetVideoMetadataForVideo(videoId)
|
||||
end function
|
||||
|
||||
function GetVideoSponsorBlock()
|
||||
videoId = m.top.getField("videoid")
|
||||
|
||||
return RokuYoutube.Services.SponsorBlock.GetSkipSegmentsForVideo(videoId)
|
||||
end function
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="VideoDetailsLoaderTask" extends="Task">
|
||||
<interface>
|
||||
<field id="content" type="node" />
|
||||
<field id="videoid" type="string" />
|
||||
</interface>
|
||||
|
||||
<script type="text/brightscript" uri="VideoDetailsLoaderTask.brs" />
|
||||
</component>
|
||||
Reference in new issue
Block a user