vautinsh Posted April 5, 2010 Report Share Posted April 5, 2010 Sveiki, vai kāds varētu lūdzu pateikt kā izdarīt lai šis skripts lasītu tikai .mp3 failus ? <? /** * Produce an XPSF playlist on the fly from files in a given folder * * Code by Lewis Smith www.lasmit.com * Code released under GNU General Public Licence - http://www.gnu.org/licenses/gpl.html * * If you use this software and find it useful please drop me an email - lewis@lasmit.com * I'd like to build a list of people using the script which I'll publish on my site, so please do get in touch. * Code uses snippets from http://getid3.sourceforge.net/source2/demo.browse.dhtml.phps * Using getID3 library from http://getid3.sourceforge.net/ */ $base_url = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']); // Definitions define("ROOT", $_SERVER["HTTP_HOST"]); // This is your domain name, can probably be left define("PATH", $_SERVER["DOCUMENT_ROOT"]); // This is the full physical root to your folder, can probably be left define("MP3_PATH", "$base_url/uploads"); // This is the virtual path to the folder containing your MP3s, // e.g. if your files are at http://www.me.com/files/mp3s then this should // be set to files/mp3s require_once('getid3/getid3.php'); // Include the getId3 library // Create ID3 object $getid3 = new getID3; $getid3->encoding = 'UTF-8'; $dir = PATH . "/" . MP3_PATH; // Read directory if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { $full_name = "$dir/$file"; if (is_file($full_name)) { $files[$full_name] = $file; } elseif ($file[0] != '.') { $dir[$full_name] = $file; } } closedir($dh); } } // Produce output if ($files) { print <<< END_HEADER <?xml version="1.0" encoding="UTF-8"?> <playlist version="1" xmlns="http://xspf.org/ns/0/"> <!-- Playlist generated automatically using script from www.lasmit.com --> <trackList> END_HEADER; if ($_REQUEST['shuffle']=="true") { shuffle($files); } else { asort($files); } $counter = $i = 0; foreach ($files as $full_name => $short_name) { $getid3->Analyze($dir . "/" . $short_name); $artist = $title = ''; if (@$getid3->info['tags']) { foreach ($getid3->info['tags'] as $tag => $tag_info) { if (@$getid3->info['tags'][$tag]['title']) { $artist = @$getid3->info['tags'][$tag]['artist'][0]; $title = @$getid3->info['tags'][$tag]['title'][0]; $album = @$getid3->info['tags'][$tag]['album'][0]; break; } else { $title = basename($short_name, ".mp3"); } } } else { $title = basename($short_name, ".mp3"); } $url = ROOT . "/" . MP3_PATH . "/" . $short_name; if (strpos($url, "http://") === false) { $url = "http://" . $url; } $info = ROOT; if (strpos($info, "http://") === false) { $info = "http://" . $info; } print <<< END_TRACK <track> <location>{$url}</location> <!-- artist or band name --> <creator>{$artist}</creator> <!-- album name --> <album>{$album}</album> <!-- name of the song --> <title>{$title}</title> </track> END_TRACK; } print <<< END_FOOTER </trackList> </playlist> END_FOOTER; } ?> Quote Link to comment Share on other sites More sharing options...
lostz Posted April 5, 2010 Report Share Posted April 5, 2010 a vaitad viņš nelasa tikai .mp3 jau ? )) Quote Link to comment Share on other sites More sharing options...
vautinsh Posted April 6, 2010 Author Report Share Posted April 6, 2010 diemžēl nē :( Quote Link to comment Share on other sites More sharing options...
briedis Posted April 6, 2010 Report Share Posted April 6, 2010 Nez, tur kur atlasi/drukā, tur pārbaudi vai paplašinājums ir .mp3, ja ir, tad ok, ja nav, tad izlaid ciklu... Quote Link to comment Share on other sites More sharing options...
vautinsh Posted April 6, 2010 Author Report Share Posted April 6, 2010 Es nesapratu kā tu to domā, esmu iesācējs šitajās lietās! vari ludzu uzrakstit ka man jaraksta taja failaa... Quote Link to comment Share on other sites More sharing options...
kasisppr Posted April 7, 2010 Report Share Posted April 7, 2010 minūte ar Googles tanti un paprasot "PHP get file extension" un rezultāts rokā. Nu tad tālāk papildinām tajā sadaļā, kur nolasi filus no direktorijas ar attiecīgo kodu // Read directory if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { $full_name = "$dir/$file"; $ext = substr(strrchr(strtolower($file), '.'), 1); // dabujam paplashinajumu failam if (is_file($full_name) && $ext == "mp3") { $files[$full_name] = $file; } elseif ($file[0] != '.') { $dir[$full_name] = $file; } } closedir($dh); } } "Paldies" lūdzu pārskaitīt uz kontu. ;) Quote Link to comment Share on other sites More sharing options...
Roze Posted April 7, 2010 Report Share Posted April 7, 2010 Drošvien nepalīdz konkrētajā situācijā (iesācējam), bet ideja kapēc kaut kādu gatavu skriptu (it īpaši ja nav jausmas ko tie vispār dara) izmantošana ne vienmēr ir optimāla. Visa tā ķeska pāris rindās ( http://lv.php.net/glob ): <? foreach (glob("*.mp3") as $filename) { echo $filename."\n"; } ?> Quote Link to comment Share on other sites More sharing options...
vautinsh Posted April 8, 2010 Author Report Share Posted April 8, 2010 Liels, liels, liels paldies! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.