diff --git a/source/api/Items.brs b/source/api/Items.brs index 40e40957..61af42e9 100644 --- a/source/api/Items.brs +++ b/source/api/Items.brs @@ -397,11 +397,13 @@ function BackdropImage(id as string) end function ' Seasons for a TV Show -function TVSeasons(id as string) +function TVSeasons(id as string) as dynamic url = Substitute("Shows/{0}/Seasons", id) resp = APIRequest(url, { "UserId": get_setting("active_user") }) - data = getJson(resp) + ' validate data + if data = invalid or data.Items = invalid then return invalid + results = [] for each item in data.Items imgParams = { "AddPlayedIndicator": item.UserData.Played } @@ -414,11 +416,14 @@ function TVSeasons(id as string) return data end function -function TVEpisodes(show_id as string, season_id as string) +function TVEpisodes(show_id as string, season_id as string) as dynamic url = Substitute("Shows/{0}/Episodes", show_id) resp = APIRequest(url, { "seasonId": season_id, "UserId": get_setting("active_user"), "fields": "MediaStreams" }) data = getJson(resp) + ' validate data + if data = invalid or data.Items = invalid then return invalid + results = [] for each item in data.Items imgParams = { "maxWidth": 400, "maxheight": 250 } @@ -428,7 +433,11 @@ function TVEpisodes(show_id as string, season_id as string) tmp.image.posterDisplayMode = "scaleToZoom" end if tmp.json = item - tmp.overview = ItemMetaData(item.id).overview + tmpMetaData = ItemMetaData(item.id) + ' validate meta data + if tmpMetaData <> invalid and tmpMetaData.overview <> invalid + tmp.overview = tmpMetaData.overview + end if results.push(tmp) end for data.Items = results diff --git a/source/api/baserequest.brs b/source/api/baserequest.brs index 1253f762..6d00f36b 100644 --- a/source/api/baserequest.brs +++ b/source/api/baserequest.brs @@ -35,13 +35,15 @@ function buildParams(params = {} as object) as string return param_array.join("&") end function -function buildURL(path as string, params = {} as object) as string +function buildURL(path as string, params = {} as object) as dynamic + serverURL = get_url() + if serverURL = invalid then return invalid ' Add intial '/' if path does not start with one if path.Left(1) = "/" - full_url = get_url() + path + full_url = serverURL + path else - full_url = get_url() + "/" + path + full_url = serverURL + "/" + path end if if params.count() > 0 @@ -51,17 +53,19 @@ function buildURL(path as string, params = {} as object) as string return full_url end function -function APIRequest(url as string, params = {} as object) +function APIRequest(url as string, params = {} as object) as dynamic + full_url = buildURL(url, params) + if full_url = invalid then return invalid + req = createObject("roUrlTransfer") + req.setUrl(full_url) + req = authorize_request(req) + ' SSL cert serverURL = get_setting("server") if serverURL <> invalid and serverURL.left(8) = "https://" req.setCertificatesFile("common:/certs/ca-bundle.crt") end if - full_url = buildURL(url, params) - req.setUrl(full_url) - req = authorize_request(req) - return req end function @@ -119,18 +123,18 @@ function deleteVoid(req) end function function get_url() - base = get_setting("server") - if base <> invalid - if base.right(1) = "/" - base = base.left(base.len() - 1) - end if + serverURL = get_setting("server") + if serverURL = invalid then return invalid - ' append http:// to the start if not specified - if base.left(7) <> "http://" and base.left(8) <> "https://" - base = "http://" + base - end if + if serverURL.right(1) = "/" + serverURL = serverURL.left(serverURL.len() - 1) end if - return base + + ' append http:// to the start if not specified + if serverURL.left(7) <> "http://" and serverURL.left(8) <> "https://" + serverURL = "http://" + serverURL + end if + return serverURL end function function authorize_request(request) diff --git a/source/utils/Subtitles.brs b/source/utils/Subtitles.brs index 13126df2..ba9a41a0 100644 --- a/source/utils/Subtitles.brs +++ b/source/utils/Subtitles.brs @@ -84,17 +84,18 @@ function setupSubtitle(video, subtitles, subtitle_idx = -1) as integer selectedSubtitle = subtitles[subtitleSelIdx] - if selectedSubtitle.IsEncoded - ' With encoded subtitles, turn off captions - video.globalCaptionMode = "Off" - else - ' If this is a text-based subtitle, set relevant settings for roku captions - video.globalCaptionMode = "On" - video.subtitleTrack = video.availableSubtitleTracks[availSubtitleTrackIdx(video, subtitleSelIdx)].TrackName + if isValid(selectedSubtitle) and isValid(selectedSubtitle.IsEncoded) + if selectedSubtitle.IsEncoded + ' With encoded subtitles, turn off captions + video.globalCaptionMode = "Off" + else + ' If this is a text-based subtitle, set relevant settings for roku captions + video.globalCaptionMode = "On" + video.subtitleTrack = video.availableSubtitleTracks[availSubtitleTrackIdx(video, subtitleSelIdx)].TrackName + end if end if return subtitleSelIdx - end function ' The subtitle index on the server differs from the index we track locally