2023-10-03 16:11:25 +00:00
|
|
|
import "pkg:/source/api/Items.bs"
|
|
|
|
import "pkg:/source/api/baserequest.bs"
|
|
|
|
import "pkg:/source/utils/config.bs"
|
|
|
|
import "pkg:/source/utils/misc.bs"
|
|
|
|
import "pkg:/source/api/Image.bs"
|
|
|
|
import "pkg:/source/utils/deviceCapabilities.bs"
|
2023-10-03 16:27:07 +00:00
|
|
|
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
2023-05-05 17:45:53 +00:00
|
|
|
import "pkg:/source/api/sdk.bs"
|
2023-05-03 21:21:04 +00:00
|
|
|
|
2020-06-10 16:43:32 +00:00
|
|
|
sub init()
|
2023-05-03 21:21:04 +00:00
|
|
|
m.log = log.Logger("LoadItemsTask2")
|
2021-07-09 20:08:32 +00:00
|
|
|
m.top.functionName = "loadItems"
|
2022-09-05 06:50:13 +00:00
|
|
|
|
|
|
|
m.top.limit = 60
|
2023-06-01 12:43:27 +00:00
|
|
|
usersettingLimit = m.global.session.user.settings["itemgrid.Limit"]
|
2022-09-05 06:50:13 +00:00
|
|
|
|
|
|
|
if usersettingLimit <> invalid
|
|
|
|
m.top.limit = usersettingLimit
|
|
|
|
end if
|
2020-06-10 16:43:32 +00:00
|
|
|
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"
|
2020-06-10 16:43:32 +00:00
|
|
|
else
|
2021-07-09 20:08:32 +00:00
|
|
|
sort_order = "Descending"
|
|
|
|
end if
|
|
|
|
|
2022-09-24 00:16:52 +00:00
|
|
|
if m.top.ItemType = "LogoImage"
|
2023-05-05 17:45:53 +00:00
|
|
|
logoImageExists = api.items.HeadImageURLByName(m.top.itemId, "logo")
|
2022-09-24 00:16:52 +00:00
|
|
|
if logoImageExists
|
2023-05-05 17:45:53 +00:00
|
|
|
m.top.content = [api.items.GetImageURL(m.top.itemId, "logo", 0, { "maxHeight": 500, "maxWidth": 500, "quality": "90" })]
|
2022-09-24 00:16:52 +00:00
|
|
|
else
|
|
|
|
m.top.content = []
|
|
|
|
end if
|
|
|
|
|
|
|
|
return
|
|
|
|
end if
|
2021-07-09 20:08:32 +00:00
|
|
|
|
|
|
|
params = {
|
|
|
|
limit: m.top.limit,
|
|
|
|
StartIndex: m.top.startIndex,
|
|
|
|
parentid: m.top.itemId,
|
|
|
|
SortBy: sort_field,
|
|
|
|
SortOrder: sort_order,
|
|
|
|
recursive: m.top.recursive,
|
2022-07-09 08:39:29 +00:00
|
|
|
Fields: "Overview",
|
|
|
|
StudioIds: m.top.studioIds,
|
|
|
|
genreIds: m.top.genreIds
|
2021-07-09 20:08:32 +00:00
|
|
|
}
|
2022-09-05 06:50:13 +00:00
|
|
|
|
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 = "#"
|
2022-09-05 06:50:13 +00:00
|
|
|
if m.top.ItemType = "LiveTV" or m.top.ItemType = "TvChannel"
|
|
|
|
params.searchterm = "A"
|
|
|
|
params.append({ parentid: " " })
|
|
|
|
else
|
|
|
|
params.NameLessThan = "A"
|
|
|
|
end if
|
2022-04-29 07:03:01 +00:00
|
|
|
else
|
2022-09-05 06:50:13 +00:00
|
|
|
if m.top.ItemType = "LiveTV" or m.top.ItemType = "TvChannel"
|
|
|
|
params.searchterm = m.top.nameStartsWith
|
|
|
|
params.append({ parentid: " " })
|
|
|
|
else
|
|
|
|
params.NameStartsWith = m.top.nameStartsWith
|
|
|
|
end if
|
2022-04-29 07:03:01 +00:00
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
2022-12-06 19:56:21 +00:00
|
|
|
'reset data
|
2022-12-06 20:14:12 +00:00
|
|
|
if LCase(m.top.searchTerm) = LCase(tr("all"))
|
2022-12-06 19:56:21 +00:00
|
|
|
params.searchTerm = " "
|
|
|
|
else if m.top.searchTerm <> ""
|
2022-09-05 06:50:13 +00:00
|
|
|
params.searchTerm = m.top.searchTerm
|
|
|
|
end if
|
|
|
|
|
2022-12-06 20:16:33 +00:00
|
|
|
filter = LCase(m.top.filter)
|
|
|
|
if filter = "all"
|
2021-07-09 20:08:32 +00:00
|
|
|
' do nothing
|
2022-12-06 20:16:33 +00:00
|
|
|
else if filter = "favorites"
|
2021-07-09 20:08:32 +00:00
|
|
|
params.append({ Filters: "IsFavorite" })
|
2021-08-01 08:49:08 +00:00
|
|
|
params.append({ isFavorite: true })
|
2022-12-14 23:55:46 +00:00
|
|
|
else if filter = "unplayed"
|
|
|
|
params.append({ Filters: "IsUnplayed" })
|
|
|
|
else if filter = "played"
|
|
|
|
params.append({ Filters: "IsPlayed" })
|
2022-12-15 00:10:40 +00:00
|
|
|
else if filter = "resumable"
|
|
|
|
params.append({ Filters: "IsResumable" })
|
2020-06-10 16:43:32 +00:00
|
|
|
end if
|
2020-10-17 19:07:32 +00:00
|
|
|
|
2023-02-25 19:51:36 +00:00
|
|
|
if isValid(m.top.filterOptions)
|
|
|
|
if m.top.filterOptions.count() > 0
|
|
|
|
params.append(m.top.filterOptions)
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
if m.top.ItemType <> ""
|
|
|
|
params.append({ IncludeItemTypes: m.top.ItemType })
|
|
|
|
end if
|
2020-06-10 16:43:32 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
if m.top.ItemType = "LiveTV"
|
|
|
|
url = "LiveTv/Channels"
|
2023-06-01 12:43:27 +00:00
|
|
|
params.append({ UserId: m.global.session.user.id })
|
2022-07-09 08:39:29 +00:00
|
|
|
else if m.top.view = "Networks"
|
|
|
|
url = "Studios"
|
2023-06-01 12:43:27 +00:00
|
|
|
params.append({ UserId: m.global.session.user.id })
|
2022-07-09 08:39:29 +00:00
|
|
|
else if m.top.view = "Genres"
|
|
|
|
url = "Genres"
|
2023-06-01 12:43:27 +00:00
|
|
|
params.append({ UserId: m.global.session.user.id, includeItemTypes: m.top.itemType })
|
2022-09-27 01:26:17 +00:00
|
|
|
else if m.top.ItemType = "MusicArtist"
|
|
|
|
url = "Artists"
|
|
|
|
params.append({
|
2023-06-01 12:43:27 +00:00
|
|
|
UserId: m.global.session.user.id,
|
2022-12-31 02:59:19 +00:00
|
|
|
Fields: "Genres"
|
2022-09-27 01:26:17 +00:00
|
|
|
})
|
2022-12-31 02:59:19 +00:00
|
|
|
params.IncludeItemTypes = "MusicAlbum,Audio"
|
2023-04-06 00:07:53 +00:00
|
|
|
else if m.top.ItemType = "AlbumArtists"
|
|
|
|
url = "Artists/AlbumArtists"
|
|
|
|
params.append({
|
2023-06-01 12:43:27 +00:00
|
|
|
UserId: m.global.session.user.id,
|
2023-04-06 00:07:53 +00:00
|
|
|
Fields: "Genres"
|
|
|
|
})
|
|
|
|
params.IncludeItemTypes = "MusicAlbum,Audio"
|
2022-10-02 18:23:42 +00:00
|
|
|
else if m.top.ItemType = "MusicAlbum"
|
2023-06-01 12:43:27 +00:00
|
|
|
url = Substitute("Users/{0}/Items/", m.global.session.user.id)
|
2022-10-02 18:23:42 +00:00
|
|
|
params.append({ ImageTypeLimit: 1 })
|
|
|
|
params.append({ EnableImageTypes: "Primary,Backdrop,Banner,Thumb" })
|
2021-07-09 20:08:32 +00:00
|
|
|
else
|
2023-06-01 12:43:27 +00:00
|
|
|
url = Substitute("Users/{0}/Items/", m.global.session.user.id)
|
2021-07-09 20:08:32 +00:00
|
|
|
end if
|
2022-12-14 23:55:46 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
resp = APIRequest(url, params)
|
2022-05-21 15:45:38 +00:00
|
|
|
data = getJson(resp)
|
2022-04-25 07:24:08 +00:00
|
|
|
if data <> invalid
|
|
|
|
|
|
|
|
if data.TotalRecordCount <> invalid then m.top.totalRecordCount = data.TotalRecordCount
|
|
|
|
|
|
|
|
for each item in data.Items
|
|
|
|
tmp = invalid
|
2022-09-21 19:36:38 +00:00
|
|
|
if item.Type = "Movie" or item.Type = "MusicVideo"
|
2022-04-25 07:24:08 +00:00
|
|
|
tmp = CreateObject("roSGNode", "MovieData")
|
|
|
|
else if item.Type = "Series"
|
|
|
|
tmp = CreateObject("roSGNode", "SeriesData")
|
2022-09-05 06:50:13 +00:00
|
|
|
else if item.Type = "BoxSet" or item.Type = "ManualPlaylistsFolder"
|
2022-04-25 07:24:08 +00:00
|
|
|
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")
|
2023-01-04 18:54:22 +00:00
|
|
|
else if item.Type = "Video" or item.Type = "Recording"
|
2022-04-25 07:24:08 +00:00
|
|
|
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")
|
2023-02-25 16:43:36 +00:00
|
|
|
else if item.type = "Playlist"
|
|
|
|
tmp = CreateObject("roSGNode", "PlaylistData")
|
|
|
|
tmp.type = "Playlist"
|
|
|
|
tmp.image = PosterImage(item.id, { "maxHeight": 425, "maxWidth": 290, "quality": "90" })
|
2022-07-09 08:39:29 +00:00
|
|
|
else if item.type = "Episode"
|
|
|
|
tmp = CreateObject("roSGNode", "TVEpisode")
|
|
|
|
else if item.Type = "Genre"
|
2022-09-24 00:16:52 +00:00
|
|
|
tmp = CreateObject("roSGNode", "ContentNode")
|
|
|
|
tmp.title = item.name
|
|
|
|
|
2023-06-01 12:43:27 +00:00
|
|
|
genreData = api.users.GetItemsByQuery(m.global.session.user.id, {
|
2022-09-24 00:16:52 +00:00
|
|
|
SortBy: "Random",
|
|
|
|
SortOrder: "Ascending",
|
2022-12-30 16:11:19 +00:00
|
|
|
IncludeItemTypes: m.top.itemType,
|
2022-09-24 00:16:52 +00:00
|
|
|
Recursive: true,
|
|
|
|
Fields: "PrimaryImageAspectRatio,MediaSourceCount,BasicSyncInfo",
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
EnableImageTypes: "Primary",
|
|
|
|
Limit: 6,
|
|
|
|
GenreIds: item.id,
|
|
|
|
EnableTotalRecordCount: false,
|
|
|
|
ParentId: m.top.itemId
|
|
|
|
})
|
|
|
|
|
|
|
|
if genreData.Items.Count() > 5
|
|
|
|
' Add View All item to the start of the row
|
|
|
|
row = tmp.createChild("FolderData")
|
|
|
|
row.parentFolder = m.top.itemId
|
2022-12-30 16:11:19 +00:00
|
|
|
row.title = tr("View All") + " " + item.name
|
|
|
|
item.name = tr("View All") + " " + item.name
|
2022-09-24 00:16:52 +00:00
|
|
|
row.json = item
|
|
|
|
row.type = "Folder"
|
2022-12-30 16:11:19 +00:00
|
|
|
|
|
|
|
if LCase(m.top.itemType) = "movie"
|
2023-05-05 17:45:53 +00:00
|
|
|
genreItemImage = api.items.GetImageURL(item.id)
|
2022-12-30 16:11:19 +00:00
|
|
|
else
|
|
|
|
genreItemImage = invalid
|
|
|
|
row.posterURL = invalid
|
|
|
|
end if
|
|
|
|
|
|
|
|
row.FHDPOSTERURL = genreItemImage
|
|
|
|
row.HDPOSTERURL = genreItemImage
|
|
|
|
row.SDPOSTERURL = genreItemImage
|
2022-09-24 00:16:52 +00:00
|
|
|
end if
|
|
|
|
|
2022-12-30 16:11:19 +00:00
|
|
|
for each genreItem in genreData.Items
|
|
|
|
if LCase(m.top.itemType) = "movie"
|
|
|
|
row = tmp.createChild("MovieData")
|
|
|
|
else
|
|
|
|
row = tmp.createChild("SeriesData")
|
|
|
|
end if
|
|
|
|
|
2023-05-05 17:45:53 +00:00
|
|
|
genreItemImage = api.items.GetImageURL(genreItem.id)
|
2022-12-30 16:11:19 +00:00
|
|
|
row.title = genreItem.name
|
|
|
|
row.FHDPOSTERURL = genreItemImage
|
|
|
|
row.HDPOSTERURL = genreItemImage
|
|
|
|
row.SDPOSTERURL = genreItemImage
|
|
|
|
row.json = genreItem
|
|
|
|
row.id = genreItem.id
|
|
|
|
row.type = genreItem.type
|
2022-09-24 00:16:52 +00:00
|
|
|
end for
|
|
|
|
|
2022-07-09 08:39:29 +00:00
|
|
|
else if item.Type = "Studio"
|
|
|
|
tmp = CreateObject("roSGNode", "FolderData")
|
2022-09-27 01:26:17 +00:00
|
|
|
else if item.Type = "MusicAlbum"
|
|
|
|
tmp = CreateObject("roSGNode", "MusicAlbumData")
|
2022-10-02 18:23:42 +00:00
|
|
|
tmp.type = "MusicAlbum"
|
2023-05-05 17:45:53 +00:00
|
|
|
if api.items.HeadImageURLByName(item.id, "primary")
|
2022-10-02 18:23:42 +00:00
|
|
|
tmp.posterURL = ImageURL(item.id, "Primary")
|
|
|
|
else
|
|
|
|
tmp.posterURL = ImageURL(item.id, "backdrop")
|
|
|
|
end if
|
2022-09-27 01:26:17 +00:00
|
|
|
else if item.Type = "MusicArtist"
|
2022-05-14 02:35:50 +00:00
|
|
|
tmp = CreateObject("roSGNode", "MusicArtistData")
|
2022-05-15 04:14:42 +00:00
|
|
|
else if item.Type = "Audio"
|
|
|
|
tmp = CreateObject("roSGNode", "MusicSongData")
|
2023-02-25 16:43:36 +00:00
|
|
|
tmp.type = "Audio"
|
2023-05-05 17:45:53 +00:00
|
|
|
tmp.image = api.items.GetImageURL(item.id, "primary", 0, { "maxHeight": 280, "maxWidth": 280, "quality": "90" })
|
2022-12-10 05:06:56 +00:00
|
|
|
else if item.Type = "MusicGenre"
|
|
|
|
tmp = CreateObject("roSGNode", "FolderData")
|
|
|
|
tmp.title = item.name
|
|
|
|
tmp.parentFolder = m.top.itemId
|
|
|
|
tmp.json = item
|
|
|
|
tmp.type = "Folder"
|
2023-05-05 17:45:53 +00:00
|
|
|
tmp.posterUrl = api.items.GetImageURL(item.id, "primary", 0, { "maxHeight": 280, "maxWidth": 280, "quality": "90" })
|
2022-12-10 05:06:56 +00:00
|
|
|
|
2022-04-25 07:24:08 +00:00
|
|
|
else
|
2023-05-03 21:21:04 +00:00
|
|
|
m.log.warn("Unknown Type", item.Type)
|
2022-04-25 07:24:08 +00:00
|
|
|
end if
|
2022-09-24 00:16:52 +00:00
|
|
|
|
2022-04-25 07:24:08 +00:00
|
|
|
if tmp <> invalid
|
2022-12-10 05:06:56 +00:00
|
|
|
if item.Type <> "Genre" and item.Type <> "MusicGenre"
|
2022-09-24 00:16:52 +00:00
|
|
|
tmp.parentFolder = m.top.itemId
|
|
|
|
tmp.json = item
|
|
|
|
if item.UserData <> invalid and item.UserData.isFavorite <> invalid
|
|
|
|
tmp.favorite = item.UserData.isFavorite
|
|
|
|
end if
|
2022-05-14 10:13:28 +00:00
|
|
|
end if
|
2022-09-24 00:16:52 +00:00
|
|
|
|
2022-04-25 07:24:08 +00:00
|
|
|
results.push(tmp)
|
|
|
|
end if
|
|
|
|
end for
|
2020-06-10 16:43:32 +00:00
|
|
|
end if
|
2021-07-09 20:08:32 +00:00
|
|
|
m.top.content = results
|
2022-05-30 12:57:40 +00:00
|
|
|
end sub
|