Your Digital Media Has Never Looked So Good

 
deejannon
Topic Author
Posts: 1
Joined: Fri Dec 01, 2017 5:47 pm

Help with getting video links

Fri Dec 01, 2017 6:22 pm

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
 
renojim
** Valued Community Member **
Posts: 3182
Joined: Mon Feb 15, 2010 1:35 pm

Re: Help with getting video links

Sat Dec 02, 2017 1:04 am

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

Who is online

Users browsing this forum: bbrouse and 6 guests