2019-10-11 19:01:46 +00:00
|
|
|
function ItemsList(params = {} as object)
|
2019-04-20 22:28:28 +00:00
|
|
|
' Gets items based on a query.
|
|
|
|
resp = APIRequest("Items", params)
|
|
|
|
data = getJson(resp)
|
|
|
|
' TODO - parse items
|
|
|
|
return data
|
|
|
|
end function
|
|
|
|
|
2019-10-11 19:01:46 +00:00
|
|
|
function UserItems(params = {} as object)
|
2019-04-20 22:28:28 +00:00
|
|
|
' Gets items based on a query
|
|
|
|
resp = APIRequest(Substitute("Items/{0}/Items", get_setting("active_user")), params)
|
|
|
|
data = getJson(resp)
|
|
|
|
' TODO - parse items
|
|
|
|
return data
|
|
|
|
end function
|
|
|
|
|
2019-10-11 19:01:46 +00:00
|
|
|
function UserItemsResume(params = {} as object)
|
2019-04-20 22:28:28 +00:00
|
|
|
' Gets items based on a query
|
|
|
|
resp = APIRequest(Substitute("Items/{0}/Items/Resume", get_setting("active_user")), params)
|
|
|
|
data = getJson(resp)
|
|
|
|
' TODO - parse items
|
|
|
|
return data
|
|
|
|
end function
|
|
|
|
|
2020-02-22 00:50:20 +00:00
|
|
|
function ItemGetSession(id as string, StartTimeTicks = 0 as longinteger)
|
2020-02-15 01:47:06 +00:00
|
|
|
params = {
|
|
|
|
UserId: get_setting("active_user"),
|
2020-02-22 00:50:20 +00:00
|
|
|
StartTimeTicks: StartTimeTicks,
|
2020-02-15 01:47:06 +00:00
|
|
|
IsPlayback: "true",
|
|
|
|
AutoOpenLiveStream: "true",
|
2020-02-15 16:34:22 +00:00
|
|
|
MaxStreamingBitrate: "140000000"
|
2020-02-15 01:47:06 +00:00
|
|
|
}
|
|
|
|
resp = APIRequest(Substitute("Items/{0}/PlaybackInfo", id), params)
|
|
|
|
data = getJson(resp)
|
|
|
|
return data.PlaySessionId
|
|
|
|
end function
|
2019-04-20 22:28:28 +00:00
|
|
|
|
2019-03-19 02:59:23 +00:00
|
|
|
' List of available libraries
|
|
|
|
function LibraryList()
|
|
|
|
url = Substitute("Users/{0}/Views/", get_setting("active_user"))
|
|
|
|
resp = APIRequest(url)
|
2019-04-14 23:34:50 +00:00
|
|
|
data = getJson(resp)
|
|
|
|
results = []
|
|
|
|
for each item in data.Items
|
|
|
|
tmp = CreateObject("roSGNode", "LibraryData")
|
|
|
|
tmp.json = item
|
2019-10-13 08:59:51 +00:00
|
|
|
params = { "Tag" : tmp.json.ImageTags.Primary, "maxHeight" : 261, "maxWidth" : 464 }
|
|
|
|
tmp.imageURL = ImageURL(tmp.json.id, "Primary", params)
|
2019-04-14 23:34:50 +00:00
|
|
|
results.push(tmp)
|
|
|
|
end for
|
|
|
|
data.Items = results
|
|
|
|
return data
|
2019-03-19 02:59:23 +00:00
|
|
|
end function
|
|
|
|
|
|
|
|
' Search across all libraries
|
2019-10-11 19:01:46 +00:00
|
|
|
function SearchMedia(query as string)
|
2019-05-10 04:42:25 +00:00
|
|
|
' This appears to be done differently on the web now
|
|
|
|
' For each potential type, a separate query is done:
|
|
|
|
' varying item types, and artists, and people
|
|
|
|
resp = APIRequest(Substitute("Users/{0}/Items", get_setting("active_user")), {
|
|
|
|
"searchTerm": query,
|
|
|
|
"IncludePeople": true,
|
|
|
|
"IncludeMedia": true,
|
|
|
|
"IncludeGenres": false,
|
|
|
|
"IncludeStudios": false,
|
|
|
|
"IncludeArtists": false,
|
|
|
|
' "IncludeItemTypes: "Movie",
|
2019-10-11 19:01:46 +00:00
|
|
|
"EnableTotalRecordCount": false,
|
2019-05-10 04:42:25 +00:00
|
|
|
"ImageTypeLimit": 1,
|
|
|
|
"Recursive": true
|
|
|
|
})
|
2019-03-19 02:59:23 +00:00
|
|
|
data = getJson(resp)
|
2019-04-15 00:16:47 +00:00
|
|
|
results = []
|
2019-05-10 04:42:25 +00:00
|
|
|
for each item in data.Items
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp = CreateObject("roSGNode", "SearchData")
|
2019-05-10 04:42:25 +00:00
|
|
|
tmp.image = PosterImage(item.id)
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp.json = item
|
|
|
|
results.push(tmp)
|
2019-03-19 02:59:23 +00:00
|
|
|
end for
|
2019-04-15 00:16:47 +00:00
|
|
|
data.SearchHints = results
|
2019-03-19 02:59:23 +00:00
|
|
|
return data
|
|
|
|
end function
|
|
|
|
|
|
|
|
' List items from within a library
|
2019-10-11 19:01:46 +00:00
|
|
|
function ItemList(library_id = invalid as string, params = {})
|
2019-03-19 02:59:23 +00:00
|
|
|
if params["limit"] = invalid
|
|
|
|
params["limit"] = 30
|
|
|
|
end if
|
|
|
|
if params["page"] = invalid
|
|
|
|
params["page"] = 1
|
|
|
|
end if
|
|
|
|
params["parentid"] = library_id
|
|
|
|
url = Substitute("Users/{0}/Items/", get_setting("active_user"))
|
|
|
|
resp = APIRequest(url, params)
|
|
|
|
data = getJson(resp)
|
2019-04-06 00:27:35 +00:00
|
|
|
results = []
|
2019-03-19 02:59:23 +00:00
|
|
|
for each item in data.Items
|
2019-10-12 01:23:53 +00:00
|
|
|
imgParams = {}
|
|
|
|
if item.ImageTags.Primary <> invalid then
|
|
|
|
' If Primary image exists use it
|
|
|
|
param = { "Tag" : item.ImageTags.Primary }
|
|
|
|
imgParams.Append(param)
|
|
|
|
end if
|
|
|
|
param = { "AddPlayedIndicator": item.UserData.Played }
|
|
|
|
imgParams.Append(param)
|
|
|
|
if item.UserData.PlayedPercentage <> invalid then
|
|
|
|
param = { "PercentPlayed": item.UserData.PlayedPercentage }
|
|
|
|
imgParams.Append(param)
|
|
|
|
end if
|
2019-04-06 00:27:35 +00:00
|
|
|
if item.type = "Movie"
|
|
|
|
tmp = CreateObject("roSGNode", "MovieData")
|
2019-10-12 01:23:53 +00:00
|
|
|
tmp.image = PosterImage(item.id, imgParams)
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp.json = item
|
2019-04-06 00:27:35 +00:00
|
|
|
results.push(tmp)
|
2019-04-06 00:35:29 +00:00
|
|
|
else if item.type = "Series"
|
2019-10-12 01:23:53 +00:00
|
|
|
if item.UserData.UnplayedItemCount > 0 then
|
|
|
|
param = { "UnplayedCount" : item.UserData.UnplayedItemCount }
|
|
|
|
imgParams.Append(param)
|
|
|
|
end if
|
2019-04-06 00:35:29 +00:00
|
|
|
tmp = CreateObject("roSGNode", "SeriesData")
|
2019-10-12 01:23:53 +00:00
|
|
|
tmp.image = PosterImage(item.id, imgParams)
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp.json = item
|
|
|
|
results.push(tmp)
|
2019-04-15 00:24:03 +00:00
|
|
|
else if item.type = "BoxSet"
|
2019-10-12 01:32:16 +00:00
|
|
|
if item.UserData.UnplayedItemCount > 0 then
|
|
|
|
param = { "UnplayedCount" : item.UserData.UnplayedItemCount }
|
|
|
|
imgParams.Append(param)
|
|
|
|
end if
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp = CreateObject("roSGNode", "CollectionData")
|
2019-10-12 01:23:53 +00:00
|
|
|
tmp.image = PosterImage(item.id, imgParams)
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp.json = item
|
2019-04-06 00:35:29 +00:00
|
|
|
results.push(tmp)
|
2019-04-06 00:27:35 +00:00
|
|
|
else
|
2019-04-06 00:35:29 +00:00
|
|
|
print item.type
|
2019-04-06 00:27:35 +00:00
|
|
|
' Otherwise we just stick with the JSON
|
|
|
|
results.push(item)
|
|
|
|
end if
|
2019-03-19 02:59:23 +00:00
|
|
|
end for
|
2019-04-06 00:27:35 +00:00
|
|
|
data.items = results
|
2019-03-19 02:59:23 +00:00
|
|
|
return data
|
|
|
|
end function
|
|
|
|
|
|
|
|
' MetaData about an item
|
2019-10-11 19:01:46 +00:00
|
|
|
function ItemMetaData(id as string)
|
2019-03-19 02:59:23 +00:00
|
|
|
url = Substitute("Users/{0}/Items/{1}", get_setting("active_user"), id)
|
|
|
|
resp = APIRequest(url)
|
|
|
|
data = getJson(resp)
|
2019-04-06 00:35:29 +00:00
|
|
|
if data.type = "Movie"
|
|
|
|
tmp = CreateObject("roSGNode", "MovieData")
|
2019-05-10 04:24:19 +00:00
|
|
|
tmp.image = PosterImage(data.id)
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp.json = data
|
2019-04-06 00:35:29 +00:00
|
|
|
return tmp
|
|
|
|
else if data.type = "Series"
|
|
|
|
tmp = CreateObject("roSGNode", "SeriesData")
|
2019-05-10 04:24:19 +00:00
|
|
|
tmp.image = PosterImage(data.id)
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp.json = data
|
2019-04-06 00:35:29 +00:00
|
|
|
return tmp
|
2019-04-21 20:11:54 +00:00
|
|
|
else if data.type = "Episode"
|
|
|
|
tmp = CreateObject("roSGNode", "TVEpisodeData")
|
2019-05-10 04:24:19 +00:00
|
|
|
tmp.image = PosterImage(data.id)
|
2019-04-21 20:11:54 +00:00
|
|
|
tmp.json = data
|
|
|
|
return tmp
|
2019-04-15 00:24:03 +00:00
|
|
|
else if data.type = "BoxSet"
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp = CreateObject("roSGNode", "CollectionData")
|
2019-05-10 04:24:19 +00:00
|
|
|
tmp.image = PosterImage(data.id)
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp.json = item
|
2019-04-21 20:11:54 +00:00
|
|
|
return tmp
|
2019-04-06 00:35:29 +00:00
|
|
|
else
|
|
|
|
print data.type
|
|
|
|
' Return json if we don't know what it is
|
|
|
|
return data
|
|
|
|
end if
|
2019-03-19 02:59:23 +00:00
|
|
|
return data
|
|
|
|
end function
|
|
|
|
|
|
|
|
' Seasons for a TV Show
|
2019-10-11 19:01:46 +00:00
|
|
|
function TVSeasons(id as string)
|
2019-03-19 02:59:23 +00:00
|
|
|
url = Substitute("Shows/{0}/Seasons", id)
|
2019-10-11 19:01:46 +00:00
|
|
|
resp = APIRequest(url, { "UserId": get_setting("active_user") })
|
2019-03-19 02:59:23 +00:00
|
|
|
|
|
|
|
data = getJson(resp)
|
2019-04-15 00:16:47 +00:00
|
|
|
results = []
|
2019-03-19 02:59:23 +00:00
|
|
|
for each item in data.Items
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp = CreateObject("roSGNode", "TVEpisodeData")
|
2019-05-10 04:24:19 +00:00
|
|
|
tmp.image = PosterImage(item.id)
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp.json = item
|
|
|
|
results.push(tmp)
|
2019-03-19 02:59:23 +00:00
|
|
|
end for
|
2019-04-15 00:16:47 +00:00
|
|
|
data.Items = results
|
2019-03-19 02:59:23 +00:00
|
|
|
return data
|
|
|
|
end function
|
|
|
|
|
2019-10-11 19:01:46 +00:00
|
|
|
function TVEpisodes(show_id as string, season_id as string)
|
2019-04-14 04:47:27 +00:00
|
|
|
url = Substitute("Shows/{0}/Episodes", show_id)
|
2019-10-11 19:01:46 +00:00
|
|
|
resp = APIRequest(url, { "seasonId": season_id, "UserId": get_setting("active_user") })
|
2019-04-14 04:47:27 +00:00
|
|
|
|
|
|
|
data = getJson(resp)
|
2019-04-15 00:16:47 +00:00
|
|
|
results = []
|
2019-04-14 04:47:27 +00:00
|
|
|
for each item in data.Items
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp = CreateObject("roSGNode", "TVEpisodeData")
|
2019-05-10 04:24:19 +00:00
|
|
|
tmp.image = PosterImage(item.id)
|
2019-12-07 02:49:37 +00:00
|
|
|
if tmp.image <> invalid
|
|
|
|
tmp.image.posterDisplayMode = "scaleToFit"
|
|
|
|
end if
|
2019-04-15 00:16:47 +00:00
|
|
|
tmp.json = item
|
|
|
|
results.push(tmp)
|
2019-04-14 04:47:27 +00:00
|
|
|
end for
|
2019-04-15 00:16:47 +00:00
|
|
|
data.Items = results
|
2019-04-14 04:47:27 +00:00
|
|
|
return data
|
|
|
|
end function
|
|
|
|
|
2019-03-19 02:59:23 +00:00
|
|
|
' The next up episode for a TV show
|
2019-10-11 19:01:46 +00:00
|
|
|
function TVNext(id as string)
|
2019-03-19 02:59:23 +00:00
|
|
|
url = Substitute("Shows/NextUp", id)
|
2019-10-11 19:01:46 +00:00
|
|
|
resp = APIRequest(url, { "UserId": get_setting("active_user"), "SeriesId": id })
|
2019-03-19 02:59:23 +00:00
|
|
|
|
|
|
|
data = getJson(resp)
|
|
|
|
for each item in data.Items
|
2019-05-10 04:24:19 +00:00
|
|
|
item.image = PosterImage(item.id)
|
2019-03-19 02:59:23 +00:00
|
|
|
end for
|
|
|
|
return data
|
|
|
|
end function
|