CodeWiki : flv2audio

WikiHome :: List Pages :: Login
cmantito.com

Script Information


This script is a quick Perl hack I wrote that, when supplied with a URL to an FLV file, downloads the FLV file to /tmp, and extracts the audio from it, then gets rid of the FLV.

I frequently find music videos on YouTube, etc, of songs I like that I either can't get the name of (to find the song on LimeWire/BitTorrent/iTunes Music Store), or can't find the song on LimeWire/BitTorrent/iTunes Music Store. This lets me get the music out of the video quickly and easily.



Source Code


flv2audio.pl
#!/usr/bin/perl

if(!$ARGV[0] || !$ARGV[1]){
   print "Usage: flv2audio flvurl filename [-p]\n\n";
   print "\tflvurl\t\tURL to FLV video.\n";
   print "\tfilename\tFilename to dump audio to.\n\n";
   print "Options:\n";
   print "\t-p\tPlay the file after converting.\n\n";
   print "Example: flv2audio \"http://youtube.com/get_video?video_id=-drFTofDqoM&t=OEgsToPDskKbqHqh37NEu5bb857oKfUJ\" teamRocket.mp3\n";
   exit(15);
}else{
   print "Beginning...\n";
   
   print "Fetching data...\n";
   system("wget '".$ARGV[0]."' -o /dev/null -O '/tmp/".$ARGV[1].".tmp'");
   if($? > 0){
      print "Couldn't retrieve the specified URL. Aborting...\n(Is wget installed? Is /tmp writable?)\n";
      exit(10);
   }
   
   print "Converting & extracting...\n";
   system("mplayer -dumpaudio '/tmp/".$ARGV[1].".tmp' -dumpfile '".$ARGV[1]."' &>/dev/null");
   $exit = $?;
   print "Clearing cache...\n";
   system("rm '/tmp/".$ARGV[1].".tmp' &>/dev/null");
   if($exit > 0){
      print "Couldn't extract and convert the audio. Aborting...\n(Is mplayer installed? Is /tmp readable?)\n";
      exit(5);
   }
   
   print "Finished extraction.\n";
   if($ARGV[2] eq "-p"){
      print "Playing file... (^C to abort)\n";
      system("mplayer '".$ARGV[1]."' &>/dev/null");
      if($? > 0){
         print "Couldn't complete playing the audio file.\n(Maybe you hit ^C? Does the file still exist?)\n";
      }
   }
   print "Exiting normally...\n";
   exit(0);
}



Categories: CategoryDiscontinued
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki