html/tvmusor.pl


   1 #!/usr/pkg/bin/perl
   2 #
   3 # $Id: porthu-irssi.pl,v 1.7 2003/06/14 21:14:46 bigmac Exp $
   4 #
   5 # Irssi Client for PORT.HU
   6 # Copyright (C) 2003, Gabor Nyeki (bigmac@home.sirklabs.hu).
   7 # All rights reserved.
   8 #
   9 # Redistribution and use in source and binary forms, with or without
  10 # modification, are permitted provided that the following conditions
  11 # are met:
  12 # 1. Redistributions of source code must retain the above copyright
  13 #    notice, this list of conditions and the following disclaimer.
  14 # 2. Redistributions in binary form must reproduce the above copyright
  15 #    notice, this list of conditions and the following disclaimer in the
  16 #    documentation and/or other materials provided with the distribution.
  17 # 3. Neither the name of the author nor the names of its contributors
  18 #    may be used to endorse or promote products derived from this software
  19 #    without specific prior written permission.
  20 #
  21 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  22 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  25 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31 # SUCH DAMAGE.
  32 
  33 use Irssi;
  34 use Irssi::Irc;
  35 use IO::Socket;
  36 
  37 use vars %IRSSI;
  38 %IRSSI = (
  39 	authors		=> "Gabor Nyeki",
  40 	contact		=> "bigmac@home.sirklabs.hu",
  41 	name		=> "tvmusor",
  42 	description	=> "asks for the current tv-lineup from http://www.port.hu/",
  43 	license		=> "BSDL",
  44 	changed		=> "Tue Jun  3 18:48:02 CEST 2003"
  45 );
  46 
  47 my %chans = (
  48 	m1		=> "1",
  49 	m2		=> "2",
  50 	dunatv		=> "6",
  51 	tv2		=> "3",
  52 	rtlklub		=> "5",
  53 	viasat3		=> "21",
  54 	fixtv		=> "96",
  55 	spektrum	=> "9",
  56 	hbo		=> "8",
  57 	atv		=> "15"
  58 );
  59 
  60 
  61 sub tvmusor {
  62 	my ($args) = @_;
  63 
  64 	split / /, $args;
  65 	$chan = @_[0];
  66 	$list = @_[1];
  67 
  68 	if (!$chan) {
  69 		Irssi::print "Hasznalat: /tvmusor list|csatorna [lista hossza]";
  70 		return;
  71 	}
  72 	if ($chan eq "list") {
  73 		Irssi::print "Elerheto csatornak listaja:";
  74 		foreach $buf (sort(keys %chans)) {
  75 			Irssi::print "-> $buf";
  76 		}
  77 		return;
  78 	}
  79 
  80 	if (!$chans{$chan}) {
  81 		Irssi::print "$chan nem letezik!";
  82 		return;
  83 	}
  84 
  85 	if (!$list) {
  86 		$num = 5;
  87 	} else {
  88 		$num = $list;
  89 	}
  90 
  91 
  92 	$sd = IO::Socket::INET->new(Proto => "tcp",
  93 				    PeerAddr => "www.port.hu",
  94 				    PeerPort => "80") or die;
  95 	print $sd "GET /pls/tv/tv.prog?i_days=1&i_ch=$chans{$chan}&i_ch_nr=1 HTTP/1.0\n";
  96 	print $sd "Host: www.port.hu\n";
  97 	print $sd "User-Agent: Irssi\n";
  98 	print $sd "\n";
  99 
 100 	Irssi::print "$chan:";
 101 
 102 	$i = 0;
 103 	while (<$sd>) {
 104 		if ($_ =~ /<tr><td align="right" valign="top" bgcolor="/) {
 105 			split /<strong>/, $_;
 106 
 107 			if (@_[1] =~ /<blink>(.*)<\/blink>/) {
 108 				$i = 1;
 109 				$x = $1;
 110 			} else {
 111 				if ($i) {
 112 					$i++;
 113 				}
 114 				@_[1] =~ /(.*)<\/strong>/;
 115 				$x = $1;
 116 			}
 117 
 118 			if ($i eq 0) {
 119 				next;
 120 			}
 121 
 122 			@_[2] =~ /(.*)<\/strong>/;
 123 			$y = $1;
 124 
 125 			Irssi::print "-> [$x] $y";
 126 			if ($i eq $num) {
 127 				last;
 128 			}
 129 		}
 130 	}
 131 
 132 	close $sd;
 133 
 134 	if ($i ne $num) {
 135 		Irssi::print "-> --- nincs tobb ---";
 136 	}
 137 }
 138 
 139 Irssi::command_bind('tvmusor', 'tvmusor');