Topic: perl script to reformat chordie format
When i play live, i like to have the entire song (lyrics and chords) on one sheet of paper with a minimum of 12 pt font. I find the chordie format (with the chords on top) does not suit this very well. I created this hack of a perl script to reformat chordie songs the way i like to see them, so i thought i would share with those who might like to use it - you have to have perl installed of course - yes its a hack. Maybe chordie might see fit to incorporate this format one day? pretty please.
the format btw look like this.... I am [A] a song [E] these are my [D] lryics
#!/usr/bin/perl
# do a view source on your chordie song and paste the contents
# into a file name song.txt
$inFile = 'D:\chordie\song.txt';
# rename this output file to whatever you want
# this is where the formatted song will be output
$outFile = 'D:\chordie\formattedsong.txt';
open (INFILE, "$inFile")||die $!;
open (OUTFILE, ">$outFile")||die $!;
my $title = '';
my $artist = '';
my @chords = ();
my @lyrics = ();
while (<INFILE>){
if ($_ =~ /finaltitle/i){
($x,$y,$title) = split/>/,$_;
$title =~ s/<\/h1//gi;
$title =~ s/^\s//;
}
if ($_ =~ /finalartist/i){
($x,$y,$artist) = split/>/,$_;
$artist =~ s/<\/h2//gi;
$artist =~ s/^\s//;
chomp $artist;
print OUTFILE "$artist - $title\n\n";
}
if ($_ =~ /<tr class="cl">/){
$_ =~ s/<td> <\/td>//gi;
$_ =~ s/<tr class="cl">//gi;
$_ =~ s/<\/td>//gi;
$_ =~ s/<\/tr>//gi;
$_ =~ s/\n//gi;
@chords = split(/<td class="c">/,$_);
}
if ($_ =~ /<tr class="tl">/){
$_ =~ s/<td> <\/td>//gi;
$_ =~ s/<tr class="tl">//gi;
$_ =~ s/<\/td>//gi;
$_ =~ s/<\/tr>//gi;
@lyrics = split(/<td>/,$_);
my $i=0;
foreach $l (@lyrics){
$l =~ s/\n//gi;
$l =~ s/ //gi;
chomp $l;
$l =~ s/^\s//gi;
print OUTFILE "$l";
if ($chords[$i] =~ /\w/){
if ($l !~ /\w/){
print OUTFILE "[" . $chords[$i] . "] ";
}else{
print OUTFILE " [" . $chords[$i] . "] ";
}
}
$i++;
}
print OUTFILE "\n";
@chords =();
@lyrics = ();
}
}
print "Done. Press any key to exit.";
$in = <STDIN>;