Sorry there was a missing comma in the last version.

Rob
-- 
         \                      Robert Hart
       ___\______               [EMAIL PROTECTED]
      /   ^    \_]======]       http://www.nott.ac.uk/~enxrah
 ____[##########\_____
/ ___________________ \         15 Benington Drive
\/{oOOOOOOOOOOOOOOOo}\/         Wollaton
  \o%%%%%%%%%%%%%%%o/           Nottingham
   ~~~~~~~~~~~~~~~~~            NG8 2TF
Index: cgi-bin/playlist.pl
===================================================================
RCS file: /src/repository/obs/cgi-bin/playlist.pl,v
retrieving revision 1.13
diff -u -r1.13 playlist.pl
--- cgi-bin/playlist.pl 2001/07/19 03:10:55     1.13
+++ cgi-bin/playlist.pl 2001/09/07 14:14:49
@@ -284,6 +284,32 @@
     }
 }
 
+sub SecsToTimeString {
+    my $time=pop @_;
+    my ($secs, $mins, $hours, $days);
+    $secs=$time % 60;
+    $mins=int($time/60) % 60;
+    $hours=int($time/3600) % 24;
+    $days=int($time/24/3600);
+
+    if ($secs<10){ $secs="0$secs"; }
+    if ($hours && $mins < 10){ $mins="0$mins"; }
+
+    if ($hours) {
+       $hours="$hours:"; }
+    else {
+       $hours=""; }
+    
+    if ($days>1) {
+       $days="$days days "; }
+    elsif ($days==1) {
+       $days="1 day ";}
+    else {
+       $days=""; }
+
+    return "$days$hours$mins\:$secs";
+}
+
 my (%states);
 my $o = new CGI;
 my ($list, $listcookie, $dbh, $sth);
@@ -325,8 +351,8 @@
 if (!$dbh)
 {
     print "<font size=+1 color=red>Sorry, the database is currently ";
-    print "not available. Please try again in a few minutes.</font>";
-    print "(Error: ",$DBI::errstr,")";
+    print "not available. Please try again in a few minutes.</font>\n";
+    print "(Error: ",$DBI::errstr,")\n";
 } 
 
 my $add = $o->param('add');
@@ -349,7 +375,7 @@
         {
               if ($sth->rows == 0)
                 {
-                    print "This list has been deleted.";
+                    print "This list has been deleted.\n";
                 $sth->finish;
                 print $o->end_html;
 
@@ -445,11 +471,11 @@
     print '<td><input name="Add to Play Queue" type="image" border="0" ';
     print 'alt="Add to Play Queue" src="/obs/images/add.gif"></td>';
 }
-print "</tr></table>";
+print "</tr></table>\n";
 
 print '<table border=0 cellpadding=1 cellspacing=2 width=100%>';
-print '<tr><td colspan=3>&nbsp;</td></tr><tr>';
-print '<td colspan=3 bgcolor="#cccccc" align=right>';
+print '<tr><td colspan=4>&nbsp;</td></tr><tr>';
+print '<td colspan=4 bgcolor="#cccccc" align=right>';
 print '<font face="helvetica" color="red" size=2>';
 
 $sth = $dbh->prepare("select name from Playlist where id = $list");
@@ -466,13 +492,14 @@
 
 
 $sth = $dbh->prepare("select Track.id, Track.name, Artist.name, Locked, " .
-                     "Listitems.id, Slot from Playlist,Listitems,Track," .
+                     "Listitems.id, Slot, Track.length from 
+Playlist,Listitems,Track," .
                      "Artist where Playlist.Id=$list and Listnumber=" .
                      "Playlist.Id and Track.Id=Tracknumber and " .
                      "Track.artist = Artist.Id order by Slot");
 if ($sth->execute())
 {
-    my (@row, $i);
+    my (@row, $i, $mins, $secs, $totallength);
+    $totallength=0;
 
     HandleSelectPageOps(\%states, $o, $sth->rows);
     for($i = 0; @row = $sth->fetchrow_array; $i++) 
@@ -501,13 +528,21 @@
         {
            print '<font face="helvetica" color=black link=black size=2>';
         }
+
+       $totallength+=$row[6];
+
         print $o->escapeHTML($row[1]) . " -- ";
         print $o->escapeHTML($row[2]);
+       print "</b></td><td bgcolor=white width=40>" .
+           "<font face=\"helvetica\" color=black link=black size=2>" .
+               SecsToTimeString($row[6] / 10) . "</font>";
+        print "</td></tr>\n";
 
-        print "</b></td></tr>";
     }
 
     $sth->finish();
+    print "<tr><td colspan=4>Estimated Total Length: " . 
+       SecsToTimeString($totallength/10) . "</td></tr>\n";
 }
 else
 {
Index: perl/Obs/LocalIO/LocalIO.pm
===================================================================
RCS file: /src/repository/obs/perl/Obs/LocalIO/LocalIO.pm,v
retrieving revision 1.6
diff -u -r1.6 LocalIO.pm
--- perl/Obs/LocalIO/LocalIO.pm 2000/03/27 00:22:33     1.6
+++ perl/Obs/LocalIO/LocalIO.pm 2001/09/07 14:14:49
@@ -264,13 +264,13 @@
 
 sub AddTrack
 {
-   my ($this, $name, $url, $album_id, $artist_id, $tracknum, $size) = @_;
+   my ($this, $name, $url, $album_id, $artist_id, $tracknum, $size, $length) = @_;
 
    $name = $this->{DBH}->quote($name);
    $url = $this->{DBH}->quote($url);
-   $this->{DBH}->do("insert into Track (Name, Artist, Album, TrackNum, Size, " .
+   $this->{DBH}->do("insert into Track (Name, Artist, Album, TrackNum, Size, Length, 
+" .
                     "Url, LastChanged) values ($name, $artist_id, " .
-                    "$album_id, $tracknum, $size, $url, now())");
+                    "$album_id, $tracknum, $size, $length, $url, now())");
 
    return _GetLastInsertId($this->{DBH});
 }
Index: tools/AddFiles.pl
===================================================================
RCS file: /src/repository/obs/tools/AddFiles.pl,v
retrieving revision 1.10
diff -u -r1.10 AddFiles.pl
--- tools/AddFiles.pl   2001/08/01 02:39:06     1.10
+++ tools/AddFiles.pl   2001/09/07 14:14:49
@@ -26,6 +26,7 @@
 use Obs::Defs;
 use Obs::LocalIO;
 use MP3::Tag;
+use MP3::Info; 
 
 my $NumFound = 0;
 my $AllowedChars;
@@ -34,6 +35,12 @@
 my $Testing = 0;
 my ($dbh, $Volume, $UrlPath);
 
+sub GetLengthFromFilePath
+{
+    my ($file) = @_;
+    my $mp3 = new MP3::Info $file;
+    return int($mp3->secs *10);
+}
 sub GetInfoFromFileName
 {
     my ($file) = @_;
@@ -141,7 +148,7 @@
 {
     my ($dir, $UrlPath) = @_;
     my (@files, $file, $path, $newpath);
-    my ($tag, @statinfo, $size, $url, $track_id);
+    my ($tag, @statinfo, $size, $length, $url, $track_id);
     my ($artist, $artist_id, $album, $album_id, $title, $title_id, $tracknum);
     my ($id3);
 
@@ -168,7 +175,8 @@
         $size = $statinfo[7];
 
         ($artist, $album, $title, $tracknum) = 
-             GetInfoFromFileName($file);
+           GetInfoFromFileName($file);
+       ($length) = GetLengthFromFilePath($path);
 
         $id3 = MP3::Tag->new($path);
         $id3->getTags;
@@ -255,7 +263,7 @@
                 $album_id = $dbh->AddAlbum($album, $artist_id, "") 
                     if ($album_id < 0);
                 $track_id = $dbh->AddTrack($title, $url, $album_id, $artist_id,
-                                           $tracknum, $size);
+                                           $tracknum, $size, $length);
             }
             print("[added] ");
         }
@@ -269,7 +277,7 @@
                      if ($album_id < 0);
                  $track_id = $dbh->UpdateTrack($url, $title, 
                                      $album_id, $artist_id, $tracknum, 
-                                     $size, 0) ;
+                                     $size, $length) ;
                  print("[updated] ");
             }
             else
@@ -281,7 +289,8 @@
         print("\n   Artist: '$artist'\n");
         print("    Title: '$title'\n");
         print("    Album: '$album'\n");
-        print("    Track: '$tracknum'\n\n");
+        print("    Track: '$tracknum'\n");
+       print("    Length: '$length'\n\n");
     }
 }
 

Reply via email to