Sign up here and you can log into the forum!

plugin for ipla.tv

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

plugin for ipla.tv   

Postby gabriel » Tue Jan 25, 2011 11:14 pm

I'm trying to develop an UMSP plugin for polish VoD portal ipla.tv. I can download the files to local drive and play on WDTV live. But if I set the url in the proxy there comes a message on WDTV about incorrect file format. The files are all mp4 or flv. When going to web interface and selecting the plugin, the files can be loaded. What can be reason for this message?

Regards, Gabriel
gabriel
n00b
 
Posts: 7
Joined: Tue Apr 27, 2010 11:34 am

Re: plugin for ipla.tv   

Postby gabriel » Wed Jan 26, 2011 11:09 pm

I've got it - after removing old header and inserting new (as in youtube-subscriptions) I could see the flv file. Now I'm trying to go forward with parsing the video list from xml file.
Regards, Gabriel
gabriel
n00b
 
Posts: 7
Joined: Tue Apr 27, 2010 11:34 am

Re: plugin for ipla.tv   

Postby gabriel » Thu Jan 27, 2011 12:20 pm

I could parse the xml and test plugin in Opera and see all titles, but when I select any group of videos in wdtv the message "no media in the current folder" is coming.
Here are the php files:
Code: Select all
<?php
    function _pluginMain($prmQuery)
    {
        $queryData = array();
        parse_str($prmQuery, $queryData);

        if ($queryData['category'] != '' )
        {
            return _videoList( $queryData );
        }
        else
        {
            $cats [] = array('id' => '1571', 'title' => 'Swiat wedlug Kiepskich' );
            $cats [] = array('id' => '1593', 'title' => 'I kto tu rzadzi?');
            $cats [] = array('id' => '1601', 'title' => 'Szpital na perypetiach');
            $cats [] = array('id' => '128042', 'title' => 'Daleko od noszy');

            $cats [] = array('id' => '1756', 'title' => 'Kabarety');
            $cats [] = array('id' => '1749', 'title' => 'Mamuski');

            foreach ($cats as $cat)
            {
                $Items[] = array(
                    'id'             => "umsp://plugins/ipla?category=" . $cat['id'],
                    'parentID'       => 'umsp//plugins/ipla',
                    'dc:title'       => $cat['title'],
                    'upnp:class'     => 'object.container',
                    'upnp:album_art' => '',
                );
            }
           
            return $Items;
        }
    }

    function _videoList( $queryData )
    {
        $cat = $queryData["category"];

        $xml = file_get_contents( "http://127.0.0.1/umsp/plugins/ipla-proxy.php?cat=".$cat );

        $XML = new SimpleXMLElement($xml);
        $items = $XML->xpath('//vod');
        foreach ($items as $item )
        {
                $video = 'none';
                $req = $item->xpath( 'srcreq' );
                foreach ( $req as $r )
                {
                    $v = $r->attributes()->url;
                    if ( strpos( $v, '.flv' ) > 0 )
                        $video = $v;
                }
                $thumb = $item->attributes()->thumbnail;

                $Items [] = array (
                    'id'                => $video,
                    'parentID'          => 'umsp://plugins/ipla?category=' . $cat,
                    'res'               => 'http://127.0.0.1/umsp/plugins/ipla-proxy.php?video=' . $video,
                    'dc:title'          => $item->attributes()->title,
                    'upnp:class'        => 'object.item.videoitem',
                    'upnp:album_art'    => $thumb,
                    'protocolInfo'      => '*:*:video/*:*',
                );
        }
        return $Items;
    }
?>

Code: Select all
<?php
include_once( includeWorkaround() );

    $rawURL = $_GET['url'];
    $parsedURL = parse_url($rawURL);
    $itemHost = $parsedURL['host'];
    $itemPath = $parsedURL['path'];

    if (isset($_GET['cat']))
    {
        $itemHost = "getmedia.redefine.pl";
        $itemPath = "/action/2.0/vod/list/";
        $cat = $_GET['cat'];
        _getVods( $itemHost, $itemPath, $cat );       
    }
    else
    if (isset($_GET['video']))
    {
        $video = $_GET['video'];
        _DownloadThru( $video );
    }

// set the logging level, one of L_ALL, L_DEBUG, L_INFO, L_WARNING, L_ERROR, L_OFF
global $logLevel;
$logLevel = L_ALL;
global $logIdent;
$logIdent = 'ipla-proxy';

    #_getVods($itemHost, $itemPath, '1593' );
   
    #_DownloadThru("http://redirector.redefine.pl/cbd/69793f730c5efaee299438d5472c18fe.flv");

function parse_header($content)
{
    $newline = "\r\n";
    $parts = preg_split("/$newline . $newline/", $content);
    $header = array_shift($parts);
    $content = implode($parts, $newline . $newline);
    $parts = preg_split("/$newline/", $header);
    foreach ($parts as $part)
    {
        if (preg_match("/(.*)\: (.*)/", $part, $matches))
        {
            $headers[$matches[1]] = $matches[2];
        }
    }

    _logDebug("parse_header -> returning \$headers: ".serialize($headers));
    return $headers;
}

function _DownloadThru($url)
{
   
    foreach (array (' ',"\t","\n") as $char)
        $url = preg_replace("/$char/",urlencode($char),$url);
    $parsedURL = parse_url($url);
    $itemHost = $parsedURL['host'];
    $itemPath  = array_key_exists('path', $parsedURL) ? $parsedURL['path'] : "/";
    $itemPort  = array_key_exists('port', $parsedURL) ? (int)$parsedURL['port'] : 80;
    $itemPath  .= array_key_exists('query', $parsedURL) ? "?" . $parsedURL['query'] : "";
    $itemPath = urldecode($itemPath);

    _logDebug("_DownloadThrough -> calling _GetFile($itemHost, $itemPath, $itemPort)");
    _GetFile($itemHost, $itemPath, $itemPort);
}

function _GetFile($prmHost, $prmPath, $prmPort) {
    $fp = fsockopen($prmHost, $prmPort, $errno, $errstr, 30);
    if (!$fp) {
        _logError("_GetFile -> $errstr ($errno)");
        echo "$errstr ($errno)<br />\n";
    } else {
        // prepare the header
        $method = "GET"; #$_SERVER['REQUEST_METHOD']; //MediaPlayer knows what to request
        $start = '';
        if (isset($_SERVER['CONTENT_LENGTH']))
        {
            $start = "?start=" . $_SERVER['HTTP_RANGE'];
        }
        $out  = "$method ". $prmPath . $start . ' HTTP/1.1' ."\r\n";
        $out .= 'Host: ' . $prmHost . "\r\n";
        $out .= 'Accept: */*' . "\r\n";
        $out .= 'Cookie: test_cookie_login_user_id=-8939960' . "\r\n";

       
        if(isset ($_SERVER['CONTENT_LENGTH'])){ //add content-length if the MediaPlayer specifies it
            $out .= "Content-Length: ".$_SERVER['CONTENT_LENGTH']."\r\n";
        }
        #if(isset ($_SERVER['HTTP_RANGE'])){ //jump to the specific range if the MediaPlayer specifies it (when navigating)
        #    $out .= "Range: ".$_SERVER['HTTP_RANGE']."\r\n";
        #}
        $out .= "\r\n";
        $out .= "login=common_user&passwdmd5=&ver=281&cuid=-8939960&category=1593&sortedby=2&page=0";

        fwrite($fp, $out);
        _logDebug("_GetFile -> Sent header $out");
        $headerpassed = false;
        $response_text = "";
        //HTTP/1.1 200 OK
        //HTTP/1.1 302 Found
        $http_code = "";
               
        //read back the response
   
        while ($headerpassed == false) {
            $line = fgets( $fp);
            if( $line == "\r\n" )
                $headerpassed = true; //break the loop - we have the header
            else
                if ($http_code == "")
                    $http_code = $line; //it's the first line the server sends back
                else
                    $response_text .= $line; //save the rest of the lines in $response_text
        }

        _logDebug("_GetFile -> Received header $response_text");
        //get an associative array of the response
        $response = parse_header($response_text);
       
        #if ($response['Content-Type'] == 'video/x-flv'){
       #     $response['Content-Disposition'] = 'attachment; filename="video.flv"';  //remember to ask it as an attachment
       # }
       # if ($response['Content-Type'] == 'video/mp4'){
       #     $response['Content-Disposition'] = 'attachment; filename="video.mp4"';  //remember to ask it as an attachment
       # }
       
        //I'm not getting the file - I'm getting redirected somewhere else
     

       if ( $http_code == "HTTP/1.1 302 Found\r\n" ||
            $http_code == "HTTP/1.1 302 Moved Temporarily\r\n" ||
            $http_code == "HTTP/1.1 303 See Other\r\n" ||
            $http_code == "HTTP/1.1 307 Temporary Redirect\r\n" )
       {

            fclose($fp);
            _logInfo("_GetFile -> Downloading through ". $response['Location']. " because we received a HTTP 302 or 303");
            _DownloadThru($response['Location']);  //repeat the download process
        }
        else
            if ($http_code == "HTTP/1.1 200 OK\r\n" || $http_code == "HTTP/1.1 206 Partial Content\r\n")
            {
                //extra headers have been set above for video files and will be sent   
                foreach (array_keys($response) as $header)
                {
                    //do a redirect and re-read the file/url
                    _logInfo("_GetFile -> Received 200 or 206. Asking for the content with header ". "$header: " . $response[$header]);
                    header("$header: " . $response[$header]);

                }

                _logInfo("_GetFile -> Flushing the socket and exiting...");
                fpassthru($fp); //flush the socket and exit
                exit;
            }
            else{
                //the HTTP code is not supported
                fclose($fp);
                _logError("_GetFile -> HTTP code $http_code is not supported. Out: $out. Response Text: $response_text");
            }
   } //from else socket
}
 
    function _getVods($prmHost, $prmPath, $prmCat )
    {
               
        $fp = fsockopen($prmHost, 80, $errno, $errstr, 30);
       
        if ( !$fp)
        {
            echo "$errstr ($errno)<br />\n";
        } else
        {
            $out = 'POST '. $prmPath . ' HTTP/1.1' ."\r\n";
            $out .= 'User-Agent: ipla/281' ."\r\n";
            $out .= 'Host: ' . $prmHost . "\r\n";
            $out .= 'Accept: */*' . "\r\n";
            $out .= 'Cookie: test_cookie_login_user_id=-8939960' . "\r\n";
            $out .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
            $out .= 'X-Client: ipla' . "\r\n";
            $out .= 'X-Client-Build: 281' . "\r\n";
            $out .= 'Content-Length: 82' . "\r\n\r\n";
            $out .= 'login=common_user&passwdmd5=&ver=281&cuid=-8939960&category=' . $prmCat . '&sortedby=3&page=0';

            fwrite($fp,$out);
         
            $headerpassed = false;
            while (!$headerpassed)
            {
                $line = fgets($fp);
                if ($line == "\r\n")
                {
                    $headerpassed = true;
                }
            }
           
            fpassthru($fp);
            fclose($fp);       
        }
    }

function includeWorkaround(){
   if(copy("/usr/share/umsp/funcs-log.php", "/tmp/funcs-log.php")){
        //strip all blank lines in place
        system("sed -i '/^$/d' /tmp/funcs-log.php");
        return "/tmp/funcs-log.php";
   }
   return "/usr/share/umsp/funcs-log.php";
}

?>


Has maybe someone any idea?

Regards, Gabriel
gabriel
n00b
 
Posts: 7
Joined: Tue Apr 27, 2010 11:34 am

Re: plugin for ipla.tv   

Postby gabriel » Sun Jan 30, 2011 7:35 am

I'm getting closer to the reason of the error. It has something to do with parsing xml using SimpleXML. When I issue "foreach ($items as $item)" but do no further action on nodes, the list is filled with dummy data. As soon as I try to get data from $items I get error

PHP Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed' in /usr/share/umsp/funcs-misc.php:95
Stack trace:
#0 /usr/share/umsp/funcs-misc.php(95): serialize(Array)
#1 /usr/share/umsp/control-reply.php(77): _writeCache('umsp://plugins/...', Array)
#2 {main}

Regards, Gabriel
gabriel
n00b
 
Posts: 7
Joined: Tue Apr 27, 2010 11:34 am

Re: plugin for ipla.tv   

Postby gabriel » Sun Jan 30, 2011 12:11 pm

I have now following part of code:
Code: Select all
        foreach ($data as $item )
        {
                $video = 'none.flv';
                $row = simplexml_load_string($item->asXML());

                $thumb = $item->attributes()->thumbnail;                                                                                                       
                $title = $item->attributes()->title;

                $req = $row->xpath( 'srcreq' );
                foreach ( $req as $r )
                {
                    $v = $r->attributes()->url;
                    $bitrate = $r->attributes()->bitrate;
                    if ( strpos( $v, '.flv' ) > 0 && $bitrate < 1000 )
                        $video = $v;
                }

                $Items[] = array(
                    'id'                => 'http://127.0.0.1/umsp/plugins/ipla-proxy.php?video=' . $video,
                    'parentID'          => 'umsp://plugins/ipla?category=' . $cat,
                    'res'               => 'http://127.0.0.1/umsp/plugins/ipla-proxy.php?video=' . $video,
                    'dc:title'          => $title,
                    'upnp:class'        => 'object.item.videoitem',
                    'upnp:album_art'    => $thumb,
                    'protocolInfo'      => '*:*:*:*',
                );
        }


Only $thumb and $title cannot be read from $XML. When I set both to dummy values, I can view all videos. But in the state as above comes "there are no media items in current folder".
I've tried almost all possibilities and don't know more. This is the structure of $XML:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<resp status="ok">
  <radiostations />
  <VoDs>
    <vod cpid="1" timestamp="1219960800" cdn="1" thumbnail_big="http://s.redefine.pl/dcs/o2/redefine/images/18/1884706f637515c89f62fda2d24a66ed.jpg" thumbnail="http://s.redefine.pl/dcs/o2/redefine/images/ab/abd666db1f51bdc4f2a3dac9196e147f.png" hot="0" plevel="5.0" adult="0" vcnt="839639" vote="4.90" excl="0" id="4208" title="Świat według Kiepskich - Odcinek 1" descr="„Umarł odbiornik, niech żyje odbiornik!”&#xD; Poznajemy głównych bohaterów, czyli rodzinę Kiepskich." dip_url="http://film.ipla.tv/movies/24208/embed_show" dur="1613">
      <tags>
        <tag>komedia</tag>
        <tag>swiat wedlug kiepskich</tag>
        <tag>ferdek</tag>
        <tag>kiepski</tag>
        <tag>pazdzioch</tag>
        <htag>t_999_t</htag>
      </tags>
      <cat>760</cat>
      <srcreq pr="4" quality="0" format="3" url="http://redirector.redefine.pl/cbd/b73ae7b8ec742121922c1ce91a169f70.flv" allowdl="1" bitrate="163" type="1" granted_to="" drmtype="0" fileid="YmjCD8RpNLudKtCH9B0rEg==" />
      <srcreq pr="3" quality="0" format="2" url="http://redirector.redefine.pl/cbd/VoD_1_4208_b160.mp4" allowdl="1" bitrate="159" type="1" granted_to="" drmtype="0" fileid="HXb60JZgIV0uWeJEcYmUEg==" />
      <srcreq pr="3" quality="1" format="2" url="http://redirector.redefine.pl/movies/96a96278aceaac7b1d477e577b64d671.mp4" allowdl="1" bitrate="300" type="6" granted_to="" drmtype="0" fileid="BlIHQ0SOKMZbhDAQ2iGGEg==" />
      <srcreq pr="4" quality="1" format="3" url="http://redirector.redefine.pl/cbd/02e23f63d47fd0328dbc6614e0d7297c.flv" allowdl="1" bitrate="396" type="1" granted_to="" drmtype="0" fileid="b1URfiVUflUkcfGkwN5HEg==" />
      <srcreq pr="3" quality="1" format="2" url="http://redirector.redefine.pl/cbd/VoD_1_4208_b399.mp4" allowdl="1" bitrate="392" type="1" granted_to="" drmtype="0" fileid="RxzzUYp+cU2nCm8+/GH3Eg==" />
      <srcreq pr="2" quality="1" format="0" url="http://redir.atmcdn.pl/http/o2/redefine/objects1/VoD_1_4208.wmv" allowdl="1" bitrate="528" type="1" granted_to="" drmtype="0" fileid="+/ltlHIr+O5919f0fqUYEg==" />
      <srcreq pr="4" quality="2" format="3" url="http://redirector.redefine.pl/cbd/c33f880190139100505ea6a537f6cf94.flv" allowdl="1" bitrate="803" type="1" granted_to="17121*1720" drmtype="0" fileid="4j9OlKJQnczce5TfQlC9Eg==" />
      <srcreq pr="3" quality="2" format="2" url="http://redirector.redefine.pl/cbd/VoD_1_4208_b816.mp4" allowdl="1" bitrate="800" type="1" granted_to="17121*1720" drmtype="0" fileid="k2iT249zoycfIhTcX8a3Eg==" />
    </vod>


Who can help me?
Regards, Gabriel
gabriel
n00b
 
Posts: 7
Joined: Tue Apr 27, 2010 11:34 am

Re: plugin for ipla.tv   

Postby shunte » Thu Feb 17, 2011 7:27 pm

Hi @gabriel, the code was pretty close - just needed the odd tweak

I'm assuming you probably have it working already but here is a version with webend configuration _wec, info.php and config.php files

Extract and copy to the umsp plugins folder, or alternatively rename the archive to umsp.tgz and copy to the /conf folder and then standard boot processes will move it to he umsp plugins folder for you.

Activate the plugin through the webend

File name: ipla.tgz File size: 4.76 KB

I modified both files you posted in order to make it work 100%

Enjoy!
If you like the work I do please feel free to make a donation to the Red Cross
User avatar
shunte
Developer
 
Posts: 420
Joined: Sun Sep 19, 2010 1:43 am
Location: Cambridge, MA U. S. and A.

Re: plugin for ipla.tv   

Postby rz1983 » Wed Apr 13, 2011 4:07 pm

Quick question here, I am new to wdlxtv and I wanna know how can I transfer this umsp.tgz to /conf. Can you please give me the telnet command to do this. I tried webend file transfer but i guess it does not work because Im not login as root there.

thx
rz1983
n00b
 
Posts: 2
Joined: Wed Apr 13, 2011 4:04 pm

Re: plugin for ipla.tv   

Postby mad_ady » Thu Apr 14, 2011 1:02 am

@rz1983: copy the file to a usb flash drive, insert the drive in the wdtv, login via telnet and do the following:
Code: Select all
ls /tmp/mnt/<TAB><TAB>

Replace <TAB><TAB> with the actual TAB key pressed twice to enable auto completion. Select your USB drive and run the command to get a listing of the files. You should see your umsp-plugins.tgz after a few tries. When you know the path, use this command to copy it (replace path with the complete path you discovered earlier)
Code: Select all
cp /mp/mnt/path/umsp-plugins.tgz /conf/
sync


Then, reboot and you should have the plugin available.

Or, alternatively, download the mc app bin and run mc (a command line file manager similar to Norton Commander/Total Commander) to visually navigate to your files. http://forum.wdlxtv.com/viewtopic.php?f=40&t=242

... Or, you could copy the file in a similar way from a windows share/ftp

Or (method 4), use wget directly to get the file (why did I think of this last?):
User avatar
mad_ady
Developer
 
Posts: 4570
Joined: Fri Nov 05, 2010 9:08 am
Location: Bucharest, Romania

Re: plugin for ipla.tv   

Postby rz1983 » Thu Apr 14, 2011 7:44 pm

Thanx a lot I finally got it to work. I have another question if you can help me with. Does this plugin allow you to see all the videos as you would when you download ipla on your computer or is it just these few that are displaying when I select IPLA. I only get 6 folders with 5 diffrent series and one is a category. Im interested in "pierwsza miloscz" series. Is there a way to to perform a search within wdtv to find specific episodes or channels.I know ipla has tone of videos and shows, so I dont know if this is feasible or not within wdlxtv.

Thx for the help.......
rz1983
n00b
 
Posts: 2
Joined: Wed Apr 13, 2011 4:04 pm

Re: plugin for ipla.tv   

Postby shunte » Fri Apr 15, 2011 2:25 am

search isn't supported but I'll add if @gabriel no longer wishes to support the code

No response to my post when I originally got this code up and running, very minor tweaks if I remember so the solution is all gabriels; from stats he is using the forum so with luck he'll pick the ball back up...
If you like the work I do please feel free to make a donation to the Red Cross
User avatar
shunte
Developer
 
Posts: 420
Joined: Sun Sep 19, 2010 1:43 am
Location: Cambridge, MA U. S. and A.

Next

Return to UMSP Media Server

Who is online

Users browsing this forum: No registered users and 1 guest