jellyfin-roku/components/liveTv/LoadChannelsTask.bs

73 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

import "pkg:/source/api/baserequest.bs"
import "pkg:/source/utils/config.bs"
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
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 = {
includeItemTypes: "LiveTvChannel",
SortBy: sort_field,
SortOrder: sort_order,
recursive: m.top.recursive,
UserId: m.global.session.user.id
2020-11-23 17:13:57 +00:00
}
2021-07-09 20:08:32 +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
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
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