Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
skick1234 committed Aug 5, 2024
1 parent 9117764 commit 3aecec8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 330 deletions.
4 changes: 1 addition & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const getInfo = require('./info');
const utils = require('./utils');
const formatUtils = require('./format-utils');
const urlUtils = require('./url-utils');
const sig = require('./sig');
const miniget = require('miniget');
const m3u8stream = require('m3u8stream');
const { parseTimestamp } = require('m3u8stream');
Expand Down Expand Up @@ -35,7 +34,6 @@ ytdl.getVideoID = urlUtils.getVideoID;
ytdl.createAgent = agent.createAgent;
ytdl.createProxyAgent = agent.createProxyAgent;
ytdl.cache = {
sig: sig.cache,
info: getInfo.cache,
watch: getInfo.watchPageCache,
};
Expand Down Expand Up @@ -72,7 +70,7 @@ const pipeAndSetEvents = (req, stream, end) => {
const downloadFromInfoCallback = (stream, info, options) => {
options = options || {};

let err = utils.playError(info.player_response, ['UNPLAYABLE', 'LIVE_STREAM_OFFLINE', 'LOGIN_REQUIRED']);
let err = utils.playError(info.player_response);
if (err) {
stream.emit('error', err);
return;
Expand Down
42 changes: 5 additions & 37 deletions lib/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const { setTimeout } = require('timers');
const formatUtils = require('./format-utils');
const urlUtils = require('./url-utils');
const extras = require('./info-extras');
// TODO: Sig is currently broken.
// const sig = require('./sig');
const Cache = require('./cache');
const { defaultAgent } = require('./agent');

Expand All @@ -19,13 +17,6 @@ const BASE_URL = 'https://www.youtube.com/watch?v=';
exports.cache = new Cache();
exports.watchPageCache = new Cache();


// Special error class used to determine if an error is unrecoverable,
// as in, ytdl-core should not try again to fetch the video metadata.
// In this case, the video is usually unavailable in some way.
class UnrecoverableError extends Error {}


// List of URLs that show up in `notice_url` for age restricted videos.
const AGE_RESTRICTED_URLS = [
'support.google.com/youtube/?p=age_restrictions',
Expand All @@ -52,10 +43,8 @@ exports.getBasicInfo = async(id, options) => {
options.requestOptions.dispatcher = dispatcher;
const info = await retryFunc(getWatchHTMLPage, [id, options], retryOptions);

const playErr = utils.playError(info.player_response, ['ERROR'], UnrecoverableError);
const playErr = utils.playError(info.player_response);
if (playErr) throw playErr;
const privateErr = privateVideoError(info.player_response);
if (privateErr) throw privateErr;


Object.assign(info, {
Expand Down Expand Up @@ -88,21 +77,6 @@ exports.getBasicInfo = async(id, options) => {
return info;
};

const privateVideoError = player_response => {
const playability = player_response && player_response.playabilityStatus;
if (!playability) return null;
if (playability.status === 'LOGIN_REQUIRED') {
return new UnrecoverableError(playability.reason || (playability.messages && playability.messages[0]));
}
if (playability.status === 'LIVE_STREAM_OFFLINE') {
return new UnrecoverableError(playability.reason || 'The live stream is offline.');
}
if (playability.status === 'UNPLAYABLE') {
return new UnrecoverableError(playability.reason || 'This video is unavailable.');
}
return null;
};

const getWatchHTMLURL = (id, options) =>
`${BASE_URL + id}&hl=${options.lang || 'en'}&bpctr=${Math.ceil(Date.now() / 1000)}&has_verified=1`;
const getWatchHTMLPageBody = (id, options) => {
Expand Down Expand Up @@ -245,6 +219,9 @@ const parseFormats = player_response => {
exports.getInfo = async(id, options) => {
const info = await exports.getBasicInfo(id, options);
const iosPlayerResponse = await fetchIosJsonPlayer(id, options);
const playErr = utils.playError(iosPlayerResponse);
if (playErr) throw playErr;

info.formats = parseFormats(iosPlayerResponse);
const hasManifest =
iosPlayerResponse && iosPlayerResponse.streamingData && (
Expand All @@ -253,14 +230,6 @@ exports.getInfo = async(id, options) => {
);
let funcs = [];
if (info.formats.length) {
// Stream from ios player doesn't need to be deciphered.
// info.html5player = info.html5player ||
// getHTML5player(await getWatchHTMLPageBody(id, options)) || getHTML5player(await getEmbedPageBody(id, options));
// if (!info.html5player) {
// throw Error('Unable to find html5player file');
// }
// const html5player = new URL(info.html5player, BASE_URL).toString();
// funcs.push(sig.decipherFormats(info.formats, html5player, options));
funcs.push(info.formats);
}
if (hasManifest && iosPlayerResponse.streamingData.dashManifestUrl) {
Expand Down Expand Up @@ -290,10 +259,9 @@ const IOS_CLIENT_VERSION = '19.28.1',
IOS_OS_VERSION = '17.5.1.21F90';

const fetchIosJsonPlayer = async(videoId, options) => {
const cpn = utils.generateClientPlaybackNonce(16);
const payload = {
videoId,
cpn,
cpn: utils.generateClientPlaybackNonce(16),
contentCheckOk: true,
racyCheckOk: true,
context: {
Expand Down
Loading

2 comments on commit 3aecec8

@martinbrennan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello
What has happened to sig.js?
Apologies for my ignorance but I used the recently updated sig.js in my project to fix recent changes at Youtube so I was happy with it.
Is it not a necessary part of your code?
If not can you suggest where I should look to find updates to these algorithms in case of future changes at Youtube?
Martin

@luthfipun
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that by using an iOS/Android player user-agent, decipher is no longer required. However, in some cases and for other reasons, I still use the user client user-agent.

Therefore, I hope that the sig.js/decipher will continue to be updated as an alternative when using other user-agents

Thank you

Please sign in to comment.