From 4dcc3ad9f73c76450828177bc318c8dffaa24536 Mon Sep 17 00:00:00 2001 From: Charles Ewert Date: Sat, 23 Sep 2023 12:32:50 -0400 Subject: [PATCH] add quickplay support for series networks and genres --- components/ItemGrid/ItemGrid.brs | 14 +++++- source/utils/quickplay.bs | 82 +++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 31 deletions(-) diff --git a/components/ItemGrid/ItemGrid.brs b/components/ItemGrid/ItemGrid.brs index 92c109156..00da31c6e 100644 --- a/components/ItemGrid/ItemGrid.brs +++ b/components/ItemGrid/ItemGrid.brs @@ -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 @@ -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 diff --git a/source/utils/quickplay.bs b/source/utils/quickplay.bs index 7127d9c13..25a7acb42 100644 --- a/source/utils/quickplay.bs +++ b/source/utils/quickplay.bs @@ -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. @@ -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"], @@ -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" @@ -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 @@ -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 @@ -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