Safe Haskell | None |
---|---|
Language | Haskell98 |
- data Track = Track {
- trackURL :: Text
- trackTitle :: Maybe Text
- type Playlist = [Track]
- data Format
- parsePlaylist :: Format -> ByteString -> Either String Playlist
- generatePlaylist :: Format -> Playlist -> ByteString
- fileNameToFormat :: FilePath -> Maybe Format
- appendExtension :: Format -> FilePath -> FilePath
Playlist Types
A single music file or streaming URL.
Playlist Formats
Playlist formats.
Parsing and Generating
parsePlaylist :: Format -> ByteString -> Either String Playlist Source
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 -> ByteString Source
Generate a lazy ByteString
containing playlist data from the
given playlist and in the given format.
BL.putStr $ generatePlaylist M3U somePlaylist
fileNameToFormat :: FilePath -> Maybe Format Source
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 -> FilePath Source
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"