X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=web%2Fwebchord.cgi;h=c9bb1e37aa350620e10bbeab3017a7b1d18fe929;hb=ecd3c635d8d78181bed4fa98cc6162e0b6516160;hp=15a318667775e8459d0da66c6b1f2394e481b6c1;hpb=6ccc008640029eca058691a3ee1a1dcce508e291;p=songbook.git diff --git a/web/webchord.cgi b/web/webchord.cgi index 15a3186..c9bb1e3 100755 --- a/web/webchord.cgi +++ b/web/webchord.cgi @@ -12,7 +12,6 @@ # 2003-08-03 Version 1.1 Uses stylesheets # 2014-02-05 Added things particular to my implementation of Songbook at # http://defaria.com/songbook - use strict; use warnings; @@ -41,31 +40,31 @@ unless (-f $infile) { sub debug ($) { my ($msg) = @_; - + return unless $debug; - + print "Debug: $msg
"; - + return; } # debug -sub warning ($) { +sub warning ($) { my ($msg) = @_; debug "warning"; print "Warning $msg
"; - return; + return; } # warning sub error { my ($msg) = @_; - + print "Web Chord: Error" . "

Error

\n$msg\n

" . ""; - + exit; } # error @@ -73,17 +72,17 @@ sub musicFileExists ($) { my ($song) = @_; debug "ENTER musicFileExists ($song)"; - + my $title = fileparse ($song, qr/\.pro/); my $musicfile = "/opt/media/$title.mp3"; if (-r $musicfile) { debug "Exists!"; - + return $title; } else { debug "Could not find $musicfile"; - + return undef; } # if } # musicFileExists @@ -92,10 +91,10 @@ sub updateMusicpath ($$) { my ($chopro, $song) = @_; my $title = musicFileExists $song; - + # If there's no corresponding music file then do nothing return unless $title; - + # If the .pro file already has musicpath then do nothing if ($chopro =~ /\{musicpath:.*\}/) { debug "$song already has musicpath"; @@ -105,26 +104,26 @@ sub updateMusicpath ($$) { # Otherwise append the musicpath my $songfile; - + open $songfile, '>>', $song or undef $songfile; - + unless (defined $songfile) { my $msg = "Unable to open $song for append - $!
"; $msg .= "
Please notify Andrew DeFaria so this can be corrected.
"; $msg .= "
Thanks"; warning $msg; - + return; } # unless my $songbase = '/sdcard'; - + print $songfile "{musicpath:$songbase/SongBook/Media/$title.mp3}\n"; - + close $songfile; - return; + return; } # updateMusicPath # Outputs the HTML code of the chordpro file in the first parameter @@ -135,95 +134,57 @@ sub chopro2html ($$) { $chopro =~ s/\>/\>/g; # replace > with > $chopro =~ s/\&/\&/g; # replace & with & - my $title; - - if(($chopro =~ /^{title:(.*)}/mi) || ($chopro =~ /^{t:(.*)}/mi)) { + my $title = "ChordPro Song"; + my $artist = "Unknown"; + + if (($chopro =~ /^{title:(.*)}/mi) || ($chopro =~ /^{t:(.*)}/mi)) { $title = $1; - } else { - $title = "ChordPro song"; - } + } # if + + if (($chopro =~ /^{subtitle:(.*)}/mi) || ($chopro =~ /^{st:(.*)}/mi)) { + $artist = $1; + } # if + print < $title - + + + + + END $title = musicFileExists $song; - + if ($title) { updateMusicpath $chopro, $song; } # if - + print << "END"; - +
-END - - if ($title) { - print <<"END"; - -END - } # if -print <<"END"; + +
Home - -
$title
+
+
+

Mark A: + not set + Mark B: + not set

+
+
END my $mode = 0; # mode defines which class to use @@ -237,27 +198,23 @@ END $_ = $1; chomp; - if(/^#(.*)/) { # a line starting with # is a comment - print "\n"; # insert as HTML comment - } elsif(/{(.*)}/) { # this is a command + if (/^#(.*)/) { # a line starting with # is a comment + print "\n"; # insert as HTML comment + } elsif (/{(.*)}/) { # this is a command $_ = $1; - if(/^title:/i || /^t:/i) { # title - print "

$'

\n"; - } elsif(/^subtitle:/i || /^st:/i) { # subtitle - print "

$'

\n"; - } elsif(/^start_of_chorus/i || /^soc/i) { # start_of_chorus + if (/^start_of_chorus/i || /^soc/i) { # start_of_chorus $mode |= 1; - } elsif(/^end_of_chorus/i || /^eoc/i) { # end_of_chorus + } elsif (/^end_of_chorus/i || /^eoc/i) { # end_of_chorus $mode &= ~1; - } elsif(/^comment:/i || /^c:/i) { # comment + } elsif (/^comment:/i || /^c:/i) { # comment print "($')\n"; - } elsif(/^comment_italic:/i || /^ci:/i) { # comment_italic + } elsif (/^comment_italic:/i || /^ci:/i) { # comment_italic print "($')\n"; - } elsif(/^comment_box:/i || /^cb:/i) { # comment_box + } elsif (/^comment_box:/i || /^cb:/i) { # comment_box print "

$'

\n"; - } elsif(/^start_of_tab/i || /^sot/i) { # start_of_tab + } elsif (/^start_of_tab/i || /^sot/i) { # start_of_tab $mode |= 2; - } elsif(/^end_of_tab/i || /^eot/i) { # end_of_tab + } elsif (/^end_of_tab/i || /^eot/i) { # end_of_tab $mode &= ~2; } else { print "\n"; @@ -273,37 +230,39 @@ END } push(@lyrics,$_); # rest of line (after last chord) into @lyrics - if($lyrics[0] eq "") { # line began with a chord + if ($lyrics[0] eq "") { # line began with a chord shift(@chords); # remove first item shift(@lyrics); # (they are both empty) } - if(@lyrics==0) { # empty line? + if (@lyrics==0) { # empty line? print "
\n"; - } elsif(@lyrics==1 && $chords[0] eq "") { # line without chords - print "
$lyrics[0]
\n"; + } elsif (@lyrics==1 && $chords[0] eq "") { # line without chords + print "
$lyrics[0]
\n"; } else { - print ""; - print "\n"; + print "
"; + print "\n"; my($i); for($i = 0; $i < @chords; $i++) { - print ""; + print ""; } - print "\n\n"; + print "\n\n"; for($i = 0; $i < @lyrics; $i++) { - print ""; + print ""; } - print "
$chords[$i]$chords[$i]
$lyrics[$i]$lyrics[$i]
\n"; + print "\n"; } # if } # if } # while + + print "
"; } # chordpro2html ## Main print header; unless ($infile) { - error "No chordpro parameter"; + error "No chordpro parameter"; } # unless open my $file, '<', $infile @@ -318,6 +277,4 @@ chopro2html ($chopro, $infile); print end_html(); -exit; - - +exit; \ No newline at end of file