Skip to content

Commit

Permalink
add quickplay support for series networks and genres
Browse files Browse the repository at this point in the history
  • Loading branch information
cewert committed Sep 23, 2023
1 parent 080c8e8 commit 4dcc3ad
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 31 deletions.
14 changes: 12 additions & 2 deletions components/ItemGrid/ItemGrid.brs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,16 @@ sub onChannelFocused(msg)
m.channelFocused = node.focusedChannel
end sub

'Returns Focused Item
function getItemFocused()
if m.itemGrid.isinFocusChain() and isValid(m.itemGrid.itemFocused)
return m.itemGrid.content.getChild(m.itemGrid.itemFocused)
else if m.genreList.isinFocusChain() and isValid(m.genreList.rowItemFocused)
return m.genreList.content.getChild(m.genreList.rowItemFocused[0]).getChild(m.genreList.rowItemFocused[1])
end if
return invalid
end function

function onKeyEvent(key as string, press as boolean) as boolean
if not press then return false

Expand Down Expand Up @@ -782,8 +792,8 @@ function onKeyEvent(key as string, press as boolean) as boolean
end if
else if key = "play"
markupGrid = m.top.findNode("itemGrid")
itemToPlay = markupGrid.content.getChild(markupGrid.itemFocused)

itemToPlay = getItemFocused()
print "itemToPlay=", itemToPlay
if itemToPlay <> invalid
m.top.quickPlayNode = itemToPlay
return true
Expand Down
82 changes: 53 additions & 29 deletions source/utils/quickplay.bs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,36 @@ namespace quickplay
end if
end sub

' More than one TV Show Series.
' Shuffle play all watched episodes
sub multipleSeries(itemNodes as object)
if isValidAndNotEmpty(itemNodes)
for each tvshow in itemNodes
' grab all watched episodes for each series
showData = api.shows.GetEpisodes(tvshow.id, {
"userId": m.global.session.user.id,
"imageTypeLimit": 0,
"EnableTotalRecordCount": false,
"enableImages": false
})

if isValid(showData) and isValidAndNotEmpty(showData.items)
' add all played episodes to queue
for each episode in showData.items
if isValid(episode.userdata) and isValid(episode.userdata.Played)
if episode.userdata.Played
m.global.queueManager.callFunc("push", episode)
end if
end if
end for
end if
end for
if m.global.queueManager.callFunc("getCount") > 1
m.global.queueManager.callFunc("toggleShuffle")
end if
end if
end sub

' A TV Show Season.
' Play the first unwatched episode.
' If none, play the whole season starting with episode 1.
Expand Down Expand Up @@ -276,7 +306,6 @@ namespace quickplay
' Shuffle play all items found
sub folder(itemNode as object)
if not isValid(itemNode) or not isValid(itemNode.id) then return
print "itemNode.json=", itemNode.json

paramArray = {
"includeItemTypes": ["Episode", "Movie", "Video"],
Expand All @@ -289,6 +318,8 @@ namespace quickplay
}
' modify api query based on folder type
folderType = Lcase(itemNode.json.type)

' modify qpi query based on folder type
if folderType = "studio"
paramArray["studioIds"] = itemNode.id
else if folderType = "genre"
Expand All @@ -300,16 +331,28 @@ namespace quickplay
else
paramArray["parentId"] = itemNode.id
end if
' loof for tv series in stead of video files
if isValid(itemNode.json.SeriesCount) and itemNode.json.SeriesCount > 0
paramArray["includeItemTypes"] = "Series"
paramArray.Delete("videoTypes")
end if
' get folder items
folderData = api.users.GetItemsByQuery(m.global.session.user.id, paramArray)
print "folderData=", folderData

if isValid(folderData) and isValidAndNotEmpty(folderData.items)
pushToQueue(folderData.items)

' don't show shuffle icon for 1 item
if folderData.items.count() > 1
m.global.queueManager.callFunc("toggleShuffle")
if isValid(itemNode.json.SeriesCount) and itemNode.json.SeriesCount > 0
if itemNode.json.SeriesCount = 1
quickplay.series(folderData.items[0])
else
quickplay.multipleSeries(folderData.items)
end if
else
pushToQueue(folderData.items)
' don't show shuffle icon for 1 item
if folderData.items.count() > 1
m.global.queueManager.callFunc("toggleShuffle")
end if
end if
end if
end sub
Expand Down Expand Up @@ -340,7 +383,9 @@ namespace quickplay
end if
end if
end for
m.global.queueManager.callFunc("toggleShuffle")
if m.global.queueManager.callFunc("getCount") > 1
m.global.queueManager.callFunc("toggleShuffle")
end if
end if
else if collectionType = "music"
' get all audio files under this collection
Expand Down Expand Up @@ -402,28 +447,7 @@ namespace quickplay
print "tvshowsData=", tvshowsData

if isValid(tvshowsData) and isValidAndNotEmpty(tvshowsData.items)
for each tvshow in tvshowsData.items
' grab all watched episodes for each series
showData = api.shows.GetEpisodes(tvshow.id, {
"userId": m.global.session.user.id,
"imageTypeLimit": 0,
"EnableTotalRecordCount": false,
"enableImages": false
})

if isValid(showData) and isValidAndNotEmpty(showData.items)
' add all played episodes to queue
for each episode in showData.items
if isValid(episode.userdata) and isValid(episode.userdata.Played)
if episode.userdata.Played
m.global.queueManager.callFunc("push", episode)
end if
end if
end for

end if
end for
m.global.queueManager.callFunc("toggleShuffle")
quickplay.multipleSeries(tvshowsData.items)
end if
else if collectionType = "musicvideos"
' get randomized list of videos inside
Expand Down

0 comments on commit 4dcc3ad

Please sign in to comment.