2023-05-03 21:21:04 +00:00
|
|
|
import "pkg:/source/api/baserequest.brs"
|
|
|
|
import "pkg:/source/utils/config.brs"
|
|
|
|
|
2020-11-23 17:13:57 +00:00
|
|
|
sub init()
|
|
|
|
m.top.functionName = "loadChannels"
|
2021-07-09 20:08:32 +00:00
|
|
|
end sub
|
|
|
|
|
|
|
|
sub loadChannels()
|
|
|
|
|
2020-11-23 17:13:57 +00:00
|
|
|
results = []
|
2021-07-09 20:08:32 +00:00
|
|
|
|
2022-09-05 06:50:13 +00:00
|
|
|
sort_field = m.top.sortField
|
|
|
|
|
|
|
|
if m.top.sortAscending = true
|
|
|
|
sort_order = "Ascending"
|
|
|
|
else
|
|
|
|
sort_order = "Descending"
|
|
|
|
end if
|
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
params = {
|
2022-09-05 06:50:13 +00:00
|
|
|
includeItemTypes: "LiveTvChannel",
|
|
|
|
SortBy: sort_field,
|
|
|
|
SortOrder: sort_order,
|
|
|
|
recursive: m.top.recursive,
|
2023-06-01 12:43:27 +00:00
|
|
|
UserId: m.global.session.user.id
|
2020-11-23 17:13:57 +00:00
|
|
|
}
|
2021-07-09 20:08:32 +00:00
|
|
|
|
2022-09-05 06:50:13 +00:00
|
|
|
' Handle special case when getting names starting with numeral
|
|
|
|
if m.top.NameStartsWith <> ""
|
|
|
|
if m.top.NameStartsWith = "#"
|
|
|
|
params.searchterm = "A"
|
|
|
|
else
|
|
|
|
params.searchterm = m.top.nameStartsWith
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
'Append voice search when there is text
|
|
|
|
if m.top.searchTerm <> ""
|
|
|
|
params.searchTerm = m.top.searchTerm
|
|
|
|
end if
|
|
|
|
|
2021-08-01 08:49:08 +00:00
|
|
|
if m.top.filter = "Favorites"
|
|
|
|
params.append({ isFavorite: true })
|
|
|
|
end if
|
|
|
|
|
2023-06-01 12:43:27 +00:00
|
|
|
url = Substitute("Users/{0}/Items/", m.global.session.user.id)
|
2020-11-23 17:13:57 +00:00
|
|
|
|
|
|
|
resp = APIRequest(url, params)
|
|
|
|
data = getJson(resp)
|
2021-07-09 20:08:32 +00:00
|
|
|
|
2021-06-26 13:52:16 +00:00
|
|
|
if data.TotalRecordCount = invalid
|
2020-11-23 17:13:57 +00:00
|
|
|
m.top.channels = results
|
|
|
|
return
|
|
|
|
end if
|
2021-07-09 20:08:32 +00:00
|
|
|
|
|
|
|
|
2020-11-23 17:13:57 +00:00
|
|
|
for each item in data.Items
|
2021-07-09 20:08:32 +00:00
|
|
|
channel = createObject("roSGNode", "ChannelData")
|
|
|
|
channel.json = item
|
2022-05-14 10:13:28 +00:00
|
|
|
if item.UserData <> invalid and item.UserData.isFavorite <> invalid
|
|
|
|
channel.favorite = item.UserData.isFavorite
|
|
|
|
if channel.favorite = true
|
|
|
|
results.Unshift(channel)
|
|
|
|
else
|
|
|
|
results.push(channel)
|
|
|
|
end if
|
|
|
|
else
|
|
|
|
results.push(channel)
|
|
|
|
end if
|
2021-07-09 20:08:32 +00:00
|
|
|
end for
|
2020-11-23 17:13:57 +00:00
|
|
|
m.top.channels = results
|
2021-07-09 20:08:32 +00:00
|
|
|
end sub
|