Script to get active tv channel

Ideas and dreaming will go this forum

smilykoch
Posts: 13
Joined: Mon Mar 26, 2012 2:22 pm

Re: Script to get active tv channel

Post by smilykoch » Thu Jun 07, 2012 10:40 am

How come this doesn't work?

Code: Select all

#!"C:\xampp\perl\bin\perl.exe"
# tv.cgi
#print "Content-type: text/plain\n\n";
use warnings;
use strict;

use Net::UPnP::ControlPoint;

my $upnp = Net::UPnP::ControlPoint->new();
my @devs = $upnp->search();
my $tv;

foreach my $dev ( @devs ) 
{
   foreach my $serv ( $dev->getservicelist() )
   {
      if ( $serv->getservicetype() =~ /TVAgent/ )
      {
         $tv = $serv;
         last;
      }
   }
}

die "TVAgent not found\n" unless $tv;

my $res = action( 'GetCurrentExternalSource' );
print "?????";
print "$res->{CurrentExternalSource}";
print "%%%%%";

if($res->{CurrentExternalSource} == 'TV')
{
	$res = action( 'GetCurrentMainTVChannel' );
	if($res->{CurrentChannel} =~ /<MajorCh>(.+?)<\/MajorCh>/)
	{
		print "$1";
		print "@@@@@";
	}else{
		print "Something went wrong";
	}
}

exit 0;

# -----------------------------------------------------------------------------

sub action
{
   my ( $act, $args ) = @_;

   my $r = $tv->postaction( $act, $args );

   unless ( 200 == $r->getstatuscode() )
   {
      die "Error $act: ". $r->getstatuscode()."\n";
   }

   my $res = $r->getargumentlist();
   unless ( 'OK' eq $res->{Result} )
   {
      die "Error $act response $res->{Result}\n";
   }

   return $res;
}

# -----------------------------------------------------------------------------

__END__

And? How do i open .dat files? eg. the channel list from GetChannelListURL?


Cheers!

Eduardo
Posts: 9
Joined: Sat May 19, 2012 4:03 pm

Re: Script to get active tv channel

Post by Eduardo » Wed Jun 27, 2012 10:48 am

I'm sorry by my late response.
smilykoch wrote:How come this doesn't work? ...
You must look out the output:

Code: Select all

$ ./tmp.pl 
Argument "TV" isn't numeric in numeric eq (==) at ./tmp.pl line 32.
Argument "TV" isn't numeric in numeric eq (==) at ./tmp.pl line 32.
?????TV%%%%%3@@@@@
There are only two warnings in line 32, change this:

Code: Select all

if($res->{CurrentExternalSource} == 'TV')
to this:

Code: Select all

if($res->{CurrentExternalSource} eq 'TV')
for me this script works well, the number 3 is the channel number.
smilykoch wrote:... And? How do i open .dat files? eg. the channel list from GetChannelListURL?...
I don't know the structure of this file, maybe the channel editor can read it

This is the head of my ChannelList.dat:

Code: Select all

$ hexdump -C ChannelList.dat | head 
00000000  25 01 69 00 02 00 01 00  fe ff 3a 00 12 02 ff ff  |%.i.......:.....|
00000010  31 00 00 00 00 00 00 00  00 c4 04 00 4c 61 20 31  |1...........La 1|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000080  02 00 02 00 fe ff 3a 00  13 02 ff ff 32 00 00 00  |......:.....2...|
00000090  00 00 00 00 00 c4 04 00  4c 61 20 32 00 00 00 00  |........La 2....|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000000f0  00 00 00 00 00 00 00 00  00 00 00 00 02 00 03 00  |................|
00000100  fe ff 45 00 8c 00 ff ff  33 00 00 00 00 00 00 00  |..E.....3.......|
00000110  00 c4 08 00 41 4e 54 45  4e 41 20 33 00 00 00 00  |....ANTENA 3....|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000170  00 00 00 00 00 00 00 00  02 00 04 00 fe ff 43 00  |..............C.|
00000180  21 04 ff ff 34 00 00 00  00 00 00 00 00 c4 06 00  |!...4...........|
00000190  43 55 41 54 52 4f 00 00  00 00 00 00 00 00 00 00  |CUATRO..........|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 02 00 05 00  fe ff 44 00 b4 00 ff ff  |..........D.....|
00000200  35 00 00 00 00 00 00 00  00 c4 09 00 54 65 6c 65  |5...........Tele|
00000210  63 69 6e 63 6f 00 00 00  00 00 00 00 00 00 00 00  |cinco...........|
00000220  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000270  02 00 06 00 fe ff 43 00  54 01 ff ff 36 00 00 00  |......C.T...6...|
00000280  00 00 00 00 00 c4 07 00  6c 61 53 65 78 74 61 00  |........laSexta.|
00000290  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
maybe this is for another thread.
Eduardo

smilykoch
Posts: 13
Joined: Mon Mar 26, 2012 2:22 pm

Re: Script to get active tv channel

Post by smilykoch » Wed Jun 27, 2012 8:21 pm

hmmm... if i run the exact same code as i posted above in my perl (with the eq instead of ==) i get:

Code: Select all

Can't use an undefined value as an ARRAY reference at C:/xampp/perl/site/lib/Net
/UPnP/Device.pm line 111.
WHY? :O

Eduardo
Posts: 9
Joined: Sat May 19, 2012 4:03 pm

Re: Script to get active tv channel

Post by Eduardo » Tue Jul 03, 2012 9:51 pm

smilykoch wrote:...

Code: Select all

Can't use an undefined value as an ARRAY reference at C:/xampp/perl/site/lib/Net
/UPnP/Device.pm line 111.
...
You need debug your environment, your network, etc...
I recommend you that use wireshark for that
and maybe Data::Dumper for dump structures, ej:

Code: Select all

foreach my $dev ( @devs )
{
   print "dev: ".Dumper( $dev )."\n";
   my @servlist = $dev->getservicelist();
   print "Service list: ".Dumper( \@servlist )."\n";
   foreach my $serv ( @servlist )
   {
      if ( $serv->getservicetype() =~ /TVAgent/ )
      {
         $tv = $serv;
         last;
      }
   }
}
Eduardo

Eduardo
Posts: 9
Joined: Sat May 19, 2012 4:03 pm

Re: Script to get active tv channel

Post by Eduardo » Wed Jul 04, 2012 9:55 pm

arris69 wrote:...can you pls make an

Code: Select all

ls -alR /mtd_rwarea/dlna*
and pls. post output?...
here you are:

Code: Select all

ls -alR /mtd_rwarea/dlna*
/mtd_rwarea/dlna_web_root:
drwxr-xr-x    1 root     0               0 Jan  1  1980 .
drwxr-xr-x    1 root     0               0 Jan  1 00:01 ..
-rwxr-xr-x    1 root     0             494 Jan  1  1980 DmrAclConfig.xml
drwxr-xr-x    1 root     0               0 Jan  1  1980 MainTVServer2
-rwxr-xr-x    1 root     0             481 Jan  1  1980 RcrAclConfig.xml
-rwxr-xr-x    1 root     0             235 Jan  1  1980 RcrMobileList.xml
drwxr-xr-x    1 root     0               0 Jan  1  1980 dmr
-rwxr-xr-x    1 root     0              63 Jan  1  1980 dmr_permissions.conf
drwxr-xr-x    1 root     0               0 Jan  1  1980 rcr

/mtd_rwarea/dlna_web_root/MainTVServer2:
drwxr-xr-x    1 root     0               0 Jan  1  1980 .
drwxr-xr-x    1 root     0               0 Jan  1  1980 ..
-rwxr-xr-x    1 root     0           43565 Jan  1  1980 MainTVAgent2.xml
-rwxr-xr-x    1 root     0            1217 Jan  1  1980 MainTVServer2Desc.xml

/mtd_rwarea/dlna_web_root/dmr:
drwxr-xr-x    1 root     0               0 Jan  1  1980 .
drwxr-xr-x    1 root     0               0 Jan  1  1980 ..
-rwxr-xr-x    1 root     0           18139 Jan  1  1980 AVTransport1.xml
-rwxr-xr-x    1 root     0            5294 Jan  1  1980 ConnectionManager1.xml
-rwxr-xr-x    1 root     0            9873 Jan  1  1980 RenderingControl1.xml
-rwxr-xr-x    1 root     0            3099 Jan  1  1980 SamsungMRDesc.xml
lrwxr-xr-x    1 root     0             108 Jan  1  1980 icon_LRG.jpg -> /mtd_appdata/Images_960x540/DMR/icon_LRG.jpg
lrwxr-xr-x    1 root     0             108 Jan  1  1980 icon_LRG.png -> /mtd_appdata/Images_960x540/DMR/icon_LRG.png
lrwxr-xr-x    1 root     0             108 Jan  1  1980 icon_SML.jpg -> /mtd_appdata/Images_960x540/DMR/icon_SML.jpg
lrwxr-xr-x    1 root     0             108 Jan  1  1980 icon_SML.png -> /mtd_appdata/Images_960x540/DMR/icon_SML.png

/mtd_rwarea/dlna_web_root/rcr:
drwxr-xr-x    1 root     0               0 Jan  1  1980 .
drwxr-xr-x    1 root     0               0 Jan  1  1980 ..
-rwxr-xr-x    1 root     0            1244 Jan  1  1980 RemoteControlReceiver.xml
-rwxr-xr-x    1 root     0            2787 Jan  1  1980 TestRCRService.xml
Eduardo

perhanna
Posts: 1
Joined: Sat Jan 26, 2013 9:53 am

Re: Script to get active tv channel

Post by perhanna » Sat Jan 26, 2013 9:55 am

It so difficult

Post Reply

Return to “[D] Brainstorm”