Fixed up title handling
[songbook.git] / web / webchord.cgi
index a64b4c1..e657db8 100755 (executable)
@@ -19,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');
@@ -68,38 +68,30 @@ sub error {
   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
@@ -118,6 +110,7 @@ sub updateMusicpath ($$) {
   } # unless
 
   my $songbase = '/sdcard';
+  my $title    = getTitle $song;
 
   print $songfile "{musicpath:$songbase/SongBook/Media/$title.mp3}\n";
 
@@ -144,8 +137,8 @@ sub chopro2html ($$) {
   if (($chopro =~ /^{subtitle:(.*)}/mi) || ($chopro =~ /^{st:(.*)}/mi)) {
     $artist = $1;
   } # if
-  
-  print <<END;
+
+  print <<"END";
 <html>
 <head>
 <title>$title</title>
@@ -158,24 +151,29 @@ sub chopro2html ($$) {
 <body>
 END
 
-      $title = musicFileExists $song;
+      $title = getTitle $song;
 
       if ($title) {
         updateMusicpath $chopro, $song;
       } # if
 
+      my $titleLink = "<a href=\"/songbook/pro/$title.pro\">$title</a>";
       print << "END";
 <table id="heading">
   <tbody>
     <tr>
       <td align="left"><a href="/songbook"><img src="/Icons/Home.png" alt="Home"></a></td>
-      <td><div id="title">$title</div>
+      <td><div id="title">$titleLink</div>
           <div id="artist"><a href="/songbook/displayartist.php?artist=$artist">$artist</a></div></td>
       <td align="right" width="300px">
         <audio id="song" controls autoplay style="padding:0; margin:0">
-          <source src="http://defaria.com/Media/$title.mp3" style="padding:0; margin:0" type='audio/mp3'>
+          <source src="https://defaria.com/Media/$title.mp3" style="padding:0; margin:0" type='audio/mp3'>
           Your user agent does not support the HTML5 Audio element.
-        </audio>
+        </audio><br>
+        <p align="center" <font size=-1><b>Mark A:</b></font>
+                          <font size=-1 color=#666><span id="a"><i>not set</i></span></font>
+                          <font size=-1><b>Mark B:</b></font>
+                          <font size=-1 color=#666><span id="b">not set</span></font></p>
       </td>
     </tr>
   </tbody>
@@ -238,8 +236,7 @@ END
       } else {
         print "<table cellpadding=0 cellspacing=0>";
         print "<tr>\n";
-        my($i);
-        for($i = 0; $i < @chords; $i++) {
+        for(my $i = 0; $i < @chords; $i++) {
           print "<td class=\"$cClasses[$mode]\">$chords[$i]</td>";
         }
         print "</tr>\n<tr>\n";
@@ -250,7 +247,7 @@ END
       } # if
     } # if
   } # while
-  
+
   print "</div>";
 } # chordpro2html