Archival of video podcasts Български

June 18th, 2008Category: My Life

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:

  1. #!/usr/bin/perl -w
  2. # This script gets the latest Systm Podcast feed.
  3. # It will check if the episode is downloaded and if not,
  4. # it will download it, generate a .flv video, look for the
  5. # $flag entry in index.html and will insert html code for
  6. # the downloaded episode.
  7. #
  8. # Requires: ffmpeg, flvtool2, mencode and convert (IM)
  9. #
  10. #
  11. # by Georgi Todorov
  12. #
  13. #
  14. use strict;
  15. use XML::RSS;
  16. use LWP::Simple;
  17. use Date::Format;
  18. use Date::Parse;
  19.  
  20. my $duration;
  21. my $image;
  22. my $url2parse;
  23. my $title;
  24. my $url;
  25. my $desc;
  26. my $ep=0;
  27. my $fname;
  28. my $class;
  29. my $line;
  30. my $i=0;
  31. my $date;
  32. my @asdf;
  33. my @splitted;
  34. my $extension;
  35. my $enc;
  36. # Create new instance of XML::RSS
  37. my $rss = new XML::RSS;
  38. # Get the URL, assign it to url2parse, and then parse the RSS content
  39. $url2parse = get("http://revision3.com/systm/feed/quicktime-high-definition");
  40. #print $url2parse;
  41. $rss->parse($url2parse);
  42. # Print the channel items
  43. #print $rss->as_string;
  44. open OLDINDEX, "<index.html";
  45. open NEWINDEX, ">newindex.html";
  46. my $flag = "<!--start-->";
  47. while ( $line = <OLDINDEX>){
  48. chomp($line);
  49. if ($line eq $flag){
  50. print NEWINDEX $line."\n";
  51. $i = 1;
  52. }
  53. if ($i == 0){
  54. print NEWINDEX $line."\n";
  55. }else{
  56. foreach my $item (@{$rss->{'items'}}) {
  57. next unless defined($item->{'title'}) && defined($item->{'enclosure'});
  58. $date = time2str("%A, %B %o, %Y", str2time($item->{'pubDate'}));
  59. $date =~s/ +/ /gi;
  60. $url = $item->{'enclosure'}->{'url'};
  61. @asdf = split(/\//, $url);
  62. $ep = $asdf[$#asdf-1];
  63. $ep =~s/^0*//;
  64. $title = "Episode ". $ep;
  65. @splitted = split(/\./, $url);
  66. $extension = $splitted[$#splitted];
  67. if ( $ep%2 == 0 ){
  68. $class = "left";
  69. }else{
  70. $class = "right";
  71. }
  72. $fname = "Systm Episode ".$ep." (".$date.")";
  73. $desc = $item->{'description'};
  74.  
  75. print "-------- Working on $title --------\n";
  76. print "Looking for $fname.$extension ...";
  77. if (-e "$fname.m4v")
  78. {
  79. print "found. Skipping.\n";
  80. }elsif (-e "$fname.flv")
  81. {
  82. print "found. Skipping.\n";
  83. }else{
  84. print "not found. Downloading:\n";
  85. system ("wget $url -O \"$fname.$extension\"");
  86. print "Generating a Thumbnail and Encoding:\n";
  87. system ("ffmpeg -y -i \"$fname.$extension\" -f image2 -ss 100 -vframes 1 -an out.jpg");
  88. system ("convert out.jpg -resize x100 -quality 95 \"images/$fname.jpg\"");
  89. system ("rm out.jpg");
  90. system ("./encode2 \"$fname.$extension\" \"$fname.flv\"");
  91. system ("flvtool2 -UP \"$fname.flv\"");
  92. $duration = `/usr/bin/ffmpeg -i \"$fname.flv\" 2>&1|grep Duration|cut -d \":\" -f 3,4|cut -d \",\" -f 1`;
  93. print NEWINDEX "<div class=\"$class\">\n";
  94. print NEWINDEX "\t<div class=\"imglt\">\n";
  95. print NEWINDEX "\t\t<img src=\"images/$fname.jpg\" alt=\"$fname\" /><br />\n";
  96. print NEWINDEX "\t\t<a href='javascript:flowPlayerOpenFullScreen(\"$fname.flv\")' class=\"download_button\" >Play</a>\n";
  97. print NEWINDEX "\t\t<a href=\"$fname.mov\" class=\"download_button\" >Download</a>\n";
  98. print NEWINDEX "\t</div>\n";
  99. print NEWINDEX "\t<b>$title ($date)</b<br />\n";
  100. print NEWINDEX "\t<b>Length:</b> $duration\n";
  101. print NEWINDEX "\t<p>$desc</p>\n";
  102. print NEWINDEX "</div>\n";
  103. if ($class eq "right"){
  104. print NEWINDEX "<div class=\"clear\">\n";
  105. print NEWINDEX "\t&nbsp;<br />\n\t&nbsp;\n";
  106. print NEWINDEX"</div>\n";
  107. }
  108. }
  109. print "-------- DONE --------\n";
  110.  
  111. }
  112. $i = 0;
  113. }
  114. }
  115. close OLDINDEX;
  116. close NEWINDEX;
  117. system("mv index.html oldindex.html&&mv newindex.html index.html");
  118.  

It works pretty good for now. encode2 just contains the looooong mencoder command for encoding to flv:

  1. mencoder "$1" -o "$2" -of lavf -ovc lavc -oac lavc \
  2. -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames \
  3. -lavcopts vcodec=flv:vbitrate=800:autoaspect:mbd=2:\
  4. mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:precmp=2:\
  5. cmp=2:subcmp=2:preme=2:turbo:acodec=mp3:abitrate=56 \
  6. -srate 22050 -af lavcresample=22050

Leave a Reply


Georgi’s Blog is proudly powered by WordPress
Постове (RSS) and Коментари (RSS).
Get Firefox! Creative Commons License
21 queries. 0.636 seconds.