Skip to content

Instantly share code, notes, and snippets.

@jcready
Last active December 10, 2015 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcready/4422076 to your computer and use it in GitHub Desktop.
Save jcready/4422076 to your computer and use it in GitHub Desktop.
function parsePls(pls) {
//get number of entries
var matched = pls.match(/numberofentries=\d+/i);
matched = matched[0].split("=");
var numberOfEntries = matched[1];
var i = 1;
var files = [], file, title, length;
while (i <= numberOfEntries) {
var fileRegex = new RegExp('File'+i+'=\\S+');
var titleRegex = new RegExp('Title'+i+'=(.)+');
var lengthRegex = new RegExp('Length'+i+'=\\S+');
//get stream URLs
file = pls.match(fileRegex)[0].split("=")[1];
title = pls.match(titleRegex)[0].split("=")[1];
length = pls.match(lengthRegex)[0].split("=")[1];
users = title.substring(1, title.indexOf(')')).replace(/^#\d\d?\s-\s/,'').split('/');
files.push({ 'file': file, 'title': title.substring(title.indexOf(')')+2, title.length), 'listeners': ~~users[0], 'limit': ~~users[1] });
i++;
}
return files;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment