diff --git a/lib/info.js b/lib/info.js index 8e1ddaaf..fe7d4a48 100644 --- a/lib/info.js +++ b/lib/info.js @@ -84,7 +84,7 @@ exports.getBasicInfo = async(id, options) => { // and requires an account logged in to view, try the embed page. let embedUrl = `${EMBED_URL + id}?${params}`; body = await miniget(embedUrl, options.requestOptions).text(); - let jsonStr = util.between(body, '\'PLAYER_CONFIG\': ', ''); + let jsonStr = util.between(body, /['"]PLAYER_CONFIG['"]:\s?/, ''); let config; if (!jsonStr) { throw Error('Could not find player config'); diff --git a/lib/util.js b/lib/util.js index 95f6aaec..1dccd06c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -217,9 +217,17 @@ exports.filterFormats = (formats, filter) => { * @returns {string} */ exports.between = (haystack, left, right) => { - let pos = haystack.indexOf(left); - if (pos === -1) { return ''; } - haystack = haystack.slice(pos + left.length); + let pos; + if (left instanceof RegExp) { + const match = haystack.match(left); + if (!match) { return ''; } + pos = match.index + match[0].length; + } else { + pos = haystack.indexOf(left); + if (pos === -1) { return ''; } + pos += left.length; + } + haystack = haystack.slice(pos); pos = haystack.indexOf(right); if (pos === -1) { return ''; } haystack = haystack.slice(0, pos);