Add display of most recent play date.
[adorno.git] / www / dir.php
blob986845b072e521ce26318115b7a14281318b8b00
1 <?php
2 include("always.php");
3 $dd = urlencode("$d");
4 ?>
5 <html>
6 <head>
7 <title>Adorno - Directory of <?php echo str_replace("&nbsp;","",nice_track_name("$d")); ?></title>
8 </head>
9 <body bgcolor=white>
10 <table width=100%><tr>
11 <td><h2>Directory of <?php echo nice_track_name("$d"); ?></h2></td>
12 <td align=right><a href="/?submit=a&action=next">NEXT</a> &nbsp; | &nbsp;
13 <a href="/dir.php?d=$dd&submit=a&action=clear">CLEAR</a> &nbsp; | &nbsp;
14 <a href="/dir.php?d=$dd&submit=a&action=quit">QUIT</a> &nbsp; | &nbsp;
15 <a href="/dir.php?d=$dd&submit=a&action=off">OFF</a> &nbsp; | &nbsp;
16 <a href="/">TOP</a>
17 </td></tr></table>
18 <hr>
20 <?php
23 $dirname = eregi_replace( "\/*$", "", "/music" . "$d" );
24 $dirname = "/music" . "$d";
25 $tracklist = array();
26 $dirlist = array();
27 $md5list = array();
28 $in_database = false;
29 if ( $dir = opendir( "$dirname" ) ) {
30 while (($file = readdir($dir)) !== false) {
31 if ( is_dir( "$dirname/$file" ) ) {
32 if ( ereg( "^\.", $file ) ) continue;
33 array_push( $dirlist, $file );
35 else {
36 if ( !ereg( "\.(mp3)|(ogg)$", $file ) ) continue;
37 array_push( $tracklist, $file );
38 if ( ! $in_database ) {
39 $md5 = `/usr/bin/md5sum "$dirname$file"`;
40 list( $hashkey, $track) = explode( " ", trim($md5), 2);
41 $query = "SELECT * FROM tracks WHERE hash_key = '$hashkey';";
42 $result = pg_Exec( $dbconn, $query);
43 if ( $result && pg_NumRows($result) > 0 ) {
44 echo "$track was found in database<br>\n";
45 $in_database = true;
47 else {
48 $md5 = `/usr/bin/md5sum "$dirname$file"`;
49 array_push( $md5list, $md5 );
54 closedir($dir);
57 $file = ereg_replace( "/[^/]+/$", "/", $d);
58 echo "<p><a href=\"/dir.php?d=$file\">Up one level</a><br>\n";
60 sort ($dirlist);
61 reset ($dirlist);
62 while (list ($key, $val) = each ($dirlist)) {
63 // echo " &nbsp; <a href=\"/dir.php?d=$d&submit=a&action=queue&track=$d$val\">$val</a><br>\n";
64 echo "<a href=\"/dir.php?d=$d" . urlencode($val) . "/\">" . str_replace(" ", "&nbsp;", $val) . "</a> &nbsp; \n";
66 echo "</p>\n";
68 echo "<hr>\n";
70 if ( count($tracklist) > 0 ) {
71 echo "<p><b>Select tracks to Play</b><br>\n";
72 sort ($tracklist);
73 reset ($tracklist);
74 while (list ($key, $val) = each ($tracklist)) {
75 echo " &nbsp; <a href=\"/dir.php?d=$dd&submit=a&action=queue&track=$dd" . urlencode($val) . "\">$val</a><br>\n";
77 echo "</p>\n";
80 if ( count($md5list) > 0 ) {
81 echo "<p><b>Database List</b><br>\n";
82 reset ($md5list);
83 while (list ($key, $val) = each ($md5list)) {
84 list( $hashkey, $track) = explode( " ", trim($val), 2);
85 $query = "SELECT * FROM tracks WHERE hash_key = '$hashkey';";
86 $result = pg_Exec( $dbconn, $query);
87 if ( $result && pg_NumRows($result) > 0 ) {
88 echo "$track was found in database<br>\n";
90 else {
91 $track = trim($track);
92 echo "$track added into database<br>\n";
93 $safe_track = eregi_replace( '^.*/([^/]+)$', "\\1", str_replace( "'", "''", $track ));
94 $safe_path = str_replace( "'", "''", $track );
95 if ( eregi( '\.mp3$', $track ) ) {
96 $command = "mp3info -p '%n\t%t\t%l\t%a' '$track'"; // track number >> track title >> album name >> artist name
97 // error_log( "mdaemon: $command", 0);
98 $mp3info = `$command`; // track number >> track title >> album name >> artist name
99 // error_log( "mdaemon: $mp3info", 0);
100 list( $tnum, $ttitle, $talbum, $tartist ) = split( "\t", $mp3info, 4);
101 $tnum = intval($tnum);
102 $ttitle = str_replace( "'", "''", $ttitle );
103 $talbum = str_replace( "'", "''", $talbum );
104 $tartist = str_replace( "'", "''", $tartist );
105 $query = "INSERT INTO tracks ( hash_key, path_name, title, artist, album, tracknum ) ";
106 $query .= "VALUES( '$hashkey', '$safe_path', '$ttitle', '$tartist', '$talbum', '$tnum') ;";
108 else if ( eregi( '\.ogg$', $track ) ) {
109 $ogginfo = `ogginfo $track`;
111 // serial=1994287629
112 // header_integrity=pass
113 // ARTIST=Cranberries
114 // ALBUM=Bury the Hatchett
115 // TITLE=Fee Fi Fo
116 // TRACKNUMBER=12
117 // vendor=Xiphophorus libVorbis I 20011231
118 // version=0
119 // channels=2
120 // rate=44100
121 // bitrate_upper=none
122 // bitrate_nominal=112015
123 // bitrate_lower=none
124 // stream_integrity=pass
125 // bitrate_average=114037
126 // length=287.133333
127 // playtime=4:47
128 // stream_truncated=false
130 $trackinfo = split( "\n", $ogginfo);
131 while( list( $k , $v ) = each( $trackinfo ) ) {
132 list( $type, $value ) = split( "=", $v, 2);
133 switch ( strtoupper($type) ) {
134 case 'ARTIST': $tartist = $value; break;
135 case 'ALBUM': $talbum = $value; break;
136 case 'TITLE': $ttitle = $value; break;
137 case 'TRACKNUMBER': $tnum = $value; break;
140 $tnum = intval($tnum);
141 $ttitle = str_replace( "'", "''", $ttitle );
142 $talbum = str_replace( "'", "''", $talbum );
143 $tartist = str_replace( "'", "''", $tartist );
145 $query = "INSERT INTO tracks ( hash_key, path_name, title, artist, album, tracknum ) ";
146 $query .= "VALUES( '$hashkey', '$safe_path', '$ttitle', '$tartist', '$talbum', '$tnum') ;";
147 // $query = "INSERT INTO tracks ( hash_key, path_name, title ) VALUES( '$hashkey', '$safe_path', '$safe_track') ;";
149 else {
150 $query = "INSERT INTO tracks ( hash_key, path_name, title ) VALUES( '$hashkey', '$safe_path', '$safe_track') ;";
152 $result = pg_Exec( $dbconn, $query);
154 // echo " &nbsp; <a href=\"/dir.php?d=$d&submit=a&action=queue&track=$d$val\">$val</a><br>\n";
158 show_queue();
162 </body>
163 </html>