1#!/usr/local/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 33use strict; 34use Irssi; 35use Irssi::Irc; 36use IO::Socket; 37 38use vars qw($VERSION %IRSSI); 39use vars %IRSSI; 40%IRSSI = ( 41 authors => "Gabor Nyeki", 42 contact => "bigmac\@home.sirklabs.hu", 43 name => "tvmusor", 44 description => "asks for the current tv-lineup from http://www.port.hu/", 45 license => "BSDL", 46 changed => "Tue Jun 3 18:48:02 CEST 2003" 47); 48 49my %chans = ( 50 m1 => "1", 51 m2 => "2", 52 dunatv => "6", 53 tv2 => "3", 54 rtlklub => "5", 55 viasat3 => "21", 56 fixtv => "96", 57 spektrum => "9", 58 hbo => "8", 59 atv => "15" 60); 61 62 63sub tvmusor { 64 my ($args) = @_; 65 66 split / /, $args; 67 my $chan = @_[0]; 68 my $list = @_[1]; 69 70 if (!$chan) { 71 Irssi::print "Hasznalat: /tvmusor list|csatorna [lista hossza]"; 72 return; 73 } 74 if ($chan eq "list") { 75 Irssi::print "Elerheto csatornak listaja:"; 76 foreach my $buf (sort(keys %chans)) { 77 Irssi::print "-> $buf"; 78 } 79 return; 80 } 81 82 if (!$chans{$chan}) { 83 Irssi::print "$chan nem letezik!"; 84 return; 85 } 86 87 my $num; 88 if (!$list) { 89 $num = 5; 90 } else { 91 $num = $list; 92 } 93 94 95 my $sd = IO::Socket::INET->new(Proto => "tcp", 96 PeerAddr => "www.port.hu", 97 PeerPort => "80") or die; 98 print $sd "GET /pls/tv/tv.prog?i_days=1&i_ch=$chans{$chan}&i_ch_nr=1 HTTP/1.0\n"; 99 print $sd "Host: www.port.hu\n"; 100 print $sd "User-Agent: Irssi\n"; 101 print $sd "\n"; 102 103 Irssi::print "$chan:"; 104 105 my $i = 0; 106 my ($x, $y); 107 while (<$sd>) { 108 if ($_ =~ /<tr><td align="right" valign="top" bgcolor="/) { 109 split /<strong>/, $_; 110 111 if (@_[1] =~ /<blink>(.*)<\/blink>/) { 112 $i = 1; 113 $x = $1; 114 } else { 115 if ($i) { 116 $i++; 117 } 118 @_[1] =~ /(.*)<\/strong>/; 119 $x = $1; 120 } 121 122 if ($i eq 0) { 123 next; 124 } 125 126 @_[2] =~ /(.*)<\/strong>/; 127 $y = $1; 128 129 Irssi::print "-> [$x] $y"; 130 if ($i eq $num) { 131 last; 132 } 133 } 134 } 135 136 close $sd; 137 138 if ($i ne $num) { 139 Irssi::print "-> --- nincs tobb ---"; 140 } 141} 142 143Irssi::command_bind('tvmusor', 'tvmusor'); 144