Skip to content

Commit

Permalink
Add support for TV show season level extra features
Browse files Browse the repository at this point in the history
  • Loading branch information
jarodaerts committed Oct 15, 2023
1 parent 1465c62 commit e8ed687
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
32 changes: 29 additions & 3 deletions components/tvshows/TVEpisodes.brs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sub init()
m.rows = m.top.findNode("picker")
m.poster = m.top.findNode("seasonPoster")
m.Shuffle = m.top.findNode("Shuffle")
m.Extras = m.top.findNode("Extras")
m.tvEpisodeRow = m.top.findNode("tvEpisodeRow")

m.unplayedCount = m.top.findNode("unplayedCount")
Expand All @@ -21,6 +22,12 @@ sub setSeasonLoading()
m.top.overhangTitle = tr("Loading...")
end sub

sub setExtraButtonVisibility()
if isValid(m.top.extrasObjects) and (not m.top.extrasObjects.items.IsEmpty())
m.Extras.visible = true
end if
end sub

sub updateSeason()
if m.global.session.user.settings["ui.tvshows.disableUnwatchedEpisodeCount"] = false
if isValid(m.top.seasonData) and isValid(m.top.seasonData.UserData) and isValid(m.top.seasonData.UserData.UnplayedItemCount)
Expand All @@ -45,13 +52,23 @@ function onKeyEvent(key as string, press as boolean) as boolean
return true
end if

if key = "right" and (m.Shuffle.hasFocus())
if key = "right" and (m.Shuffle.hasFocus() or m.Extras.hasFocus())
m.tvEpisodeRow.setFocus(true)
return true
end if

if key = "OK" or key = "play"
showExtras = isValid(m.top.extrasObjects) and (not m.top.extrasObjects.IsEmpty())
if showExtras and key = "up" and (m.Extras.hasFocus())
m.Shuffle.setFocus(true)
return true
end if

if showExtras and key = "down" and (m.Shuffle.hasFocus())
m.Extras.setFocus(true)
return true
end if

if key = "OK" or key = "play"
if m.Shuffle.hasFocus()
episodeList = m.rows.getChild(0).objects.items

Expand All @@ -66,6 +83,16 @@ function onKeyEvent(key as string, press as boolean) as boolean
m.global.queueManager.callFunc("playQueue")
return true
end if

if showExtras and m.Extras.hasFocus()
if m.Extras.text.trim() = "Extras"
m.Extras.text = "Episodes"
m.top.objects = m.top.extrasObjects
else
m.Extras.text = "Extras"
m.top.objects = m.top.episodeObjects
end if
end if
end if

focusedChild = m.top.focusedChild.focusedChild
Expand All @@ -81,7 +108,6 @@ function onKeyEvent(key as string, press as boolean) as boolean
m.top.lastFocus = focusedChild
itemToPlay = focusedChild.content.getChild(focusedChild.rowItemFocused[0]).getChild(0)
if isValid(itemToPlay) and isValid(itemToPlay.id) and itemToPlay.id <> ""
itemToPlay.type = "Episode"
m.top.quickPlayNode = itemToPlay
end if
handled = true
Expand Down
3 changes: 3 additions & 0 deletions components/tvshows/TVEpisodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
</Rectangle>
</Poster>
<JFButton id="Shuffle" minChars="10" text="Shuffle" translation="[90, 640]" visible="false"></JFButton>
<JFButton id="Extras" minChars="10" text="Extras" translation="[90, 740]" visible="false"></JFButton>
<TVEpisodeRowWithOptions id="picker" visible="true" />
</children>
<interface>
<field id="episodeSelected" alias="picker.itemSelected" />
<field id="quickPlayNode" type="node" alwaysNotify="true" />
<field id="seasonData" type="assocarray" onChange="setSeasonLoading" />
<field id="objects" alias="picker.objects" />
<field id="episodeObjects" type="assocarray" />
<field id="extrasObjects" type="assocarray" onChange="setExtraButtonVisibility" />
</interface>
</component>
4 changes: 1 addition & 3 deletions settings/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"type": "bool",
"default": "false"
}

]
},
{
Expand Down Expand Up @@ -126,7 +125,6 @@
]
}
]

},
{
"title": "Video Codec Support",
Expand Down Expand Up @@ -362,4 +360,4 @@
}
]
}
]
]
6 changes: 6 additions & 0 deletions source/ShowScenes.brs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,9 @@ function CreateSeasonDetailsGroup(series as object, season as object) as dynamic
m.global.sceneManager.callFunc("pushScene", group)
group.seasonData = seasonMetaData.json
group.objects = TVEpisodes(series.id, season.id)
group.episodeObjects = group.objects
group.extrasObjects = TVSeasonExtras(season.id)

' watch for button presses
group.observeField("episodeSelected", m.port)
group.observeField("quickPlayNode", m.port)
Expand Down Expand Up @@ -770,6 +773,9 @@ function CreateSeasonDetailsGroupByID(seriesID as string, seasonID as string) as
m.global.sceneManager.callFunc("pushScene", group)
group.seasonData = seasonMetaData.json
group.objects = TVEpisodes(seriesID, seasonID)
group.episodeObjects = group.objects
group.extrasObjects = TVSeasonExtras(seasonID)

' watch for button presses
group.observeField("episodeSelected", m.port)
group.observeField("quickPlayNode", m.port)
Expand Down
35 changes: 35 additions & 0 deletions source/api/Items.brs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,41 @@ function TVEpisodes(show_id as string, season_id as string) as dynamic
return data
end function

function TVSeasonExtras(season_id as string) as dynamic
url = Substitute("/Users/{0}/Items/{1}/SpecialFeatures", m.global.session.user.id, season_id)
resp = APIRequest(url)

' validate data
data = getJson(resp)
if data = invalid then return invalid

results = []
for each item in data
imgParams = { "maxWidth": 400, "maxheight": 250 }
tmp = CreateObject("roSGNode", "TVEpisodeData")
tmp.image = PosterImage(item.id, imgParams)
if tmp.image <> invalid
tmp.image.posterDisplayMode = "scaleToZoom"
end if
tmp.json = item

' Force item type to Video so episode auto queue is not attempted
tmp.type = "Video"
tmpMetaData = ItemMetaData(item.id)

' Validate meta data
if tmpMetaData <> invalid and tmpMetaData.overview <> invalid
tmp.overview = tmpMetaData.overview
end if
results.push(tmp)
end for

' Build that data format that the TVEpisodeRow expects
extrasData = { Items: [] }
extrasData.Items = results
return extrasData
end function

function TVEpisodeShuffleList(show_id as string)
url = Substitute("Shows/{0}/Episodes", show_id)
resp = APIRequest(url, {
Expand Down

0 comments on commit e8ed687

Please sign in to comment.