Parse m3u, m3u extended, and pls
window.ASX.parse which take a
string and return a possibly empty array of objects.
// Fetch the playlist file, using xhr for examplevar xhr = ;xhropen"GET" "my_playlist.m3u";xhroverrideMimeType"audio/x-mpegurl"; // Needed, see below.xhronload = parse;xhrsend;// Parse itvar playlist = M3Uparsethisresponse;var audio = ;nextaudio playlist 0;;// Play each song after a song finishesif i < playlistlengthaudiosrc = playlisti++file;audioonended = nextbindnull audio playlist i;audioplay;;
which take a string and return
a possibly empty array of objects.
npm install playlist-parser
var parsers = require"playlist-parser";var M3U = parsersM3U;var fs = require"fs";var playlist = M3UparsefsreadFileSync"my_playlist.m3u" encoding: "utf8" ;
Calls to parse return an array of objects that look like:
length: 1234artist: "Iron Maiden"title: "Rime of the Ancient Mariner"file: ""
file: ""title: "My favorite song ever by my favorite artist"length: 1234
This software is dual licensed under the MIT and Beerware license.
The MIT License (MIT)
Copyright (c) 2013 Nick Desaulniers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"THE BEER-WARE LICENSE" (Revision 42): email@example.com wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return. Nick Desaulniers