tango2mp3

ethan on 2003-01-18T14:48:32

I'll admit: I am a great fan of the Tango Argentino as it has been traditionally played, sung and recorded in Argentina for almost 100 years. todotango has a new playlist with ten random songs on their webside each day so naturally I scan this list to catch a few worthwhile songs.

Unfortunately, the audio is only available in either .wma or .ram format, both not exactly pleasant to convert. With the help of Perl, the CPAN, mplayer and lame it was a finger snap to set up a script that - fed with a digit specifcying the song - downloads the .wma song, extracts the meta data of the song for the id3-tags and converts the whole thing into mp3. Some people might be put off by the low audio quality (as mp3 it is around 50kbs / 22.05kHz)...but that just belongs to a real tango argentino. Lo-Fi obligatory.



#! /usr/bin/perl -w

use strict; use URI; use LWP::Simple; use HTML::TableContentParser;

our $PATH = "/mp3/oddities/tango argentino";

my $exit; while (@ARGV) {

my $param = get_wma(shift) or $exit |= 1, next; my $err = encode_wma($param); warn "Error on file $param->{wma}\n" if $err; $exit |= $err;

} exit $exit; sub get_wma { my $w = shift; my $q = do { my $uri = URI->new; $uri->query_form( id => $w, f => 'wax', amkyw => 'arg', ); $uri->query; };

my $src = get("http://www.todotango.com/english/download/play.asp?$q") or warn "Skipping: $w does not exist\n", return; if (!is_success(getstore("http://www.todotango.com/audio/wax/$w.wma", "$w.wma"))) { warn "Skipping: $w.wma is not downloadable\n"; return; } my $table = HTML::TableContentParser->new->parse($src)->[2]; local $_ = $table->{rows}->[0]->{cells}->[0]->{data}; my ($title, $comment, $artist) = m!<b>(.*?)</b>.*\((Music:.*)\).*((?:Orchestra|Singer):?\s.*?)<br>!s; # year better matched separately: it's not always there my ($year) = m!((?:19|20)\d{2})!;

my ($music, $lyric) = $comment =~ m!Music:(.*?)- Lyric:(.*)!; s/^\s+//g, s/\s+$// for $music, $lyric; $artist =~ s/Singer: ?//; my $param; $param->{title} = $title; $param->{artist} = $artist; $param->{comment} = "$music/$lyric"; $param->{year} = $year || ''; $param->{wma} = "$w.wma"; $param; } sub encode_wma { my $arg = shift; my $target = "$PATH/$arg->{artist} - $arg->{title}.mp3"; my @mply_args = (qw/mplayer -ao pcm/, $arg->{wma}); my @lame_args = (qw/lame -h -v/, '--tt' => $arg->{title}, '--ta' => $arg->{artist}, '--ty' => $arg->{year}, '--tc' => $arg->{comment}, '--tg' => 'Tango', 'audiodump.wav', $target); warn "Invoking: \n", join " ", @mply_args, "\n\n"; system @mply_args; warn "Invoking: \n", join " ", @lame_args, "\n\n"; return system @lame_args; }