Skip to content

Commit

Permalink
[feat] Add option to skip content warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodytrash committed Jun 22, 2022
1 parent 2becc33 commit 3fd31ac
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/components/requestPreprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function handleXhrOpen(method, url, xhr) {
});
}

if (method === 'POST' && ['/youtubei/v1/player', '/youtubei/v1/next'].includes(url.pathname)) {
if (Config.SKIP_CONTENT_WARNINGS && method === 'POST' && ['/youtubei/v1/player', '/youtubei/v1/next'].includes(url.pathname)) {
// Add content check flags to player and next request (this will skip content warnings)
interceptors.attachGenericInterceptor(xhr, 'send', (args) => {
if (typeof args[0] === 'string') {
Expand Down Expand Up @@ -67,7 +67,7 @@ export function handleFetchRequest(url, requestOptions) {
}
}

if (['/youtubei/v1/player', '/youtubei/v1/next'].includes(url.pathname)) {
if (Config.SKIP_CONTENT_WARNINGS && ['/youtubei/v1/player', '/youtubei/v1/next'].includes(url.pathname)) {
// Add content check flags to player and next request (this will skip content warnings)
requestOptions.body = setContentCheckOk(requestOptions.body);
}
Expand Down
4 changes: 1 addition & 3 deletions src/components/strategies/player.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { innertube, proxy } from '../endpoints';
import { isEmbed, isConfirmed, getCurrentVideoStartTime, getYtcfgValue, getSignatureTimestamp } from '../../utils';

export default function getUnlockStrategies(originalPlayerResponse) {
const videoId = originalPlayerResponse.videoDetails?.videoId || getYtcfgValue('PLAYER_VARS').video_id;
const reason = originalPlayerResponse.playabilityStatus?.status || originalPlayerResponse.previewPlayabilityStatus?.status;
export default function getUnlockStrategies(videoId, reason) {
const clientName = getYtcfgValue('INNERTUBE_CLIENT_NAME') || 'WEB';
const clientVersion = getYtcfgValue('INNERTUBE_CLIENT_VERSION') || '2.20220203.04.00';
const signatureTimestamp = getSignatureTimestamp();
Expand Down
2 changes: 1 addition & 1 deletion src/components/unlocker/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as unlockPlayerResponse } from './player.js';
export { default as unlockNextResponse } from './next.js';

export { lastPlayerUnlockReason, getLastProxiedGoogleVideoId } from './player.js';
export { lastPlayerUnlockReason, lastPlayerUnlockVideoId, getLastProxiedGoogleVideoId } from './player.js';
22 changes: 15 additions & 7 deletions src/components/unlocker/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const messagesMap = {
fail: 'Unable to unlock this video 🙁 - More information in the developer console',
};

export let lastPlayerUnlockVideoId = null;
export let lastPlayerUnlockReason = null;

let lastProxiedGoogleVideoUrlParams;
Expand All @@ -27,7 +28,18 @@ export default function unlockResponse(playerResponse) {
return playerResponse;
}

const unlockedPlayerResponse = getUnlockedPlayerResponse(playerResponse);
const videoId = playerResponse.videoDetails?.videoId || getYtcfgValue('PLAYER_VARS').video_id;
const reason = playerResponse.playabilityStatus?.status || playerResponse.previewPlayabilityStatus?.status;

if (!Config.SKIP_CONTENT_WARNINGS && reason.includes('CHECK_REQUIRED')) {
logger.info(`SKIP_CONTENT_WARNINGS disabled and ${reason} status detected.`);
return playerResponse;
}

lastPlayerUnlockVideoId = videoId;
lastPlayerUnlockReason = reason;

const unlockedPlayerResponse = getUnlockedPlayerResponse(videoId, reason);

// account proxy error?
if (unlockedPlayerResponse.errorMessage) {
Expand Down Expand Up @@ -62,15 +74,11 @@ export default function unlockResponse(playerResponse) {
Toast.show(messagesMap.success);
}

function getUnlockedPlayerResponse(playerResponse) {
const videoId = playerResponse.videoDetails?.videoId || getYtcfgValue('PLAYER_VARS').video_id;

function getUnlockedPlayerResponse(videoId, reason) {
// Check if response is cached
if (cachedPlayerResponse.videoId === videoId) return createDeepCopy(cachedPlayerResponse);

lastPlayerUnlockReason = playerResponse.playabilityStatus?.status || playerResponse.previewPlayabilityStatus?.status;

const unlockStrategies = getPlayerUnlockStrategies(playerResponse);
const unlockStrategies = getPlayerUnlockStrategies(videoId, reason);

let unlockedPlayerResponse = {};

Expand Down
3 changes: 3 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export let ENABLE_UNLOCK_CONFIRMATION_EMBED = true;
// Show notification?
export let ENABLE_UNLOCK_NOTIFICATION = true;

// Disable content warnings?
export let SKIP_CONTENT_WARNINGS = false;

// Some Innertube bypass methods require the following authentication headers of the currently logged in user.
export const GOOGLE_AUTH_HEADER_NAMES = ['Authorization', 'X-Goog-AuthUser'];

Expand Down

0 comments on commit 3fd31ac

Please sign in to comment.