Listen NRJ germany and finland from mediaplayer


Deprecated: Calling get_class() without arguments is deprecated in /var/www/wordpress/wp-includes/class-wp-http.php on line 329

I’m sometimes listening Radio NRJ on my PC. But for NRJ germany and finland it is not possible to have a fixed URL which can be used in a mediaplayer or MythTV. To use this channel is some kind of handshake with session ids is necessary.

I wrote a perl script handling this handshake and doing the redirect with the correct session ids.


#!/usr/bin/perl -w
#
# This is the perl-based redirect for NRJ streams from germany and finland
#
# @date $Date: 2010-03-05 04:51:10 +0000 $
#
# Load some required modules
use strict;
use warnings;
use CGI qw/:standard/;
use XML::DOM;
require HTTP::Request;
require LWP::UserAgent;
my $q = CGI->new( );
my $baseUrl = "http://wr.nrj.net/xml/";
my $ip = "85.181.52.138";
my $channellistid = $q->param("channellistid");
my $channelname = $q->param("channelname");
my $test = $q->param("test");
# Channel list
my $url_channels = "$baseUrl?q=getRadios&id=$channellistid&ip=$ip";
my $parserChannels = new XML::DOM::Parser;
my $docChannels = $parserChannels->parsefile ($url_channels);
my $nodesDynId = $docChannels ->getElementsByTagName("DynId");
my $nDynId = $nodesDynId->getLength;
my $nodeDynId = $nodesDynId->item(0);
my $dynId = $nodeDynId->getFirstChild()->getNodeValue();
my $nodesSessionId = $docChannels ->getElementsByTagName("SessionId");
my $nSessionId = $nodesSessionId->getLength;
my $nodeSessionId = $nodesSessionId->item(0);
my $sessionId= $nodeSessionId->getFirstChild()->getNodeValue();
my $nodesItem = $docChannels ->getElementsByTagName("Item");
my $nItem = $nodesItem->getLength;
my $channelid;
for (my $i = 0; $i item ($i);
if ( $nodeItem->getElementsByTagName("name")->item(0)->getFirstChild()->getNodeValue() eq $channelname ) {
$channelid = $nodeItem->getElementsByTagName("id")->item(0)->getFirstChild()->getNodeValue();
}
}
$docChannels->dispose;
#Channel
my $url_channel = "$baseUrl?q=getRadio&id=$channelid&sess=$sessionId&DynId=$dynId";
my $parserChannel = new XML::DOM::Parser;
my $docChannel = $parserChannel->parsefile ($url_channel);
my $nodesUrl = $docChannel ->getElementsByTagName("url");
my $nUrl = $nodesUrl->getLength;
my $nodeUrl = $nodesUrl->item(0);
my $rdurl = $nodeUrl->getFirstChild()->getNodeValue();
$docChannel->dispose;
# Redirect or output
if ( $rdurl eq "" || $test ne "" ){
print $q->header();
print $q->start_html(-title=>"Test result"); print "<p>Base Url: $baseUrl</p>";
print "<p>IP: $ip</p>";
print "<p>Test: $test</p>";
print "<p>Channel list Id: $channellistid</p>";
print "<p>Channel name: $channelname</p>";
print "<p>Number of DynId elements: $nDynId</p>";
print "<p>DynId: $dynId</p>";
print "<p>Number of SessionId elements: $nSessionId</p>";
print "<p>SessionId: $sessionId</p>";
print "<p>Number of Item elements: $nItem</p>";
print "<p>Channel Id: $channelid</p>";
print "<p>Number of url elements: $nUrl</p>";
print "<p>Redirect URL: $rdurl</p>";
print $q->end_html();
}
else{
print $q->redirect( -URL => $rdurl );
}

Deploy this perl script on a webserver. To test it call http://10.0.0.100/radioredirect/nrj.pl?channellistid=335544&channelname=NRJ+POP&test=1 in your webbrowser where http://10.0.0.100/radioredirect has to replaced by the content root of the script.

If this works you can use eg the link http://10.0.0.100/radioredirect/nrj.pl?channellistid=335544&channelname=NRJ+POP for the german NRJ pop channel or the link http://10.0.0.100/radioredirect/nrj.pl?channellistid=E9ajufyzkgrs7mvljfikomdh9ys0nl7u&channelname=NRJ for finish NRJ.

The channellistid defines if the channel is from NRJ germany or NRJ finland. The channel is identified by its name.

Leave a Reply