playlists-0.2.0.0: Library and executable for working with playlist files.

Safe HaskellNone

Text.Playlist

Contents

Synopsis

Playlist Types

data Track Source

A single music file or streaming URL.

Constructors

Track 

Fields

trackURL :: Text

URL for a file or streaming resource.

trackTitle :: Maybe Text

Optional title.

Instances

type Playlist = [Track]Source

A list of Tracks.

Playlist Formats

Parsing and Generating

parsePlaylist :: Format -> ByteString -> Either String PlaylistSource

Parse a playlist from a ByteString. Parsing may fail in which case an error message is returned in Left.

 content <- BS.getContents
 case parsePlaylist M3U content of
  Left err -> fail $ "failed to parse playlist: " ++ err
  Right x  -> return x

generatePlaylist :: Format -> Playlist -> ByteStringSource

Generate a lazy ByteString containing playlist data from the given playlist and in the given format.

 BL.putStr $ generatePlaylist M3U somePlaylist

fileNameToFormat :: FilePath -> Maybe FormatSource

Try to figure out a file's format from it's file extension.

>>> fileNameToFormat "foo.m3u"
Just M3U
>>> fileNameToFormat "foo.txt"
Nothing

appendExtension :: Format -> FilePath -> FilePathSource

Given a file name that does not have a file extension, return a file name with the appropriate extension included based on the given format.

>>> appendExtension M3U "foo"
"foo.m3u"