2019-04-20 22:28:28 +00:00
|
|
|
function ItemsList(params={} as object)
|
|
|
|
' Gets items based on a query.
|
|
|
|
resp = APIRequest("Items", params)
|
|
|
|
data = getJson(resp)
|
|
|
|
' TODO - parse items
|
|
|
|
return data
|
|
|
|
end function
|
|
|
|
|
|
|
|
function UserItems(params={} as object)
|
|
|
|
' 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
|
|
|
|
|
|
|
|
function UserItemsResume(params={} as object)
|
|
|
|
' 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
results.push(tmp)
|
|
|
|
end for
|
|
|
|
data.Items = results
|
|
|
|
return data
|
2019-03-19 02:59:23 +00:00
|
|
|
end function
|
|
|
|
|
|
|
|
' Search across all libraries
|
|
|
|
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",
|
|
|
|
"EnableTotalRecordCount": false,
|
|
|
|
"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
|
|
|
|
function ItemList(library_id=invalid as String, params={})
|
|
|
|
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-04-06 00:27:35 +00:00
|
|
|
if item.type = "Movie"
|
|
|
|
tmp = CreateObject("roSGNode", "MovieData")
|
2019-05-10 04:24:19 +00:00
|
|
|
tmp.image = PosterImage(item.id)
|
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"
|
|
|
|
tmp = CreateObject("roSGNode", "SeriesData")
|
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-04-15 00:24:03 +00:00
|
|
|
else if item.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(item.id)
|
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
|
|
|
|
function ItemMetaData(id as String)
|
|
|
|
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
|
|
|
|
function TVSeasons(id as String)
|
|
|
|
url = Substitute("Shows/{0}/Seasons", id)
|
|
|
|
resp = APIRequest(url, {"UserId": get_setting("active_user")})
|
|
|
|
|
|
|
|
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-04-14 04:47:27 +00:00
|
|
|
function TVEpisodes(show_id as String, season_id as String)
|
|
|
|
url = Substitute("Shows/{0}/Episodes", show_id)
|
|
|
|
resp = APIRequest(url, {"seasonId": season_id, "UserId": get_setting("active_user")})
|
|
|
|
|
|
|
|
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-07-23 03:11:13 +00:00
|
|
|
tmp.image.posterDisplayMode = "scaleToFit"
|
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
|
|
|
|
function TVNext(id as String)
|
|
|
|
url = Substitute("Shows/NextUp", id)
|
|
|
|
resp = APIRequest(url, {"UserId": get_setting("active_user"), "SeriesId": id})
|
|
|
|
|
|
|
|
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
|