playlist
Parse playlist files
Install
In your mix.exs:
defp deps do
[
{:playlist, "~> 1.0.0"}
]
end
Then run mix deps.get.
Usage
This package can parse M3U and PLS files and exports two modules: Playlist.M3U and Playlist.PLS. Both of these export a parse/1 function, which takes a string representing a playlist file and returns a list of maps, each
representing a track in the file.
Example
Let's assume we have a M3U file that looks like this:
#EXTM3U
#EXTINF:822,A - Track 1
~/Music/1.mp3
#EXTINF:272,B - Track 2
mp3/b/2.ogg
#EXTINF:381,C - Track 3
http://coolmusic.com/12345.m4a
#EXTINF:249,D - Track 4
ws://nice.com/54321.aac
#EXTINF:249,E - Track 5
wss://192.168.1.1/llllllll.mp3We can parse it like this:
{:ok, file} = File.read("playlist.m3u")
{:ok, parsed} = Playlist.M3U.parse(file)parsed will look like this:
[
%{artist: "A ", file: "~/Music/1.mp3", length: "822", title: "Track 1"},
%{artist: "B ", file: "mp3/b/2.ogg", length: "272", title: "Track 2"},
%{artist: "C ", file: "http://coolmusic.com/12345.m4a", length: "381", title: "Track 3"},
%{artist: "D ", file: "ws://nice.com/54321.aac", length: "249", title: "Track 4"},
%{artist: "E ", file: "wss://192.168.1.1/llllllll.mp3", length: "249", title: "Track 5"}
]
Any error during the parsing will result in a {:error, reason} tuple.
License
MIT © Juan Soto