Roku Developer Program

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

Help with getting video links

Hello All, I'm brand new to developing for Roku, and I've been messing around with some examples trying to get the hang of everything. I've managed to get an app working that parses a json file from a site, and populates a row with thumbnails and info for live streaming content. My problem is the site does not include direct links to play the live video, instead it has links to user pages that contain the live video, and a chatroom. Unless I'm mistaken, I should be able to use GetToString() to fetch the source code from the page and then Match the correct link using regex correct?


So this is what I have, and it doesn't seem to work. I've successfully tested my regex outside of the roku app and it worked, but it does not work in this example. It's supposed to match a link starting with http and ending in m3u8 Any ideas that could point me in the correct direction?

Function PlayVideo(video as object, json as boolean) as integer
    videoScreen = CreateObject("roVideoScreen")
    port = CreateObject("roMessagePort")
    videoScreen.SetMessagePort( port )
    url = createObject("roURLTransfer")
                            url.SetUrl("http://mysite.com/"+video.username)
                            print url.GetUrl()
                            pre = url.GetToString()
                            test = CreateObject("roRegex","\bhttps://[.0-9A-Za-z-]+\.[A-Za-z]{2,63}+(?:/[]!#$%&'()*+,.0-9:;<=>?@A-Z[\\_`a-z{|}~^-]+){2}/[.0-9A-Z_a-z-]+\.m3u8","")
                            streamurl = test.Match(pre)
                            print streamurl
0 Kudos
2 Replies
renojim
Level 8

Re: Help with getting video links

Wow!  I thought I knew regular expressions, but that makes me dizzy just looking at it.  Maybe start with a simpler expression, like "http://.*\.m3u8", and build it up to see where the match fails.

Also, you know that test.Match(pre) will return an array, right?  The print statement should print out the entire array.  The part of the string that matches would be streamurl[0] and any matched subexpressions, if used, would be streamurl[1], streamurl[2], ... etc.

-JT
0 Kudos
norcaljohnny
Level 7

Re: Help with getting video links

Is it possible that the stream you are referring to is not loading because of the Same Origin Policy or CORS? If not make sure you have no ampersand in the url if so, convert it to &amp; or wrap your link in double quotes.

Also why are you not escaping your forward slashes as such>.... http:\/\/
0 Kudos