Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameters to get_video_info endpoint to fix 404 errors #938

Merged
merged 6 commits into from
Jun 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/info-extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,9 @@ exports.cleanVideoDetails = (videoDetails, info) => {

// Use more reliable `lengthSeconds` from `playerMicroformatRenderer`.
videoDetails.lengthSeconds =
info.player_response.microformat &&
info.player_response.microformat.playerMicroformatRenderer.lengthSeconds;
(info.player_response.microformat &&
info.player_response.microformat.playerMicroformatRenderer.lengthSeconds) ||
info.player_response.videoDetails.lengthSeconds;
return videoDetails;
};

Expand Down
7 changes: 6 additions & 1 deletion lib/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const BASE_URL = 'https://www.youtube.com/watch?v=';
exports.cache = new Cache();
exports.cookieCache = new Cache(1000 * 60 * 60 * 24);
exports.watchPageCache = new Cache();
// Cache for cver used in getVideoInfoPage
let cver = '2.20210622.10.00';


// Special error class used to determine if an error is unrecoverable,
Expand Down Expand Up @@ -273,7 +275,7 @@ const getWatchJSONPage = async(id, options) => {
let cookie = reqOptions.headers.Cookie || reqOptions.headers.cookie;
reqOptions.headers = Object.assign({
'x-youtube-client-name': '1',
'x-youtube-client-version': '2.20201203.06.00',
'x-youtube-client-version': cver,
'x-youtube-identity-token': exports.cookieCache.get(cookie || 'browser') || '',
}, reqOptions.headers);

Expand Down Expand Up @@ -307,6 +309,7 @@ const getWatchHTMLPage = async(id, options) => {
let body = await getWatchHTMLPageBody(id, options);
let info = { page: 'watch' };
try {
cver = utils.between(body, '{"key":"cver","value":"', '"}');
info.player_response = findJSON('watch.html', 'player_response',
body, /\bytInitialPlayerResponse\s*=\s*\{/i, '\n', '{');
} catch (err) {
Expand All @@ -325,6 +328,8 @@ const VIDEO_EURL = 'https://youtube.googleapis.com/v/';
const getVideoInfoPage = async(id, options) => {
const url = new URL(`https://${INFO_HOST}${INFO_PATH}`);
url.searchParams.set('video_id', id);
url.searchParams.set('c', 'TVHTML5');
url.searchParams.set('cver', `7${cver.substr(1)}`);
url.searchParams.set('eurl', VIDEO_EURL + id);
url.searchParams.set('ps', 'default');
url.searchParams.set('gl', 'US');
Expand Down