<?PHP
 
/*******************************************************************************
 
  * PHP-Script:
 
  *
 
  * Example for hn_parseplaylist.class.php
 
  *
 
  * Parses Playlists of type 'extended m3u' and 'pls version 2'
 
  * and converts between that types (and also 'simple m3u')
 
  *
 
  * For latest version of classfile go to:
 
  * - http://hn273.users.phpclasses.org/browse/author/45770.html
 
  * and select the desired classpage, or go directly to:
 
  * - http://hn273.users.phpclasses.org/browse/package/2048.html
 
  *
 
  ******************************************************************************
 
  *
 
  * @Author:    Horst Nogajski <[email protected]>
 
  * @Copyright: (c) 1999 - 2005
 
  * @Licence:   GNU GPL (http://www.opensource.org/licenses/gpl-license.html)
 
  * @Version:   1.0
 
  *
 
  * $Id: hn_parseplaylist.example1.php,v 1.3 2005/01/05 22:08:21 horst Exp $
 
  *
 
  * Tabsize: 4
 
  *
 
  **/
 
 
 
    // please, ensure that we can include the class-file:
 
    require_once('hn_parseplaylist.class.php');
 
 
 
    // ensure that the example-playlistfile exists and is_readable
 
    $samplefile = 'hn_sampleplaylist.m3u';
 
    if(!file_exists($samplefile))
 
    {
 
        die('Cannot find hn_sampleplaylist.m3u!');
 
    }
 
 
    // ensure that we have read- and write-access to the current directory
 
    $testfilename = 'ichbineinetestdatei.txt';
 
    if(!touch($testfilename))
 
    {
 
        die('Have no write-access to ' . dirname(__FILE__));
 
    }
 
    if(file_exists($testfilename) && !unlink($testfilename))
 
    {
 
        die('Have no write-access to ' . dirname(__FILE__));
 
    }
 
 
    // little function to display infos with respect to environment (web or commandline)
 
    function msg($s)
 
    {
 
        echo isset($_SERVER['HTTP_HOST']) ? str_replace(array(' ',"\n"),array(' ',"<br>\n"),$s) : $s;
 
    }
 
 
 
 
    // OK! Here we go:
 
    msg("\nPHP-Class hn_ParsePlaylist :: examplefile\n");
 
    msg("\nOK! Here we go:\n");
 
    $ppl =& new hn_ParsePlaylist();
 
 
    // parse file
 
    msg("\n - parse sample-playlist-file");
 
    if(!$ppl->parse_file($samplefile))
 
    {
 
        // No success, serve infos and end!
 
        msg("\nFAILURE: Cannot successful parse Playlistfile!\n");
 
        $ppl->summary();
 
        exit(1);
 
    }
 
 
    // success, serve infos
 
    $ppl->summary();
 
 
    // sort internal list
 
    msg("\n - sort internal list by type, title");
 
    $ppl->sortPlaylist(array('type','title'));
 
 
    // save all tracks as pls
 
    msg("\n - save all tracks as pls");
 
    $ppl->saveAs_pls('all_tracks.pls');
 
 
    // save only radio-streams as simple m3u
 
    msg("\n - save only radio-streams as simple m3u");
 
    $ppl->saveAs_simple_m3u('radio_streams.m3u','radio');
 
 
    // save only files as extended m3u
 
    msg("\n - save only files as extended m3u");
 
    $ppl->saveAs_m3u('only_files.m3u','file');
 
 
 
    // OK! Open the new playlistfiles in editor of your choice and look!
 
    $result1 = "\n\nOK!\nOpen the new playlistfiles in editor of your choice and look!";
 
    $result2 = " - <a target=\"_blank\" href=\"all_tracks.pls\">all_tracks.pls</a>\n";
 
    $result2 .= " - <a target=\"_blank\" href=\"radio_streams.m3u\">radio_streams.m3u</a>\n";
 
    $result2 .= " - <a target=\"_blank\" href=\"only_files.m3u\">only_files.m3u</a>\n";
 
    if(isset($_SERVER['HTTP_HOST']))
 
    {
 
        echo nl2br($result1);
 
        echo nl2br("\nor open them directly:\n");
 
        echo nl2br($result2);
 
        echo nl2br("\n - <a target=\"_blank\" href=\"$samplefile\">and our samplefile, where we started from!</a>\n");
 
    }
 
    else
 
    {
 
        msg(strip_tags($result1.$result2));
 
    }
 
 
?>
 
 |