Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Croznut
Level 7

Parsing HLS Data From JSON File

Hey there, I'm in the final stages of setting up my feed and have run into an issue. My app loads, images, title, and descriptions pull in, but I can't for the life of me figure out how to get the HLS file to pull in...

The output of my JSON file looks like this (URLS and names have been pulled) ->

{
    "providerName": "NAME",
    "lastUpdated": "2019-12-18T22:21:37+00:00",
    "language": "en",

    "results":[
        {
            "title":"Title",
            "short_description":"Title",
            "hls_url":"VIDEO FILE",
            "thumbnail":"Image URL"
        },

 

I'm using a template provided by Roku which is below and am trying to figure out how to rewrite this so it pulls in the hls_url 

This is the original way it was written. How would i rewrite this to pull the hls file where it's listed above? 

function GetVideoUrl(mediaItem as Object) as String
content = mediaItem.Lookup("content")
if content = invalid then
return ""
end if

videos = content.Lookup("videos")
if videos = invalid then
return ""
end if

entry = videos.GetEntry(0)
if entry = invalid then
return ""
end if

url = entry.Lookup("url")
if url = invalid then
return ""
end if

return url
end function

0 Kudos
3 Replies
blankwalrus
Level 7

Re: Parsing HLS Data From JSON File

I'm not sure where the template you are using came from.

You can see an example on how to parse JSON and use the output here: https://developer.roku.com/docs/references/brightscript/language/global-utility-functions.md#parsejs...

 

What is the mediaItem object you are passing in to the GetVideoUrl function? If it is your JSON string, then I believe this may work for you

 

function GetVideoUrl(mediaItem as Object) as String
    videos = mediaItem.Lookup("results")
    if videos = invalid then
        return ""
    end if

    entry = videos.GetEntry(0)
    if entry = invalid then
        return ""
    end if

    url = entry.Lookup("hls_url")
    if url = invalid then
        return ""
    end if

    return url
end function
0 Kudos
Croznut
Level 7

Re: Parsing HLS Data From JSON File

Hey there, thank you for this!

So i updated the file with the line you had and it still doesn't work... This is the file i'm using...

https://github.com/rokudev/SceneGraphDeveloperExtensions/blob/master/samples/6_Endcards/components/c...

The JSON file i'm using is setup different than this feed as the "results" as listed above is in the root of the JSON file.

 

example.png

 

 

0 Kudos
blankwalrus
Level 7

Re: Parsing HLS Data From JSON File

I recommend you look at the tutorial link I posted. It contains a simple example on how to parse a file such as the one you posted.

 

If you are using the file from Github that you linked, you need to make sure and change the ParseJsonToNodeArray function as well because it is expecting your JSON to have a movies section and a series section.

0 Kudos