PHP Classes

File: usage/playlist.php

Recommend this page to a friend!
  Classes of MARY Matthieu   Audio_Playlist   usage/playlist.php   Download  
File: usage/playlist.php
Role: Example script
Content type: text/plain
Description: example for browsing folders and create playlist
Class: Audio_Playlist
Create play list files in multiple formats
Author: By
Last change:
Date: 16 years ago
Size: 4,349 bytes
 

Contents

Class file image Download
gothi<?php

/**
 * $Id: playlist.php 1631 2007-05-12 22:40:28Z matthieu $
 */
if (!defined('__CLASS_PATH__')) {
   
define('__CLASS_PATH__', realpath(dirname(__FILE__) . '/../'));
}
require_once
__CLASS_PATH__ . '/Autoload.php';
/**
 * @package playlist
 * 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, http://www.phplibrairies.com
 *
 * this product is under GPL licence, please see copy of this licence for
 * furthers details
 *
 * latest version at http://www.phplibrairies.com
 */
@ set_time_limit(0);
error_reporting(E_ALL);
// config arrays
$debug = Debug_Console :: getInstance();
define('__SYNTAX__', 'playlist.php /path/to/mp3/files /playlist/destination/folder');
define('__CONFIG_PLAYLIST_FILES__', 'pls:m3u:b4s');
define('__CONFIG_AUDIO_FILES__', 'mp3:mpc:wma');
define('__ERR_CODE_BAD_SYNTAX__', 1);
define('__ERR_CODE_BAD_SOURCE_FOLDER__', 3);
define('__ERR_CODE_BAD_DEST_FOLDER__', 4);

$config['file']['playlistfiles'] = explode(';', __CONFIG_PLAYLIST_FILES__);
//------------------
// checks parameters
//------------------
if ($_SERVER['argc'] != 3) {
   
$debug->showErrorMessage('Expecting at least the mp3 source folder and the destination folder');
   
$debug->showFatalMessage(__SYNTAX__, __ERR_CODE_BAD_SYNTAX__);
}
define('__PARAM_PLAYLIST_DESTINATION_FOLDER__', $_SERVER['argv'][2]);
define('__PARAM_MP3_ROOT_PATH__', $_SERVER['argv'][1]);

/**
 * Check that parameters paths are valid folders
 */
if (!is_dir(__PARAM_PLAYLIST_DESTINATION_FOLDER__)) {
   
$debug->showErrorMessage('Your playlist destination folder [' . __PARAM_PLAYLIST_DESTINATION_FOLDER__ . '] is not a valid folder');
   
$debug->showFatalMessage(__SYNTAX__, __ERR_CODE_BAD_DEST_FOLDER__);
}

if (!
is_dir(__PARAM_MP3_ROOT_PATH__)) {
   
$debug->showErrorMessage(__PARAM_MP3_ROOT_PATH__ . 'isn\'t a valid folder');
   
$debug->showFatalMessage(__SYNTAX__, __ERR_CODE_BAD_SOURCE_FOLDER__);
}
//--------------------------------------
// Delete folders where are the playlist
//--------------------------------------
$dir_playlist = new Files_DirectoryListing(__PARAM_PLAYLIST_DESTINATION_FOLDER__);
$aFile_playlist = $dir_playlist->LIST_files('--e ' . implode(',', explode(':', __CONFIG_PLAYLIST_FILES__)));

foreach (
$aFile_playlist as $id => $sPath) {
    (!@
unlink($sPath)) ? $debug->showWarningMessage('cannot delete [' . $sPath . ']') : $debug->showMessage("DELETE : clean [$sPath] succefully");
}
//----------------------------------------------
// get the list of folders in the source folders
//----------------------------------------------
$directory = new Files_DirectoryListing(__PARAM_MP3_ROOT_PATH__);
if (
$directory->DATA_errors_size()) {
   
$debug->showErrorMessage('wrong source folder');
}
$aBand = $directory->LIST_directories();
// foreach Band Name
foreach ($aBand as $key => $sFolder) {
   
// get all the album name
   
$dir_band = new Files_DirectoryListing($sFolder);
    if (!
$dir_band->DATA_errors_size()) {
       
$aAlbums = $dir_band->LIST_directories();
       
// foreach album name
       
foreach ($aAlbums as $key_album => $sPath_album) {
           
$debug->showDebugMessage("processing $sPath_album");
           
// create playlist for the album name
           
$aSubdirs = explode('/', $sPath_album);
           
$aBandname = $aSubdirs[(count($aSubdirs) - 2)];
           
$aAlbumname = $aSubdirs[(count($aSubdirs) - 1)];
            try {
               
$playlist = new Audio_Playlist($sPath_album, $aBandname, __PARAM_PLAYLIST_DESTINATION_FOLDER__ . '/' . $aBandname . "-" . $aAlbumname . ".m3u", explode(':', __CONFIG_AUDIO_FILES__));
            }
            catch (
Audio_Playlist_Exception $e) {
                echo
$e;
            }
        }
//foreach
   
} //else
   
unset ($dir_band);
}
//foreach
?>