Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ethan (3163)

  reversethis-{ed. ... rap.nov.olissat}

Being a 25-year old chap living in the western-most town of Germany. Stuying communication and information science and being a huge fan of XS-related things.

Journal of ethan (3163)

Saturday January 18, 2003
09:48 AM


[ #10054 ]

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;
                        id => $w,
                        f => 'wax',
                        amkyw => 'arg',

        my $src = get("$q")
                or warn "Skipping: $w does not exist\n", return;
        if (!is_success(getstore("$w.wma",
                                                          "$w.wma"))) {
                warn "Skipping: $w.wma is not downloadable\n";

        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";

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',
        warn "Invoking: \n", join " ", @mply_args, "\n\n";
        system @mply_args;
        warn "Invoking: \n", join " ", @lame_args, "\n\n";
        return system @lame_args;

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.