Skip to content

Commit

Permalink
fix: use regex to extract player config from embed page (#725)
Browse files Browse the repository at this point in the history
* use regex to extract player config from embed page

* Remove console statement used for debugging
  • Loading branch information
WaqasIbrahim committed Oct 15, 2020
1 parent d2500af commit bcee0ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/info.js
Expand Up @@ -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\': ', '</script>');
let jsonStr = util.between(body, /['"]PLAYER_CONFIG['"]:\s?/, '</script>');
let config;
if (!jsonStr) {
throw Error('Could not find player config');
Expand Down
14 changes: 11 additions & 3 deletions lib/util.js
Expand Up @@ -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);
Expand Down

0 comments on commit bcee0ce

Please sign in to comment.