62 )); |
62 )); |
63 $smarty->assign('allow_control', $allowcontrol); |
63 $smarty->assign('allow_control', $allowcontrol); |
64 $smarty->display('playlist.tpl'); |
64 $smarty->display('playlist.tpl'); |
65 } |
65 } |
66 |
66 |
|
67 function artwork_request_handler($httpd, $socket) |
|
68 { |
|
69 global $homedir; |
|
70 |
|
71 if ( !isset($_GET['artist']) || !isset($_GET['album']) ) |
|
72 { |
|
73 echo 'Please specify artist and album.'; |
|
74 return; |
|
75 } |
|
76 // get hash |
|
77 $artwork_hash = md5( strtolower(trim($_GET['artist'])) . strtolower(trim($_GET['album'])) ); |
|
78 $artwork_dir = "$homedir/.kde/share/apps/amarok/albumcovers"; |
|
79 if ( file_exists("$artwork_dir/large/$artwork_hash") ) |
|
80 { |
|
81 // artwork file found - scale and convert to PNG |
|
82 if ( !is_dir("$artwork_dir/greyhoundthumbnails") ) |
|
83 { |
|
84 if ( !@mkdir("$artwork_dir/greyhoundthumbnails") ) |
|
85 { |
|
86 return false; |
|
87 } |
|
88 } |
|
89 // check for the scaled cover image |
|
90 $target_file = "$artwork_dir/greyhoundthumbnails/$artwork_hash.png"; |
|
91 if ( !file_exists($target_file) ) |
|
92 { |
|
93 // not scaled yet, scale to uniform 50x50 image |
|
94 $artwork_filetype = get_image_filetype("$artwork_dir/large/$artwork_hash"); |
|
95 if ( !$artwork_filetype ) |
|
96 { |
|
97 return false; |
|
98 } |
|
99 // we'll need to copy the existing artwork file to our thumbnail dir to let scale_image() detect the type properly (it doesn't use magic bytes) |
|
100 if ( !copy("$artwork_dir/large/$artwork_hash", "$artwork_dir/greyhoundthumbnails/tmp{$artwork_hash}.$artwork_filetype") ) |
|
101 { |
|
102 return false; |
|
103 } |
|
104 // finally, scale the image |
|
105 if ( !scale_image("$artwork_dir/greyhoundthumbnails/tmp{$artwork_hash}.$artwork_filetype", $target_file, 50, 50) ) |
|
106 { |
|
107 return false; |
|
108 } |
|
109 // delete our temp file |
|
110 if ( !unlink("$artwork_dir/greyhoundthumbnails/tmp{$artwork_hash}.$artwork_filetype") ) |
|
111 { |
|
112 echo 'Couldn\'t delete the temp file'; |
|
113 return false; |
|
114 } |
|
115 } |
|
116 // we have it now, send the image through |
|
117 $fh = @fopen($target_file, 'r'); |
|
118 if ( !$fh ) |
|
119 return false; |
|
120 $httpd->header('Content-type: image/png'); |
|
121 $httpd->header('Content-length: ' . filesize($target_file)); |
|
122 $httpd->header('Expires: Wed, 1 Jan 2020 01:00:00 GMT'); |
|
123 while ( !feof($fh) ) |
|
124 { |
|
125 socket_write($socket, fread($fh, 51200)); |
|
126 } |
|
127 fclose($fh); |
|
128 } |
|
129 else |
|
130 { |
|
131 // artwork file doesn't exist |
|
132 $ar = htmlspecialchars($_GET['artist']); |
|
133 $al = htmlspecialchars($_GET['album']); |
|
134 $httpd->send_http_error($socket, 404, "The requested artwork file for $ar:$al could not be found on this server."); |
|
135 } |
|
136 } |
|
137 |
|
138 |