Repository navigation
Expand file tree
/
Copy pathTVSeriesDetails.bs
More file actions
572 lines (480 loc) · 18.6 KB
/
Copy pathTVSeriesDetails.bs
File metadata and controls
572 lines (480 loc) · 18.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
import "pkg:/source/constants/HomeRowItemSizes.bs"
import "pkg:/source/enums/AnimationControl.bs"
import "pkg:/source/enums/ColorPalette.bs"
import "pkg:/source/enums/KeyCode.bs"
import "pkg:/source/enums/PosterLoadStatus.bs"
import "pkg:/source/enums/ViewLoadStatus.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/misc.bs"
sub init()
m.top.optionsAvailable = false
m.extrasSlider = m.top.findNode("tvSeasonExtras")
m.getShuffleEpisodesTask = createObject("roSGNode", "getShuffleEpisodesTask")
m.extrasSlider.visible = false
m.seasons = m.top.findNode("seasons")
m.seasons.focusBitmapBlendColor = chainLookupReturn(m.global.session, "user.settings.colorCursor", ColorPalette.HIGHLIGHT)
m.overview = m.top.findNode("overview")
m.playedIndicator = m.top.findNode("playedIndicator")
m.tvshowPoster = m.top.findNode("tvshowPoster")
m.overview.ellipsisText = tr("...")
m.loadStatus = ViewLoadStatus.INIT
seasonListRect = m.top.FindNode("seasonListRect")
seasonListRect.color = ColorPalette.BLACK77
m.defaultClippingRect = "[-10,-10,2020,370]"
m.toplevel = m.top.findnode("toplevel")
m.seasonListRect = m.top.findnode("seasonListRect")
m.revealSeasonsAnimation = m.top.findNode("revealSeasonsAnimation")
m.toplevelTranslation = m.top.findNode("toplevelTranslation")
m.seasonListRectTranslation = m.top.findNode("seasonListRectTranslation")
m.seasonsTranslation = m.top.findNode("seasonsTranslation")
m.seasonListRectHeight = m.top.findNode("seasonListRectHeight")
m.seasonListRectWidth = m.top.findNode("seasonListRectWidth")
m.buttonGrp = m.top.findNode("buttons")
m.buttonCount = m.buttonGrp.getChildCount()
m.resume = m.top.findNode("resume")
if isValid(m.resume)
m.resume.focusBackground = chainLookupReturn(m.global.session, "user.settings.colorCursor", ColorPalette.HIGHLIGHT)
end if
m.extras = m.top.findNode("extras")
if isValid(m.extras)
m.extras.focusBackground = chainLookupReturn(m.global.session, "user.settings.colorCursor", ColorPalette.HIGHLIGHT)
end if
m.play = m.top.findNode("play")
m.play.focusBackground = chainLookupReturn(m.global.session, "user.settings.colorCursor", ColorPalette.HIGHLIGHT)
m.shuffle = m.top.findNode("shuffle")
m.shuffle.focusBackground = chainLookupReturn(m.global.session, "user.settings.colorCursor", ColorPalette.HIGHLIGHT)
m.previouslySelectedButtonIndex = -1
m.top.observeField("selectedButtonIndex", "onButtonSelectedChange")
m.top.selectedButtonIndex = 0
setFontSizes()
end sub
sub onDisplayResumeButtonChange()
' Remove the resume button
if not m.top.displayResumeButton
m.buttonGrp.removeChild(m.resume)
m.resume = invalid
m.buttonCount = m.buttonGrp.getChildCount()
if m.toplevel.translation[1] = 100
onButtonSelectedChange()
end if
return
end if
' Add resume button back
if not isValid(m.resume)
previousSelectedButton = m.buttonGrp.getChild(m.top.selectedButtonIndex)
previousSelectedButton.focus = false
m.resume = createObject("roSGNode", "IconButton")
m.resume.focusBackground = chainLookupReturn(m.global.session, "user.settings.colorCursor", ColorPalette.HIGHLIGHT)
m.resume.id = "resume"
m.resume.background = "#070707"
m.resume.padding = "35"
m.resume.icon = "pkg:/images/icons/resume.png"
m.resume.text = "Resume"
m.resume.height = "65"
m.resume.width = "140"
m.buttonGrp.insertChild(m.resume, 0)
m.buttonCount = m.buttonGrp.getChildCount()
if m.buttonGrp.isInFocusChain()
onButtonSelectedChange()
end if
end if
end sub
' Event handler when user selected a different playback button
sub onButtonSelectedChange()
' Change previously focused button back to default
if m.previouslySelectedButtonIndex > -1
previousSelectedButton = m.buttonGrp.getChild(m.previouslySelectedButtonIndex)
previousSelectedButton.focus = false
end if
' Change selected button image to focus state
selectedButton = m.buttonGrp.getChild(m.top.selectedButtonIndex)
selectedButton.setfocus(true)
selectedButton.focus = true
end sub
sub setFontSizes()
if isValid(m.overview)
m.overview.font.size = 27
end if
title = m.top.findNode("title")
if isValid(title)
title.font.size = 45
end if
runtime = m.top.findNode("runtime")
if isValid(runtime)
runtime.font.size = 23
end if
numberofepisodes = m.top.findNode("numberofepisodes")
if isValid(numberofepisodes)
numberofepisodes.font.size = 23
end if
released = m.top.findNode("released")
if isValid(released)
released.font.size = 23
end if
genres = m.top.findNode("genres")
if isValid(genres)
genres.font.size = 23
end if
rating = m.top.findNode("rating")
if isValid(rating)
rating.font.size = 23
end if
communityReview = m.top.findNode("communityReview")
if isValid(communityReview)
communityReview.font.size = 23
end if
history = m.top.findNode("history")
if isValid(history)
history.font.size = 23
end if
end sub
sub onPosterLoadStatusChanged()
if isStringEqual(m.tvshowPoster.loadStatus, PosterLoadStatus.FAILED)
tryLoadingSeasonPoster()
m.tvshowPoster.unobserveFieldScoped("loadStatus")
end if
end sub
sub tryLoadingSeasonPoster()
for each season in m.seasons.content.getChildren(-1, 0)
if isValidAndNotEmpty(season.posterURL)
m.tvshowPoster.uri = season.posterURL
exit for
end if
end for
end sub
sub itemContentChanged()
' Updates video metadata
item = m.top.itemContent
itemData = item.json
' Post image may change. We need to again watch load status
m.tvshowPoster.observeFieldscoped("loadStatus", "onPosterLoadStatusChanged")
m.tvshowPoster.uri = m.top.itemContent.posterURL
m.playedIndicator.data = {
played: chainLookupReturn(item, "json.UserData.Played", false),
unplayedCount: chainLookupReturn(item, "json.UserData.UnplayedItemCount", 0)
}
setFieldText("title", itemData.name)
if type(itemData.RunTimeTicks) = "LongInteger"
setFieldText("runtime", stri(getRuntime()) + " mins")
else
m.top.findNode("topLevelDetails").removeChild(m.top.findNode("runtimeContainer"))
end if
if isChainValid(item, "json.RecursiveItemCount")
setFieldText("numberofepisodes", stri(item.json.RecursiveItemCount) + " episodes")
else
m.top.findNode("topLevelDetails").removeChild(m.top.findNode("numberofepisodesContainer"))
end if
'Check production year, if invalid remove label
if isValid(itemData.productionYear)
setFieldText("released", itemData.productionYear)
else
m.top.findNode("topLevelDetails").removeChild(m.top.findNode("releasedContainer"))
end if
'Check rating, if invalid remove label
if isValid(itemData.officialRating)
setFieldText("rating", itemData.officialRating)
else
m.top.findNode("topLevelDetails").removeChild(m.top.findNode("ratingContainer"))
end if
'Check communityReview, if invalid remove label
if chainLookupReturn(m.global.session, "user.settings.`ui.itemdetail.showRatings`", true)
if isValid(itemData.communityRating)
setFieldText("communityReview", int(itemData.communityRating * 10) / 10)
else
m.top.findNode("topLevelDetails").removeChild(m.top.findNode("communityReviewContainer"))
end if
else
m.top.findNode("topLevelDetails").removeChild(m.top.findNode("communityReviewContainer"))
end if
'History field is set via the function getHistory()
setFieldText("history", getHistory())
'Check genres, if invalid remove label
if isValidAndNotEmpty(itemData.genres)
setFieldText("genres", itemData.genres.join(", "))
else
m.top.findNode("topLevelDetails").removeChild(m.top.findNode("genresContainer"))
end if
setFieldText("overview", itemData.overview)
if isStringEqual(m.loadStatus, ViewLoadStatus.INIT)
m.loadStatus = ViewLoadStatus.FIRSTLOAD
return
end if
end sub
sub setFieldText(field, value)
node = m.top.findNode(field)
if node = invalid or value = invalid then return
' Handle non strings... Which _shouldn't_ happen, but hey
if type(value) = "roInt" or type(value) = "Integer"
value = str(value).trim()
else if type(value) = "roFloat" or type(value) = "Float"
value = str(value).trim()
else if type(value) <> "roString" and type(value) <> "String"
value = ""
end if
node.text = value
end sub
function getRuntime() as integer
itemData = m.top.itemContent.json
' A tick is .1ms, so 1/10,000,000 for ticks to seconds,
' then 1/60 for seconds to minutess... 1/600,000,000
return round(itemData.RunTimeTicks / 600000000.0)
end function
function getEndTime() as string
itemData = m.top.itemContent.json
date = CreateObject("roDateTime")
duration_s = int(itemData.RunTimeTicks / 10000000.0)
date.fromSeconds(date.asSeconds() + duration_s)
date.toLocalTime()
return formatTime(date)
end function
function getHistory() as string
itemData = m.top.itemContent.json
' Aired Fridays at 9:30 PM on ABC (US)
airwords = invalid
studio = invalid
if itemData.status = "Ended"
verb = "Aired"
else
verb = "Airs"
end if
airdays = itemData.airdays
airtime = itemData.airtime
if isValid(airtime) and airdays.count() = 1
airwords = airdays[0] + " at " + airtime
end if
if itemData.studios.count() > 0
studio = itemData.studios[0].name
end if
if studio = invalid and airwords = invalid
m.top.findNode("topLevelDetails").removeChild(m.top.findNode("historyContainer"))
return ""
end if
words = verb
if isValid(airwords)
words = words + " " + airwords
end if
if isValid(studio)
words = words + " on " + studio
end if
return words
end function
function round(f as float) as integer
' BrightScript only has a "floor" round
' This compares floor to floor + 1 to find which is closer
m = int(f)
n = m + 1
x = abs(f - m)
y = abs(f - n)
if y > x
return m
else
return n
end if
end function
sub OnScreenShown()
scene = m.top.getScene()
if isValid(scene)
overhang = scene.findNode("overhang")
if chainLookupReturn(overhang, "isVisible", false)
overhang.isVisible = false
end if
end if
if isValid(m.top.lastFocus)
m.top.lastFocus.setFocus(true)
group = m.global.sceneManager.callFunc("getActiveScene")
group.lastFocus = m.top.lastFocus
else
firstButton = m.buttonGrp.getChild(0)
firstButton.setFocus(true)
group = m.global.sceneManager.callFunc("getActiveScene")
group.lastFocus = firstButton
end if
if isStringEqual(m.loadStatus, ViewLoadStatus.INIT)
return
end if
m.top.refreshSeasonDetailsData = not m.top.refreshSeasonDetailsData
end sub
function getFocusedItem() as object
if m.seasons.isInFocusChain()
itemFocused = m.seasons.itemFocused
return m.seasons.content.getChild(itemFocused)
end if
if m.extrasSlider.isInFocusChain()
extrasGrid = m.top.findNode("extrasGrid")
if isValid(extrasGrid.focusedItem)
return extrasGrid.focusedItem
end if
end if
return invalid
end function
sub onShuffleEpisodeDataLoaded()
m.getShuffleEpisodesTask.unobserveField("data")
m.global.queueManager.callFunc("set", m.getShuffleEpisodesTask.data.items)
m.global.queueManager.callFunc("playQueue")
end sub
sub createFullDscrDlg()
if isAllValid([m.top.itemContent.json.name, m.top.itemContent.json.overview])
m.global.sceneManager.callFunc("standardDialog", m.top.itemContent.json.name, { data: ["<p>" + m.top.itemContent.json.overview + "</p>"] })
end if
end sub
sub enterEpisodeListFullScreen()
if m.toplevel.translation[1] <> 100 then return
m.seasonListRect.color = ColorPalette.BLACKDD
m.toplevelTranslation.reverse = false
m.seasonListRectTranslation.reverse = false
m.seasonsTranslation.reverse = false
m.seasonListRectHeight.reverse = false
m.seasonListRectWidth.reverse = false
m.revealSeasonsAnimation.control = AnimationControl.START
m.seasons.clippingRect = "[-10,-10,2020,980]"
end sub
sub exitEpisodeListFullScreen()
m.seasonListRect.color = ColorPalette.BLACK77
m.toplevelTranslation.reverse = true
m.seasonListRectTranslation.reverse = true
m.seasonsTranslation.reverse = true
m.seasonListRectHeight.reverse = true
m.seasonListRectWidth.reverse = true
m.revealSeasonsAnimation.control = AnimationControl.START
m.seasons.clippingRect = m.defaultClippingRect
end sub
function onKeyEvent(key as string, press as boolean) as boolean
seasonRow = m.top.findNode("seasons")
extrasSection = m.top.findNode("extrasGrid")
if m.buttonGrp.isInFocusChain()
if isStringEqual(key, KeyCode.UP)
if m.buttonGrp.getChild(m.top.selectedButtonIndex).escape = "up"
if not isStringEqual(m.overview.text, string.EMPTY)
m.buttonGrp.getChild(m.top.selectedButtonIndex).escape = ""
selectedButton = m.buttonGrp.getChild(m.top.selectedButtonIndex)
selectedButton.focus = false
m.overview.setFocus(true)
m.overview.color = chainLookupReturn(m.global.session, "user.settings.colorCursor", ColorPalette.HIGHLIGHT)
m.top.lastFocus = m.overview
return true
end if
end if
end if
if isStringEqual(key, KeyCode.OK) or isStringEqual(key, KeyCode.PLAY)
if not press then return false
if m.shuffle.hasFocus()
m.getShuffleEpisodesTask.showID = m.top.itemContent.id
m.getShuffleEpisodesTask.observeField("data", "onShuffleEpisodeDataLoaded")
m.getShuffleEpisodesTask.control = "RUN"
return true
end if
if isValid(m.resume)
if m.resume.hasFocus()
quickplayData = m.top.itemContent
quickplayData.quickplayFromResume = true
m.top.quickPlayNode = quickplayData
return true
end if
end if
if m.extras.hasFocus()
extrasSection.setFocus(true)
m.extrasSlider.visible = true
group = m.global.sceneManager.callFunc("getActiveScene")
group.lastFocus = extrasSection
m.top.findNode("VertSlider").reverse = false
m.top.findNode("extrasFader").reverse = false
m.top.findNode("pplAnime").control = AnimationControl.START
return true
end if
if m.play.hasFocus()
m.top.playSeriesFromStart = not m.top.playSeriesFromStart
return true
end if
return false
end if
if isStringEqual(key, KeyCode.LEFT)
if m.top.selectedButtonIndex = 0 then return false
if m.buttonGrp.getChild(m.top.selectedButtonIndex).escape = "left"
m.buttonGrp.getChild(m.top.selectedButtonIndex).escape = ""
m.previouslySelectedButtonIndex = m.top.selectedButtonIndex
m.top.selectedButtonIndex = m.top.selectedButtonIndex - 1
return true
end if
end if
if isStringEqual(key, KeyCode.RIGHT)
if m.top.selectedButtonIndex < m.buttonCount - 1
m.previouslySelectedButtonIndex = m.top.selectedButtonIndex
m.top.selectedButtonIndex = m.top.selectedButtonIndex + 1
return true
end if
end if
if isStringEqual(key, KeyCode.DOWN)
if m.buttonGrp.getChild(m.top.selectedButtonIndex).escape = "down"
m.buttonGrp.getChild(m.top.selectedButtonIndex).escape = ""
selectedButton = m.buttonGrp.getChild(m.top.selectedButtonIndex)
selectedButton.focus = false
m.seasons.setFocus(true)
m.top.lastFocus = m.seasons
enterEpisodeListFullScreen()
return true
end if
end if
end if
if not press then return false
if m.overview.hasFocus()
if key = KeyCode.OK
createFullDscrDlg()
return true
end if
if key = KeyCode.DOWN
m.overview.color = ColorPalette.WHITE
selectedButton = m.buttonGrp.getChild(m.top.selectedButtonIndex)
selectedButton.focus = true
selectedButton.setfocus(true)
return true
end if
end if
if seasonRow.isInFocusChain()
if isStringEqual(key, KeyCode.BACK)
exitEpisodeListFullScreen()
onButtonSelectedChange()
return true
end if
return false
end if
if m.overview.isInFocusChain()
if isStringEqual(key, KeyCode.DOWN)
onButtonSelectedChange()
return true
end if
end if
if extrasSection.isInFocusChain()
if isStringEqual(key, KeyCode.BACK)
m.top.findNode("VertSlider").reverse = true
m.top.findNode("extrasFader").reverse = true
m.top.findNode("pplAnime").control = "start"
m.extrasSlider.visible = false
onButtonSelectedChange()
return true
end if
if isStringEqual(key, KeyCode.UP)
if extrasSection.itemFocused = 0
m.top.findNode("VertSlider").reverse = true
m.top.findNode("extrasFader").reverse = true
m.top.findNode("pplAnime").control = "start"
m.extrasSlider.visible = false
onButtonSelectedChange()
return true
end if
end if
end if
if key = "play" and m.seasons.hasFocus()
if isValid(m.seasons.content)
itemFocused = m.seasons.itemFocused
m.top.quickPlayNode = m.seasons.content.getChild(itemFocused)
return true
end if
else if key = "play" and m.extrasSlider.isInFocusChain()
extrasGrid = m.top.findNode("extrasGrid")
if extrasGrid.focusedItem <> invalid
m.top.quickPlayNode = extrasGrid.focusedItem
return true
end if
end if
return false
end function