1 <?php
require_once('./http_auth.php'); /*Delete this line to disable password protection*/ ?
>
4 ///////////////////////////////////////////////////////////////////////
6 0.2 - Few new functions (search playlist, random,...)
7 0.1.1 - Few little fixups, written help.html in Czech language ;D
8 0.1 - All functions works - TODO: bugfix & replace ugly code
9 ///////////////////////////////////////////////////////////////////////
13 $title = 'Harvie\'s JuKe!Box'; //Title of jukebox
14 $music_dir = './music'; //Local path to directory with music
15 $music_dir_url = 'http://192.168.2.163/pub/m3gen/music'; //URL path to same directory
16 //$music_dir_url = 'http://music.harvie.cz/music';
17 //$music_dir_url = 'http://softz.harvie.cz/jukebox/demo/music';
18 $cache_passwd = 'reload'; //You need this passwd to refresh search cache
19 $sort = 3; //Sort? 0 = none, 1 = playlists, 2 = 1+listings; 3 = 2+search-EXPERIMENTAL! (sorting could eat lot of memory)
20 $access_limit = 20; //How many files could be accessed without using cache (while searching)
23 $playlist_name = 'playlist.m3u'; //Name of downloaded pl
24 $m3u_exts = 'ogg|mp[0-9]|wma|wmv|wav'; //Allow only these files
25 $default_random_count = 30; //How many random songs by defaul?
28 $indexlist = array('index.html', 'index.txt'); //Search for this file in each directory
29 $bonus_dir = './jukebox-bonus'; //Misc. files directory
30 $search_cache = $bonus_dir.'/cache.db'; //Database for searching music (php +rw) - .htaccess: Deny from all!!!
31 $flash_player = $bonus_dir.'/musicplayer.swf'; //path to musicplayer
32 $css_file = $bonus_dir.'/jukebox.css'; //CSS
33 $header_file = $bonus_dir.'/header.html'; //header file
34 $footer_file = $bonus_dir.'/footer.html'; //footer file
41 $current_dir = ereg_replace('/+', '/', '/'.$_GET['dir'].'/');
42 $dir = $music_dir.$current_dir;
43 $url = $music_dir_url.$current_dir;
44 $parent_dir = dirname($current_dir);
47 function serve_download($filename) {
48 header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
49 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
50 header('Pragma: no-cache');
52 //header('Content-Type: application/force-download');
53 header('Content-Type: audio/x-mpegurl');
54 header("Content-Disposition: attachment; filename={$filename}");
55 header('Content-Transfer-Encoding: binary');
57 header('X-PHP-Application: Harvie\'s JuKe!Box');
60 function generate_m3u($dir, $prefix='', $recursive=0) {
63 while(($item = readdir($dd)) != false) {
64 if($item == '.' ||
$item == '..') continue;
65 if( is_file($dir.$item) && eregi(('\.('.$GLOBALS['m3u_exts'].')$'), $item) ) {
66 if($GLOBALS['sort'] > 0) {
69 echo($prefix.'/'.str_replace('%2F', '/', (rawurlencode($dir.$item)))."\r\n");
72 if($recursive && is_dir($dir.$item)) {
73 generate_m3u($dir.$item, $prefix);
76 if($GLOBALS['sort'] > 0) {
78 foreach($temp as $item)
79 echo($prefix.'/'.str_replace('%2F', '/', (rawurlencode($dir.$item)))."\r\n");
83 function write_search_cache($dir, $outfp) {
86 while($item = readdir($dd)) {
87 if($item == '.' ||
$item == '..') continue;
88 if( is_file($dir.$item) && eregi(('\.('.$GLOBALS['m3u_exts'].')$'), $item) ) {
89 fwrite($outfp, $dir.$item."\n");
91 if(is_dir($dir.$item)) {
92 write_search_cache($dir.$item, $outfp);
97 function generate_search_cache($dir, $outfile) {
98 echo("Generating search cache. Please wait...<br />\n"); flush();
99 @chmod
($outfile, 0755); //At least i tryed ;D
100 if(!($outfp = fopen($outfile, 'w')))
101 die("Cannot write cache to $outfile<br />You probably haven't set the permissions properly!<br />\n");
102 write_search_cache($dir, $outfp);
104 $osize = filesize($outfile); clearstatcache();
105 if($GLOBALS['sort'] > 2) {
106 echo("Sorting search cache. Please wait...<br />\n"); flush();
108 $items = file($outfile); @sort
($items);
109 $total = ' ('.sizeof($items).' files)';
110 file_put_contents($outfile, @implode
('', $items));
112 if(abs(filesize($outfile)-$osize) > 2)
113 die('ERROR! Please disable sorting of search cache ($sort < 3)<br />'."\nSorted only ".
114 filesize($outfile).' of '.$osize.' bytes!!!\n');
116 echo('Total: '.filesize($outfile).' of '.$osize.' bytes'.$total.' <a href="?">DONE!</a>'.'<br /><META http-equiv="refresh" content="2;URL=?">'."\n");
119 function render_file_line($dir, $item, $dir_url, $index, $filesize, $parent = false) {
120 $parclass=($index%2?
"even":"odd"); $parcolor=($index%2?
"lightblue":"white");
121 $temp=str_replace('&', '%26', dirname($dir_url)).'/'.str_replace('%2F', '/', (rawurlencode($dir.$item)));
122 if(is_numeric($filesize)) $filesize = round($filesize/(1024*1024), 2);
123 echo("<tr class=\"$parclass\" bgcolor=\"$parcolor\">".'<td>'.$index.'</td><td>');
124 echo('<a href="?download&song='.rawurlencode($temp).'">P</a>');
126 echo('/<a href="?dir='.
127 substr(str_replace(array('&','%2F'), array('%26','/'), (rawurlencode(dirname($dir.$item)))), strlen($GLOBALS['music_dir'])).
130 if(is_file($GLOBALS['flash_player']) && eregi(('\.('.$GLOBALS['m3u_exts'].')$'), $item)) {
131 /*echo('/<object type="application/x-shockwave-flash" width=17 height=17 data="'.
132 $GLOBALS['flash_player'].'?song_url='.rawurlencode($temp).'"></object>');*/
133 echo('/<a href="'.$GLOBALS['flash_player'].'?autoplay=true&song_url='.rawurlencode($temp).'" target="playframe">F</a>/'.
134 '<a href="about:blank" target="playframe">S</a>');
136 echo(' </td><td><a href="'.$temp.'">'.str_replace('_', ' ', $item).'</a></td><td>'.$filesize." MiB </td></tr>\n");
139 function unxss($string) {
141 array('&', '"', '\'', '<', '>'),
142 array('&', '"', ''', '<', '>'),
147 if(isset($_GET['download'])) serve_download($playlist_name);
148 if(isset($_GET['song'])) die($_GET['song']."\r\n");
150 if($_POST['cache-refresh'] == $cache_passwd) {
151 generate_search_cache($music_dir, $search_cache);
155 if(isset($_GET['playlist'])) {
156 if(!isset($_GET['search'])) {
157 generate_m3u($dir, dirname($music_dir_url), isset($_GET['recursive']));
159 if(!($searchfp = fopen($search_cache, 'r')))
160 die("Cannot read cache from $outfile<br />Refresh cache or set permissions properly!<br />\n");
161 while(!feof($searchfp)) {
162 $line = trim(fgets($searchfp));
163 if(@eregi
(str_replace(' ', '(.*)', $_GET['search']), $line))
164 echo(dirname($music_dir_url).'/'.str_replace('%2F', '/', (rawurlencode($line)))."\r\n");
170 if(isset($_GET['random'])) {
172 if(!($searchfp = fopen($search_cache, 'r')))
173 die("Cannot read cache from $outfile<br />Refresh cache or set permissions properly!<br />\n");
174 while(!feof($searchfp)) { fgets($searchfp); $flen++
; }
175 for($i=0; $i<$_GET['random']; $i++
) {
177 for($j=0; $j<rand(0, $flen-1); $j++
) fgets($searchfp);
178 echo(dirname($music_dir_url).'/'.str_replace('%2F', '/', (rawurlencode(trim(fgets($searchfp)))))."\r\n");
184 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
185 <link rel
="stylesheet" type
="text/css" href
="<?=$css_file?>">
187 <div align
="right" style
="position: absolute; top: 0; right: 0;">
188 <iframe src
="about:blank" name
="playframe" width
="0" height
="0" style
="border: none;"></iframe
>
189 <
; <a href
="javascript: history.go(-1)">BACK
</a
> |
<a href
="?">HOME (<?
=$music_dir?
>)</a
> |
<a href
="?help">ABOUT
/HELP
</a
> |
<a href
="?logout">LOGOUT
</a
>
193 if(isset($_GET['help'])) {
194 ?
><h1
>About
/Help
</h1
><?php
195 readfile($bonus_dir.'/help.html');
199 if(!isset($_GET['search'])) {
200 echo('<title>'.$title.': '.$dir.'</title>');
201 echo('<a href="?" style="color: black;"><h1>'.$title.'</h1></a><h2>Index of: '.$dir.'</h2>');
203 echo('<title>'.$title.': '.unxss($_GET['search']).'</title>');
204 echo('<a href="?" style="color: black;"><h1>'.$title.'</h1></a><h2>Searching for: '.unxss($_GET['search']).'</h2>');
210 <form action
="?" method
="GET" align
="right" style
="display: inline;">
211 <input type
="hidden" name
="download" value
="" />
212 <input type
="text" name
="random" value
="<?=$default_random_count?>" />
213 <input type
="submit" value
="random" title
="Generate random music playlist..." />
215 <form action
="?" method
="GET" align
="right" style
="display: inline;">
216 <input type
="text" name
="search"
217 title
="Search in music/google/lyrics/mp3/youtube; Hint: You can use regular expressions in search query..."
218 value
="<?=unxss($_GET['search'])?>"
220 <input type
="submit" value
="search" title
="Search in this JuKe!Box..." />
224 if(isset($_GET['search'])) {
226 ?
><div align
="right">
227 <form action
="http://google.com/search" method
="GET" align
="right" style
="display: inline;">
228 <input type
="text" name
="q" value
="<?=unxss($_GET['search'])?>" />
229 <input type
="submit" value
="google" title
="Search on Google..." />
231 <form action
="http://www.elyricsworld.com/search.php?phrase=marley" method
="GET" align
="right" style
="display: inline;">
232 <input type
="text" name
="phrase" value
="<?=unxss($_GET['search'])?>" />
233 <input type
="submit" value
="lyrics" title
="Search for lyrics on internet..." />
235 <form action
="http://jyxo.cz/s" method
="GET" align
="right" style
="display: inline;">
236 <input type
="hidden" name
="d" value
="mm" />
237 <input type
="text" name
="q" value
="<?=unxss($_GET['search'])?>" />
238 <input type
="submit" value
="jyxo multimedia" title
="Search media on internet..." />
240 <form action
="http://youtube.com/results" method
="GET" align
="right" style
="display: inline;">
241 <input type
="text" name
="search_query" value
="<?=unxss($_GET['search'])?>" />
242 <input type
="submit" value
="youtube" title
="Search on YOUTube..." />
246 <form action
="?" method
="POST" align
="right">
247 <input type
="password" name
="cache-refresh" value
="" title
="Password for refreshing - good for avoiding DoS Attacks!!!" />
248 <input type
="submit" value
="refresh cache" title
="You should refresh cache each time when you add new music or upgrade to newer version of JuKe!Box !!!" />
251 echo('Search DB size: '.(filesize($search_cache)/1024)." kB<br />\n");
253 if(!($searchfp = fopen($search_cache, 'r')))
254 die("Cannot read cache from $outfile<br />Refresh cache or set permissions properly!<br />\n");
257 echo('<table border="1" width="100%">');
258 echo('<tr><td>S</td><td><a href="?download&playlist&search='.unxss($_GET['search']).'">P</a></td><td colspan="100%">Search: '.unxss($_GET['search']).'</td></tr>');
259 while(!feof($searchfp)) {
260 $line = trim(fgets($searchfp));
261 $parclass=($i%2?
"even":"odd"); $parcolor=($i%2?
"lightblue":"white");
262 if(@eregi
(str_replace(' ', '(.*)', $_GET['search']), $line)) {
264 echo("<tr class=\"$parclass\" bgcolor=\"$parcolor\">");
265 $filesize = 0; if($i <= $access_limit) $filesize = filesize($line); else $filesize = 'n/a';
266 render_file_line('', $line, $music_dir_url, $i, $filesize, true);
270 echo("</table>Total: $i results...<br />");
274 @readfile
($header_file);
275 foreach($indexlist as $index) @readfile
($dir.$index);
278 <table border
="1" width
="100%">
280 <td
><b
><a href
="?download&playlist&dir=<?=str_replace('%2F', '/', rawurlencode($current_dir))?>">P
</a
>/<a
281 href
="?download&recursive&playlist&dir=<?=str_replace('%2F', '/', rawurlencode($current_dir))?>">R
</a
></b
></td
>
282 <td colspan
="100%"><?
=$dir?
></td
></tr
>
283 <tr
><td
>^
</td
><td
> 
;</td
><td colspan
="100%">[DIR
] <a href
="?dir=<?=rawurlencode($parent_dir)?>">.. (<?
=$parent_dir?
>)</a
></td
></tr
>
288 for($s=2;$s;$s--) { while(($item = readdir($dd)) != false) {
289 if($item == '.' ||
$item == '..') continue;
290 if(($s==2 && is_file($dir.$item)) ||
($s!=2 && is_dir($dir.$item))) continue;
292 $parclass=($i%2?
"even":"odd"); $parcolor=($i%2?
"lightblue":"white");
293 if(is_file($dir.$item)) {
298 render_file_line($dir, $item, $music_dir_url, $i, filesize($dir.$item));
301 if(is_dir($dir.$item)) {
302 $temp=str_replace('%2F', '/', rawurlencode($current_dir)).rawurlencode($item);
303 echo("<tr class=\"$parclass\" bgcolor=\"$parcolor\">".
304 '<td>'.$i.'</td><td><a href="?download&playlist&dir='.$temp.'">P</a>/'.
305 '<a href="?download&recursive&playlist&dir='.$temp.'">R</a></td>'.
306 '<td colspan="100%">[DIR] <a href="?dir='.$temp.'">'.str_replace('_', ' ', $item)."</a></td></tr>\n");
311 foreach($items as $item) {
313 render_file_line($dir, $item, $music_dir_url, $i, filesize($dir.$item));
321 'This is NOT advertisments. This is just good text to think about... Remove it if you want!',
322 'Downloading without sharing and other forms of leeching equals STEALING! ;P',
323 'Do NOT support Microsoft!!! Use Linux! ;D',
324 'Don\'t steal! Steal and share!!! ;P',
325 'Linux is not matter of price, it\'s matter of freedom!',
326 'This software brought to you by <a href="http://blog.Harvie.cz">Harvie</a> free of charge! Of course...',
327 'Don\'t be looser, use GNU/Linux! ;P',
328 'Make love and not war!',
329 'Take your chance! Prove yourself!',
330 'This software is free of charge. If you wan\'t to donate, please send some money to children in Africa/etc...'
333 echo('<i>'.$quotes[rand(0,sizeof($quotes)-1)]."</i>\n");
334 @readfile
($footer_file);
This page took 0.602062 seconds and 4 git commands to generate.