jf-roku/components/ItemGrid/LoadItemsTask2.brs

101 lines
3.1 KiB
Plaintext
Raw Normal View History

sub init()
2021-07-09 20:08:32 +00:00
m.top.functionName = "loadItems"
end sub
sub loadItems()
2021-07-09 20:08:32 +00:00
results = []
sort_field = m.top.sortField
if m.top.sortAscending = true
sort_order = "Ascending"
else
2021-07-09 20:08:32 +00:00
sort_order = "Descending"
end if
params = {
limit: m.top.limit,
StartIndex: m.top.startIndex,
parentid: m.top.itemId,
SortBy: sort_field,
SortOrder: sort_order,
recursive: m.top.recursive,
Fields: "Overview"
}
2022-04-29 07:03:01 +00:00
' Handle special case when getting names starting with numeral
if m.top.NameStartsWith <> ""
if m.top.NameStartsWith = "#"
params.NameLessThan = "A"
else
params.NameStartsWith = m.top.nameStartsWith
end if
end if
2021-07-09 20:08:32 +00:00
filter = m.top.filter
if filter = "All" or filter = "all"
' do nothing
else if filter = "Favorites"
params.append({ Filters: "IsFavorite" })
2021-08-01 08:49:08 +00:00
params.append({ isFavorite: true })
end if
2021-07-09 20:08:32 +00:00
if m.top.ItemType <> ""
params.append({ IncludeItemTypes: m.top.ItemType })
end if
2021-07-09 20:08:32 +00:00
if m.top.ItemType = "LiveTV"
url = "LiveTv/Channels"
2022-05-14 10:13:28 +00:00
params.append({ UserId: get_setting("active_user") })
2021-07-09 20:08:32 +00:00
else
url = Substitute("Users/{0}/Items/", get_setting("active_user"))
end if
resp = APIRequest(url, params)
2022-05-21 15:45:38 +00:00
data = getJson(resp)
2022-05-16 00:08:14 +00:00
if data <> invalid
if data.TotalRecordCount <> invalid then m.top.totalRecordCount = data.TotalRecordCount
for each item in data.Items
tmp = invalid
if item.Type = "Movie"
tmp = CreateObject("roSGNode", "MovieData")
else if item.Type = "Series"
tmp = CreateObject("roSGNode", "SeriesData")
else if item.Type = "BoxSet"
tmp = CreateObject("roSGNode", "CollectionData")
else if item.Type = "TvChannel"
tmp = CreateObject("roSGNode", "ChannelData")
else if item.Type = "Folder" or item.Type = "ChannelFolderItem" or item.Type = "CollectionFolder"
tmp = CreateObject("roSGNode", "FolderData")
else if item.Type = "Video"
tmp = CreateObject("roSGNode", "VideoData")
2022-05-22 22:20:34 +00:00
else if item.Type = "Photo"
tmp = CreateObject("roSGNode", "PhotoData")
else if item.type = "PhotoAlbum"
tmp = CreateObject("roSGNode", "FolderData")
2022-05-15 12:30:55 +00:00
else if item.Type = "MusicArtist" or item.Type = "MusicAlbum"
2022-05-14 02:35:50 +00:00
tmp = CreateObject("roSGNode", "MusicArtistData")
else if item.Type = "Audio"
tmp = CreateObject("roSGNode", "MusicSongData")
else
print "[LoadItems] Unknown Type: " item.Type
end if
if tmp <> invalid
tmp.json = item
2022-05-14 10:13:28 +00:00
if item.UserData <> invalid and item.UserData.isFavorite <> invalid
tmp.favorite = item.UserData.isFavorite
end if
results.push(tmp)
end if
end for
end if
2021-07-09 20:08:32 +00:00
m.top.content = results
2022-05-30 12:57:40 +00:00
end sub