I’ve picked a few video podcasts that I like to watch. But because there is a lot of info there, quite some time ago I decided to start archiving them and make them accessible from everywhere I have internet. That involved a simple web page and converting every episode to flash to avoid codec problems. The best part is, that all of them have some type of rss feeds and make it easy to get the url to the video file, a description and some other useful info. So I sat down and wrote the following script:
#!/usr/bin/perl -w# This script gets the latest Systm Podcast feed.# It will check if the episode is downloaded and if not,# it will download it, generate a .flv video, look for the# $flag entry in index.html and will insert html code for# the downloaded episode.## Requires: ffmpeg, flvtool2, mencode and convert (IM)### by Georgi Todorov##use strict;use XML::RSS;use LWP::Simple;use Date::Format;use Date::Parse;my $duration;my $image;my $url2parse;my $title;my $url;my $desc;my $ep=0;my $fname;my $class;my $line;my $i=0;my $date;my @asdf;my @splitted;my $extension;my $enc;# Create new instance of XML::RSSmy $rss = new XML::RSS;# Get the URL, assign it to url2parse, and then parse the RSS content$url2parse = get("http://revision3.com/systm/feed/quicktime-high-definition");#print $url2parse;$rss->parse($url2parse);# Print the channel items#print $rss->as_string;open OLDINDEX, "<index.html";open NEWINDEX, ">newindex.html";my $flag = "<!--start-->";while ( $line = <OLDINDEX>){chomp($line);if ($line eq $flag){print NEWINDEX $line."\n";$i = 1;}if ($i == 0){print NEWINDEX $line."\n";}else{foreach my $item (@{$rss->{'items'}}) {next unless defined($item->{'title'}) && defined($item->{'enclosure'});$date = time2str("%A, %B %o, %Y", str2time($item->{'pubDate'}));$date =~s/ +/ /gi;$url = $item->{'enclosure'}->{'url'};@asdf = split(/\//, $url);$ep = $asdf[$#asdf-1];$ep =~s/^0*//;$title = "Episode ". $ep;@splitted = split(/\./, $url);$extension = $splitted[$#splitted];if ( $ep%2 == 0 ){$class = "left";}else{$class = "right";}$fname = "Systm Episode ".$ep." (".$date.")";$desc = $item->{'description'};print "-------- Working on $title --------\n";print "Looking for $fname.$extension ...";if (-e "$fname.m4v"){print "found. Skipping.\n";}elsif (-e "$fname.flv"){print "found. Skipping.\n";}else{print "not found. Downloading:\n";system ("wget $url -O \"$fname.$extension\"");print "Generating a Thumbnail and Encoding:\n";system ("ffmpeg -y -i \"$fname.$extension\" -f image2 -ss 100 -vframes 1 -an out.jpg");system ("convert out.jpg -resize x100 -quality 95 \"images/$fname.jpg\"");system ("rm out.jpg");system ("./encode2 \"$fname.$extension\" \"$fname.flv\"");system ("flvtool2 -UP \"$fname.flv\"");$duration = `/usr/bin/ffmpeg -i \"$fname.flv\" 2>&1|grep Duration|cut -d \":\" -f 3,4|cut -d \",\" -f 1`;print NEWINDEX "<div class=\"$class\">\n";print NEWINDEX "\t<div class=\"imglt\">\n";print NEWINDEX "\t\t<img src=\"images/$fname.jpg\" alt=\"$fname\" /><br />\n";print NEWINDEX "\t\t<a href='javascript:flowPlayerOpenFullScreen(\"$fname.flv\")' class=\"download_button\" >Play</a>\n";print NEWINDEX "\t\t<a href=\"$fname.mov\" class=\"download_button\" >Download</a>\n";print NEWINDEX "\t</div>\n";print NEWINDEX "\t<b>$title ($date)</b<br />\n";print NEWINDEX "\t<b>Length:</b> $duration\n";print NEWINDEX "\t<p>$desc</p>\n";print NEWINDEX "</div>\n";if ($class eq "right"){print NEWINDEX "<div class=\"clear\">\n";print NEWINDEX "\t <br />\n\t \n";print NEWINDEX"</div>\n";}}print "-------- DONE --------\n";}$i = 0;}}close OLDINDEX;close NEWINDEX;system("mv index.html oldindex.html&&mv newindex.html index.html");- Свалете този код/download this code: updatepodcast.pl
It works pretty good for now. encode2 just contains the looooong mencoder command for encoding to flv:
mencoder "$1" -o "$2" -of lavf -ovc lavc -oac lavc \-lavfopts i_certify_that_my_video_stream_does_not_use_b_frames \-lavcopts vcodec=flv:vbitrate=800:autoaspect:mbd=2:\mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:precmp=2:\cmp=2:subcmp=2:preme=2:turbo:acodec=mp3:abitrate=56 \-srate 22050 -af lavcresample=22050- Свалете този код/download this code: encode_to_flv
