Skip to content

Commit

Permalink
fix: use get_video_info endpoint if watch and embed pages fail
Browse files Browse the repository at this point in the history
fixes #735
  • Loading branch information
fent committed Oct 22, 2020
1 parent db7a7b7 commit e88537f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/info.js
Expand Up @@ -88,7 +88,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['"]:\s?/, '</script>');
let jsonStr = util.between(body, /(['"])PLAYER_(CONFIG|VARS)\1:\s?/, '</script>');
let config;
if (!jsonStr) {
throw Error('Could not find player config');
Expand All @@ -99,9 +99,12 @@ exports.getBasicInfo = async(id, options) => {
throw Error(`Error parsing config: ${err.message}`);
}
playErr = util.playError(info, 'LOGIN_REQUIRED');
if (!config.args.player_response && !config.args.embedded_player_response && playErr) {
if ((!config.args || (!config.args.player_response && !config.args.embedded_player_response)) &&
!config.embedded_player_response && playErr) {
throw playErr;
}
let html5playerRes = /<script\s+src="([^"]+)"\s+name="player_ias\/base"\s*>/.exec(body);
info.html5player = html5playerRes ? html5playerRes[1] : null;
info.player = config;
}
return gotConfig(id, options, info, body);
Expand Down Expand Up @@ -184,7 +187,7 @@ const gotConfig = async(id, options, info, body) => {
info.player_response.microformat.playerMicroformatRenderer,
info.player_response.videoDetails, additional);
info.related_videos = extras.getRelatedVideos(info);
info.html5player = info.player && info.player.assets && info.player.assets.js;
info.html5player = info.html5player || (info.player && info.player.assets && info.player.assets.js);

// TODO: Remove these warnings later and remove the properties.
// Remember to remove from typings too.
Expand Down

0 comments on commit e88537f

Please sign in to comment.