#!/usr/bin/perl -wT # Copyright 2008 Michael Moore, # Licensed under the GNU GPL V.2 # This script requires that you have Perl and curl installed. Curl must be in your path. # You will also need the HTML::Entities and POSIX Perl modules available. These might # be available by default. use strict; use warnings; use HTML::Entities; use POSIX qw(strftime); my $curl = '/usr/bin/curl'; $ENV{'PATH'} = ""; my $feedType = 'mp3'; if(defined($ARGV[1]) && $ARGV[1] =~ m/[a-zA-Z0-9]{3}/){ $feedType = $ARGV[1]; } if(!defined($ARGV[0]) || $ARGV[0] =~ 'help' || $ARGV[0] eq '-h' || ($feedType ne 'mp3' && $feedType ne 'eng' && $feedType ne 'asl')){ print "\n\tUSAGE: ./ConferenceFeed.pl http://conferenceURL.html [eng | asl | mp3]\n\n"; print "\tConference URL is the URL of a page like this: http://www.lds.org/conference/sessions/display/0,5239,49-1-775,00.html\n"; print "\teng is for English Video in mp4 format\n"; print "\tasl is the American Sign Language mp4 video\n"; print "\tmp3 is the audio version, in whatever langauge the conference HTML page is in. mp3 is the default\n"; die("\n\tPlease pass a conference page URL\n\n"); } my $feedURL = $ARGV[0]; if($feedURL =~ m/^(http:\/\/(www\.)?lds\.org\/conference\/sessions\/display\/[0-9,-]*\.html)$/){ $feedURL = $1; }else{ die("Not a valid URL!\nRun with '--help' for usage\n"); } my @lines = `$curl $feedURL`; my $baseURL = "http://www.lds.org"; my %eng; my %asl; my %mp3; my %meta; my $session = ""; my $title = ""; my $author = ""; my $article = ""; my $talkNumber = 0; my $feedSummary = ""; my $feedIcon = ""; my $feedTitle = ""; foreach(@lines){ if($_ =~ m/(.*)<\/span/){ $session = $1; } if($_ =~ m/
(.*)<\/div>/){ $title = $author; $author = $1; $author =~ s/<(.*?)>//g; $author =~ s/“/'/; $author =~ s/”/'/; $author =~ s/'''/'/; $author = HTML::Entities::decode_entities($author); $author = HTML::Entities::encode_entities_numeric($author); } if($_ =~ m/featurestitle2">(.*)<\/span/){ $feedTitle = $1; } if($_ =~ m/(\/conference.*html).*onClick/){ $article = $baseURL . $1; } if ($_ =~ m/(http.*_\.mp3)"/ || $_ =~ m/(http.*eng.*\.mp4)"/ || $_ =~ m/(http.*ase_.*\.mp4)"/) { next if ($author eq ""); $meta{$talkNumber} = {'author' => $author, 'session' => $session, 'title' => $title, 'article' => $article}; $mp3{$talkNumber} = $1 if ($_ =~ m/(http.*_\.mp3)"/); $eng{$talkNumber} = $1 if ($_ =~ m/(http.*eng.*\.mp4)"/); if (($feedType eq 'mp3' && $_ =~ m/(http.*_\.mp3)"/) ||($_ =~ m/(http.*ase_.*\.mp4)"/)) { $asl{$talkNumber} = $1; $talkNumber++; $author = ""; } } } print ' ' . $feedTitle . ' ' . $feedURL . ' ' . $feedSummary . ' en-us Intellectual Reserve, Inc. 2008 ' . strftime("%a, %d %b %Y %H:%M%S %z",localtime(time())) . ' ' . $feedIcon . ' ' . $feedSummary . ' ' . $feedURL . ' '; foreach my $talk (sort keys %mp3) { # print $meta{$talk}->{'session'} . " :: " . $meta{$talk}->{'title'} . " : " . $meta{$talk}->{'author'} . " : " . $mp3{$talk} . " : " . $meta{$talk}->{'article'}. "\n"; print '' . $meta{$talk}->{'title'} . '' . $meta{$talk}->{'article'} . '' . $meta{$talk}->{'author'} . ' : ' . $meta{$talk}->{'title'} . ' : ' . $meta{$talk}->{'session'} . ''; print '' if($feedType eq 'eng'); print '' if($feedType eq 'asl'); print '' if($feedType eq 'mp3'); print ' '; } print ' ';