Massoud Mazar

Sharing The Knowledge

NAVIGATION - SEARCH

Simulate asp.net authentication for Roku player

Few weeks ago I decided to add a channel to my Roku box to play live videos from a Free-To-Air Satellite TV channel. This specific channel has a live video stream from their website which requires authentication. My challenge was to build a Roku app using provided SDK to simulate the authentication process of the asp.net website so I can grab the URL of the live stream. (URL has a token attached to it which requires authentication).

To accomplish this I had to make multiple HTTPs calls to the site from my Roku app, and on each call grab some piece of response and use for the next call. Following code snippet shows how URL of the stream is grabbed from a web page after logging in to the site. (As you can see there are some repeated code which you can move to a separate function, and I leave that to you ):

Function GetLiveFeedUrl() as Dynamic
    ' make sure we have the credentials
    sec = CreateObject("roRegistrySection", "credentials")
    username = sec.Read("username")
    password = sec.Read("password")
    
    if username = "" or password = ""
        if NOT EnterCredentials()
            return false
        end if
    end if
    
    result = ""
    timeout = 10000
    
    ut = CreateObject("roURLTransfer")
    ut.SetPort(CreateObject("roMessagePort"))
    ' setup the transfer for SSL
    ut.SetCertificatesFile("common:/certs/ca-bundle.crt")
    ut.InitClientCertificates()
  
    ut.AddHeader("user-agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31")
    ut.SetURL("https://www.example.com/live")
    
    if ut.AsyncGetToString()
        event = wait(timeout, ut.GetPort())
        if type(event) = "roUrlEvent"
            print event.GetResponseCode()
            result = event.GetString()
        else if event = invalid
            ut.AsyncCancel()
        else
            print "roUrlTransfer::AsyncGetToString(): unknown event"
        endif
    end if

    ' get my IP cookie from JavaScript source
    r = CreateObject("roRegex", "setCookie\(\'YPF8827340282Jdskjhfiw_928937459182JAX666\', \'(.+?)\',", "im")
    MyIP = r.Match(result)[1]
    
    ' send credentials to login page
    LoginData = "UserName=" + ut.Escape(username) + "&Password=" + ut.Escape(password) + "&btnLogin=login"
    cookie = "YPF8827340282Jdskjhfiw_928937459182JAX666=" + MyIP + "; DOAReferrer="
    ut.AddHeader("Cookie", cookie)
    ut.SetURL("https://www.example.com/User/Home/Login")
    
    if ut.AsyncPostFromString(LoginData)
        event = wait(timeout, ut.GetPort())
        if type(event) = "roUrlEvent"
            print event.GetResponseCode()
            result = event.GetString()
        else if event = invalid
            ut.AsyncCancel()
        else
            print "roUrlTransfer::AsyncGetToString(): unknown event"
        endif
    end if    

    ' add auth cookies
    headers = event.GetResponseHeadersArray()
    For Each header in headers
        If header[ "Set-Cookie" ] <> invalid Then 'And header[ "Set-Cookie" ].InStr( cookieName + "=" ) = 0 Then
            cookie = cookie + "; " + header[ "Set-Cookie" ]
      End If
    NEXT
    ut.AddHeader("Cookie", cookie)
    'print cookie
    
    ' now try to find the video URL
    ut.SetURL("http://www.example.com/live")
    
    if ut.AsyncGetToString()
        event = wait(timeout, ut.GetPort())
        if type(event) = "roUrlEvent"
            print event.GetResponseCode()
            result = event.GetString()
        else if event = invalid
            ut.AsyncCancel()
        else
            print "roUrlTransfer::AsyncGetToString(): unknown event"
        endif
    end if
    
    q = chr(34)
    r = CreateObject("roRegex", "(http://.+\.m3u8\?token=[^" +q+ "]+)", "im")
    VideoURL = r.Match(result)[1]
    print VideoURL
    return VideoURL
End Function

Note: This was part of manoto Roku app I created to allow playing the live feed of manoto1 TV on my Roku box.

Comments (12) -

Great Job Massoud, we love and enjoy your app.

Wondering now that you know how it is done, could you please create the roku app for bbcpersian and voa and similar? I have no idea what I am talking about but it seems to me those must be easier as they don't need authentication Smile

Cheers,
Shahram

Reply

Massoud Mazar

Thanks for the comment Shahram,

There are copyright and legal issues involved so one has to have written approval from content providers to release an app like this. I tried to contact Manoto TV to get their approval and no one returned my calls.
I'm sorry to say this, but it is not easy to work with fellow Iranians. Early 2010 I tried to convince GL-Wiz to let me build them something similar on Samsung platform and they turned me down. Took them 4 years to build it themselves, but I'm glad they did it eventually.

Reply

Dear massoud, it seems this app doesn't  work anymore. It tries to open the channel but then it can not.

Reply

The manoto1 app requires login info. Would you please let me know how I can get the login info please? Really appreciate it. Thanks

Reply

Massoud Mazar

Unfortunately manoto1 app is not working because of the changes manoto TV has made in their site.

Reply

Thanks. By any chance, do you have the access code for any other Iranian channels or group channels with or without manoto? I appreciate it

Reply

Massoud Mazar

I fixed the manoto Roku app. you should get the update automatically, or visit https://my.roku.com/add/manoto

Reply

thanks a million. I added it today & it works like charm.

Reply

Thanks, Thanks, Thanks

Reply

Thank you so much Massoud. Do you happen to have channels for other popular persian tvs?

Reply

Massoud Mazar

I do not have more channels, but I noticed a new Roku channel named Tavoos (or something like that) was added. I tried it and most of the channels don't work, but still you can get a few channels.

Reply

Thanks massoud. I did try that and as you said most of the channeld don't work. Jadooo is casting Farsi1 though.

Reply

Add comment