Listen NRJ germany and finland from mediaplayer

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 = "";
my $ip = "";
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();
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();
# 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();
print $q->redirect( -URL => $rdurl );

Deploy this perl script on a webserver. To test it call in your webbrowser where has to replaced by the content root of the script.

If this works you can use eg the link for the german NRJ pop channel or the link 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