Location: PHPKode > scripts > class_playlist > class_playlist/playlist.php
<?
     /**
      * this script allow browsing hard drive from mp3 and create playlist with result
      *
      * args:  path to mp3
      * for better results: this script is a test script, just for
      * showing how works class_playlist.php
      * you need to use this script to have sort your mp3 in the following way:
      * path parameters => bandname => albumname
      *
      * this script will:
      * - test paramters
      * - delete all playlist in $config['file']['playlistfile'] folders
      * - browser path paramters and get list of mp3
      * - create playlist for each path
      *
      * warning : if you have more than 300 subfolders, you can exceed the
      * max_execution time parameters
      * increase this value if you have a max_execution_time error
      *
      * for bugs, hide@address.com (remove the -no_spam)
      *
      * this product is under GPL licence, please see copy of this licence for
      * furthers details
      *
      * latest version at http://www.phpclasses.org/browse.html/package/1228.html
      */
      @set_time_limit(0);
     require_once "class_log.php";
     require_once "class_dir.php";
     require_once "class_playlist.php";

     // config arrays
     $config['parameters'] = "syntax : PHP_SELF path/to/mp3 \n";
     $config['file']['playlistfiles'] = array('b4s','pls','m3u');
     $config['file']['savepath'] = substr($argv[1],0,3).'playlists';
     $config['file']['log'] = 'C:\temp\playlist.log';

     //------------------
     // checks parameters
     //------------------
   if (count($argv) == 0){
        echo "You have pass any arguments\n";
        echo $config['parameters'];
        exit(1);
   }
   if (count($argv) != 2){
        echo $config['parameters'];
        exit(2);
   }
   
   $sRoot_path = $argv[1];

   // verifie que le dossier existe bien
   if (!is_dir($sRoot_path)){
      echo $sRoot_path[0]."isn't a valid folder \n";
      echo $config['parameters'];
      exit(3);
   }

   //------------------
   // create log file
   //------------------
   $log = new log($config['file']['log'],"w");
   if ($log->GET_errors_size()){
        foreach($log->GET_errors() as $key => $error) echo "error # [".$key."] => [".$error."] \r\n";
        return;
   }
   
   $aLog =  array();
   //--------------------------------------
   // Delete folders where are the playlist
   //--------------------------------------

   $dir_playlist = new dir($config['file']['savepath']);
   if ($dir_playlist->DATA_errors_size()>0){
      $log->WRITE($dir_playlist->DATA_errors());
      return;
   }
   $aFile_playlist = $dir_playlist->LIST_get(FALSE,$config['file']['playlistfiles']);
   foreach($aFile_playlist as $id => $sPath){
      if (!@unlink($sPath)) $aLog[] = "DELETE : unable to delete [".$sPath."]";
      else $aLog[] = "DELETE : delete [".$sPath."] succefully";
   }

   //----------------------------------------------
   // get the list of folders in the source folders
   //----------------------------------------------
   $directory = new dir($sRoot_path);
   if ($directory->DATA_errors_size()){
      $log->WRITE($dir_playlist->DATA_errors());
      return;
   }

   $aBand = $directory->LIST_directories();
   // foreach Band Name
   foreach($aBand as $key => $sFolder){
                  // get all the album name
                  $dir_band = new dir($sFolder);
                  if ($dir_band->DATA_errors_size()) $log->WRITE($dir_band->DATA_errors());
                  else{
                    $aAlbums =  $dir_band->LIST_directories();
                    // foreach album name
                    foreach($aAlbums as $key_album => $sPath_album){
                       // create playlist for the album name
                       $aSubdirs = explode($dir_band->cSep,$sPath_album);
                       $aBandname = $aSubdirs[(count($aSubdirs)-2)];
                       $aAlbumname = $aSubdirs[(count($aSubdirs)-1)];
                       $playlist = new playlist($sPath_album,$aBandname,$config['file']['savepath'].$dir_band->cSep.$aBandname."-".$aAlbumname.".b4s",array('mp3','wma'));
                       if ($playlist->DATA_error_size()) $aLog = array_merge($aLog,$playlist->DATA_error());
                       $aLog = array_merge($aLog,$playlist->DATA_log());
                    }//foreach
                  }//else
                  unset($dir_band);
   }//foreach

   //----------------
   // write log datas
   //----------------
   $log->WRITE($aLog);
   if ($log->GET_errors_size()) print_r($log->GET_errors());
?>
Return current item: class_playlist