Sign up here and you can log into the forum!

Help writing UMSP Plugin for Presto streaming service

Discussion, features, plugins--everything about zoster's UMSP UPnP Media Server software

Help writing UMSP Plugin for Presto streaming service   

Postby uptime » Tue Mar 31, 2015 3:59 am

Hi everyone,

I’m trying to write a UMSP plugin for the Presto streaming service, but I’m having trouble with the code required to make it work.
I’m new to Linux & PHP so if you could be specific with your responses, it would be helpful.

The website I’m trying to stream movies from is: https://www.presto.com.au/
I have a Gen 3 WD Live TV running a Base FW of: 2.02.32
The WDTVLX FW is: 0.1.4 running externally on a USB Flash drive.

I don’t know the required UMSP code to enter a login username and password for the site and need help to get this plugin working.
I have looked at a few examples of UMSP plugins and modified one, but I think it is missing several lines of code.
The plugin currently displays an empty screen. Previously the plugin displayed the image of a Linux penguin which was defined in umsp.php using upnp:album_art which pointed to an image on a website, but I wasn’t sure if it was copyrighted so I removed it.

I have put the file umsp.php in the directory /tmp/conf

Code: Select all
<?php
global $myMediaItems;

$myMediaItems[] = array (   
                  'id'            => 'umsp://plugins/presto',   #Attribute of item
                  'parentID'      => '0',
                  'dc:title'      => 'Presto',
                  'upnp:class'    => 'object.container',
                  );
?>


I have put the file presto.php in the directory /tmp/umsp-plugins

Code: Select all
<?php
    function _pluginMain($prmQuery) {

    $Items[] = array(   
            'id'              => 'SubItem01',
            'parentID'        => 'umsp://plugins/presto',
            'dc:title'        => 'Preso - SubItem01',
            'upnp:class'      => 'object.item.videoItem',
            'res'             => 'https://www.presto.com.au/,
            'protocolInfo'    => '*:*:*:*',
    );


    return $Items;
    }
?>



Any help you could give me would be appreciated.

Thanks,
Uptime.
uptime
n00b
 
Posts: 4
Joined: Thu Mar 05, 2015 4:18 am

Re: Help writing UMSP Plugin for Presto streaming service   

Postby mad_ady » Tue Mar 31, 2015 5:45 am

I'm not gonna laugh, because you're new at this, but your approach is terribly naive...

First read this wiki page to understand how UMSP works and what you need to do to extract the content from the site: http://wiki.wdlxtv.com/UMSP_plugin_development. You, as a developer, have the (often difficult) task of writing the PHP code to go around the site and extract video items (that's what you have to return in a "res" entry). To get those video items you have to be a good website scraper... Just pointing UMSP to the site will not help at all... Also, it would be wise to first try to save one of those movies offline and see if the WDTV will play it - sometimes there are codec incompatibilities. Also, since it looks like a streaming site, I bet it's filled with DRM and lots of protections, making scraping more difficult. Your starting point should be an analysis with Firefox and Firebug to understand how requests are made - but this requires a good understanding of HTTP/CGI technology.

You're not missing just a few lines of code - the code you have is ok - you can replace the URL in res with this one: http://techslides.com/demos/sample-videos/small.mp4 and it should play onscreen. You're missing the logic of the plugin. Have a look at the other plugins that deal with scraping to get a general understanding of what's going on.

Hope this doesn't scare you away, but writing a plugin takes time and is not trivial. :ugeek:
User avatar
mad_ady
Developer
 
Posts: 4522
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: Help writing UMSP Plugin for Presto streaming service   

Postby kroetkroet » Tue Mar 31, 2015 9:47 am

lol@mad_ady :)

I'd say it with figures: you want to have this:
Image

What you actually need is this:
Image

Your script is like the rooftop of the car - you might need bit more :mrgreen:
WDLXTV-fan! - In case you need further assistance: read our WIKI, search our Forum and most of all: donate 'something' to b-rad for his great efforts!!!
User avatar
kroetkroet
Beta Tester
 
Posts: 1004
Joined: Mon Apr 05, 2010 11:53 pm

Re: Help writing UMSP Plugin for Presto streaming service   

Postby uptime » Tue Mar 31, 2015 10:06 pm

That’s pretty funny kroetkroet and you should laugh mad_ady! :lol:

Now I know why people just request a UMSP plugin – it’s much easier!
Oh well, looks like it’s off to the wreckers to look for the missing parts to make this script work.

Thanks for the feedback mad_ady, what you said makes sense.
I think I’m better off looking for a UMSP Plugin for a streaming service that has authentication via a username and password and use it as a template to save time and to try and better understand the logic that’s is required to make it work. I had looked at that Wiki previously but couldn’t find the link to the UMSP for dummies page. It would be good if there were some UMSP tutorials on the website to make it easier for people with some skills to try and develop plugins so it’s not all left up to a handful of developers to do.

I’m beginning to understand why there are so many broken or partly working plugins.

As suggested, I will find a program that will enable me to save some streamed content to ensure the WD has the codecs to play the website content before I take this any further.

Thanks,
uptime.
uptime
n00b
 
Posts: 4
Joined: Thu Mar 05, 2015 4:18 am

Re: Help writing UMSP Plugin for Presto streaming service   

Postby mad_ady » Tue Mar 31, 2015 10:41 pm

You'll find out soon enough that authentication is not that hard. It usually involves submitting a form with a username/password, obtaining a cookie or a session id and using said cookie/session id in all further requests. To understand how it works, use Firebug's Net tab to inspect any website and see what requests get made. In principle you'd need to make those requests from php, and scrape (use regular expressions) to extract important data from the site to use in subsequent requests. What data you need or how to use it depends on how the site is created (each site is unique).

So, it's not impossible, but it requires 50% effort in site analysis (in complex solutions the site uses javascript to compute keys needed to access the content), 50% effort in coding and 50% effort in debugging :) All you need is a motivation to do it. Everything else can be learned.

@kroetkroet: I think you have the wrong parts - those you have will never make that version of VW... :lol:
User avatar
mad_ady
Developer
 
Posts: 4522
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: Help writing UMSP Plugin for Presto streaming service   

Postby recliq » Thu Apr 02, 2015 9:17 am

mad_ady wrote:@kroetkroet: I think you have the wrong parts - those you have will never make that version of VW... :lol:

Wrong! The second picture is just the stock kit, the upper one is the hacked result! :ugeek:
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5513
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: Help writing UMSP Plugin for Presto streaming service   

Postby kroetkroet » Thu Apr 02, 2015 9:20 am

Memories o memories to childhood dreams filled with mecano - o good ol' days :lol:
WDLXTV-fan! - In case you need further assistance: read our WIKI, search our Forum and most of all: donate 'something' to b-rad for his great efforts!!!
User avatar
kroetkroet
Beta Tester
 
Posts: 1004
Joined: Mon Apr 05, 2010 11:53 pm

Re: Help writing UMSP Plugin for Presto streaming service   

Postby uptime » Sun Apr 05, 2015 3:48 pm

Hi mad_ady,

Thanks for your previous posts. :D

I used firebug to look at the website and saw a 17 line cookie that you mentioned as well as a https referer which is presumably a link to the movie.
There is a lot of coding on the website and writing a UMSP script to extract this information from the web page and using it to display headings and links on the WD is beyond my knowledge. About the best I could hope for would be to login using a computer with firebug and use the session cookie and URL from a movie and add it to a UMSP plugin so I could play the movie (assuming the WD had a compatible codec). Do you have an example of the UMSP scripting I would need to add to the UMSP plugin in order to try re-using a session cookie and the URL.

Regards,
uptime.
uptime
n00b
 
Posts: 4
Joined: Thu Mar 05, 2015 4:18 am

Re: Help writing UMSP Plugin for Presto streaming service   

Postby mad_ady » Sun Apr 05, 2015 10:42 pm

Inject a cookie/session id should work, especially if you're behind a NAT (so that the server thinks it's talking to the same IP).

It's difficult for me to recommend a plugin as a template, but I remember using cookies inside the cantio plugin:
http://svn.wdlxtv.com/filedetails.php?repname=UMSP&path=%2Fplugins%2Fcantio%2Fcantio.php

especially this function:
Code: Select all
function downloadPage($uri, $sessionid, $method='GET', $postString=""){
    _logDebug("Downloading $uri");
        $opts = array(
          'http'=>array(
                'method'=>$method,
                'header'=>"Accept-language: en\r\n" .
                                  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.04 (lucid) Firefox/3.6.13 -- wdlxtv\r\n" .
                                  "Content-Type: application/x-www-form-urlencoded\r\n".
                                  "Cookie: PHPSESSID=$sessionid;\r\n",
            'content'=>"$postString"
          )
        );

        $context = stream_context_create($opts);
        $content = file_get_contents("$uri", false, $context);
        if(! $content){
            #probably we got a bad request code
            _logDebug("couldn't get content: ".print_r($http_response_header, true));
        }
        return $content;
}


This function will make a get or post to a URL and retrieve the result for you to parse. It also sends a cookie with each request.

Regaring playable content - look out for the Content-Type hearder. It tells you what kind of data the server sends back. You want to get things like "video/mp4" or "video/avi".
Here's what you can/should try:
1. Go to a page with a list of videos
2. Identify one of the links and think of a way to extract all similar links from that page (it will help you build a list of videos to display a menu)
3. When you follow a link, use firebug to identify the actual media. Analyze the media's URL to see what data you need to send to get it.
4. Also, search for the media's URL inside the page you loaded at step #3. You need to find the position where that URL is sent so that you can extract it for any similar page.
5. Write the parsing code to extract that URL and send it to the WDTV for playback.

Or, if you don't want to invest the time to write the whole plugin and support and distribute it, you can cheat by having a static UMSP entry (like the one you posted in the first post), pointing directly to the video URL in step 4. You'd have to manually extract the URL and write it in the plugin for each video you want to watch, but you'd save a lot of development time.

Note that even this step can misfire. You should try it anyway, but if you can't play the video, you should try to run wget -O - 'http://......' and see if it downloads or not. It's possible that you will need to send extra parameters (like a cookie or a POST) that will require you to write more complex code (a proxy) to get the job done.
User avatar
mad_ady
Developer
 
Posts: 4522
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: Help writing UMSP Plugin for Presto streaming service   

Postby uptime » Tue Apr 07, 2015 2:47 am

Hi Mad_ady,

Thanks for all the information and the step by step to write a dynamic UMSP plugin.
I’m going to have to do some reading in order to understand the code.
It looks like the instructions to build the Lego space station but I’m still sorting the Lego into colours!

In the meantime I want to go down the path of using a static UMSP entry.
I have found the HTTPS URL from the website which I can add to the res entry in the UMSP plugin, but I'm still unsure how to add an extracted session cookie from Firebug to the UMSP plugin.

Regards,
uptime
uptime
n00b
 
Posts: 4
Joined: Thu Mar 05, 2015 4:18 am

Next

Return to UMSP Media Server

Who is online

Users browsing this forum: No registered users and 3 guests