/[mplayer-eee-tv]/program/mojtv.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /program/mojtv.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 14 - (show annotations)
Thu Oct 29 11:55:37 2009 UTC (14 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 1783 byte(s)
create output file with embedded shell for at

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use XML::FeedPP;
7 use DateTime;
8 use Data::Dump qw(dump);
9
10 my $now = DateTime->now;
11
12 my $record = qr/(e-Hrvatska|serija|dnevnik|vrijeme|telenovela|Simpsoni|Panther|Prijatelji|kulture|otvoreno|dossier.hr)/i;
13
14 sub scrape {
15 my $url = shift;
16 my $feed = XML::FeedPP->new( $url );
17 # print "Title: ", $feed->title(), "\n";
18 # print "Date: ", $feed->pubDate(), "\n";
19 foreach my $item ( $feed->get_item() ) {
20 my ( $channel, $date ) = split /\s*-\s*/, $item->title(), 2;
21 my ( $dd, $mm, $yyyy ) = split /\./, $date, 3;
22 my $program = $item->description();
23 $program =~ s{<div[^>]*>}{\n}gs;
24 $program =~ s{</div>}{\n}gs;
25 my @last;
26 foreach my $line ( split(/\n+/, $program) ) {
27 if ( $line =~ s{<strong>(\d+):(\d+)</strong>\s*}{} ) {
28 my ($h,$m) = ($1,$2);
29 my $link = $1 if $line =~ s{<a.+href="(.+?)">([^<]+)</a>}{$2};
30 my $t = DateTime->new(
31 year => $yyyy, month => $mm, day => $dd,
32 hour => $h, minute => $m
33 );
34 if ( @last ) {
35 my ( $dt, $description, $link ) = @last;
36 $t->add( days => 1 ) if $t < $dt;
37 my $duration = $t - $dt;
38 my $sec = $duration->hours * 60 * 60
39 + $duration->minutes * 60
40 + $duration->seconds;
41 #warn "# $t $dt = $sec\n";
42 my $store = 1 if $description =~ $record && $t > $now;
43 printf "%s %4s %s %s %4d\t%s%s\n",
44 $store ? 'echo' : '####',
45 $channel,
46 $dt->ymd('-'), $dt->hms(':'), $sec,
47 $description,
48 $link ? "\t<$link>" : ''
49 ;
50
51
52 if ( $store ) {
53 my $hhmm = $dt->hms(':');
54 $hhmm =~ s{:\d\d$}{};
55 print "echo ./record-stream.sh 0 $channel $sec | at $hhmm\n";
56 }
57 };
58
59
60 @last = ( $t, $line, $link );
61 }
62 }
63 }
64 }
65
66 scrape "http://mojtv.hr/rss/rsschannel.ashx?id=$_" foreach ( 1,2,3,4 );

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26