X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=web%2Fwebchord.cgi;h=e657db8e290629bd3952c07e3d105798dc755afd;hb=HEAD;hp=15a318667775e8459d0da66c6b1f2394e481b6c1;hpb=6ccc008640029eca058691a3ee1a1dcce508e291;p=songbook.git diff --git a/web/webchord.cgi b/web/webchord.cgi index 15a3186..e657db8 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; @@ -20,7 +19,7 @@ use CGI qw(:standard); use CGI::Carp qw (fatalsToBrowser); use File::Basename; -my ($chopro, $output, $i); +my ($chopro, $i); my $documentRoot = "/web"; my $debug = param ('debug'); @@ -41,90 +40,83 @@ 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 +sub getTitle ($) { + my ($song) = @_; + + return fileparse ($song, qr/\.pro/); +} # getTitle + sub musicFileExists ($) { my ($song) = @_; debug "ENTER musicFileExists ($song)"; - - my $title = fileparse ($song, qr/\.pro/); + + my $title = getTitle ($song); my $musicfile = "/opt/media/$title.mp3"; - if (-r $musicfile) { - debug "Exists!"; - - return $title; - } else { - debug "Could not find $musicfile"; - - return undef; - } # if + return -r $musicfile; } # musicFileExists sub updateMusicpath ($$) { my ($chopro, $song) = @_; - my $title = musicFileExists $song; - # If there's no corresponding music file then do nothing - return unless $title; - + return unless musicFileExists $song; + # If the .pro file already has musicpath then do nothing - if ($chopro =~ /\{musicpath:.*\}/) { - debug "$song already has musicpath"; - } # if - return if $chopro =~ /\{musicpath:.*\}/; # 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'; - + my $title = getTitle $song; + 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 +127,58 @@ 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"; - } - print < $title - + + + + + END - $title = musicFileExists $song; - + $title = getTitle $song; + if ($title) { updateMusicpath $chopro, $song; } # if - + + my $titleLink = "$title"; print << "END"; - +
-END - - if ($title) { - print <<"END"; - -END - } # if -print <<"END"; + +
Home - -
$titleLink
+
+
+

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

+
+
END my $mode = 0; # mode defines which class to use @@ -237,27 +192,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 +224,38 @@ 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"; - my($i); - for($i = 0; $i < @chords; $i++) { - print ""; + print "
$chords[$i]
"; + print "\n"; + for(my $i = 0; $i < @chords; $i++) { + print ""; } - print "\n\n"; + print "\n\n"; for($i = 0; $i < @lyrics; $i++) { - print ""; + print ""; } - print "
$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 +270,4 @@ chopro2html ($chopro, $infile); print end_html(); -exit; - - +exit; \ No newline at end of file