PHP-Class :: HN ParsePlaylist :: Documentation

Author:    Horst Nogajski
Licence:   GNU GPL (
Version:   1.0   (2005-01-06)

You can download the class at!

UP (to the list)

Parses Playlists (Audio)

Current Version 1.0 supports reading/writing from/to:
- extended m3u
- pls version 2
- simple m3u

If source is 'simple m3u', you only can save to simple m3u.
If source is 'extended m3u' or 'pls', you can save to any type.

Optionally the class can sort the list, see methods.

Class "hn_ParsePlaylist"


You can give a playlist to the class as file or string to parse it.
NOTE: if you use parse_string-method, the string must contain line-endings!
- parse_file($filename)
- parse_string($s)

After parsing, we can retrieve an array with information of the playlist and the parse-process, calling the method:
- summary($asArray=FALSE)
Without optional BOOLEAN argument all infos are displayed directly. This is meant for debugging.
Passing TRUE to the method will return the infos as array.

The following infos are available:
- 'file' holds the filename of the parsed file, or an empty string when work with parse_string()
- 'valid' is BOOLEAN TRUE if is a valid Playlist
- 'type' can be: extm3u, m3u, pls2
- 'count' is the number of tracks in list
- 'errors' best should be empty, ;-), but can contain warnings or error-messages if e.g. no valid playlist

If it is a valid playlist, now all available track-infos are stored in internal array $tracks:
- 'title' is the Tracktitle
- 'time' holds the tracklength in seconds
- 'path' contains the filepath or the stream-URL
- 'type' contains 'file' if track is a file, and 'radio' if it beginns with 'http://'

You can sort the internal playlist in hierarchic order of given $sortlistArray.
$sortlistArray can be every combination of fieldnames: 'type','path','title','time'
- sortPlaylist($sortlistArray)

There are three methods to save the internal playlist to a file.
- saveAs_m3u($filename, $onlyType='')
- saveAs_simple_m3u($filename, $onlyType='')
- saveAs_pls($filename, $onlyType='')
For all three methods you must specify a valid filename, which means: the script must have write-access to the directory/file and also you must take care to define the right filetype-extension, e.g. .m3u or .pls!
There can be passed an optional second argument $onlyType. It's value can be 'radio' or 'file'. This is used to only include tracks of the desired type into the new playlistfile.

Three other methods lets you retrieve the different plylist-types as string instead saving to a file.
- stringAs_m3u($onlyType='')
- stringAs_simple_m3u($onlyType='')
- stringAs_pls($onlyType='')
Here we have only one optional argument $onlyType. It behaves like with the saveAs_-file-methods.