Skip to content

Commit

Permalink
Refactor embed player detection
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodytrash committed Oct 20, 2021
1 parent acc113a commit 0d63cae
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions dist/Simple-YouTube-Age-Restriction-Bypass.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
const VIDEO_PROXY_SERVER_HOST = "https://phx.4everproxy.com";

const isDesktop = window.location.host !== "m.youtube.com";
const isEmbed = window.location.pathname.includes("/embed/");

class Deferred {
constructor() {
Expand Down Expand Up @@ -297,8 +298,9 @@
if (playabilityStatus.desktopLegacyAgeGateReason) return true;
if (UNLOCKABLE_PLAYER_STATES.includes(playabilityStatus.status)) return true;

// Fix for embed player, see https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass/issues/85#issuecomment-946853553
return location.href.includes("/embed/") && ((_playabilityStatus$er = playabilityStatus.errorScreen) === null || _playabilityStatus$er === void 0 ? void 0 : (_playabilityStatus$er2 = _playabilityStatus$er.playerErrorMessageRenderer) === null || _playabilityStatus$er2 === void 0 ? void 0 : (_playabilityStatus$er3 = _playabilityStatus$er2.reason) === null || _playabilityStatus$er3 === void 0 ? void 0 : (_playabilityStatus$er4 = _playabilityStatus$er3.runs) === null || _playabilityStatus$er4 === void 0 ? void 0 : (_playabilityStatus$er5 = _playabilityStatus$er4.
// Fix to detect age restrictions on embed player
// see https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass/issues/85#issuecomment-946853553
return isEmbed && ((_playabilityStatus$er = playabilityStatus.errorScreen) === null || _playabilityStatus$er === void 0 ? void 0 : (_playabilityStatus$er2 = _playabilityStatus$er.playerErrorMessageRenderer) === null || _playabilityStatus$er2 === void 0 ? void 0 : (_playabilityStatus$er3 = _playabilityStatus$er2.reason) === null || _playabilityStatus$er3 === void 0 ? void 0 : (_playabilityStatus$er4 = _playabilityStatus$er3.runs) === null || _playabilityStatus$er4 === void 0 ? void 0 : (_playabilityStatus$er5 = _playabilityStatus$er4.
find((x) => x.navigationEndpoint)) === null || _playabilityStatus$er5 === void 0 ? void 0 : (_playabilityStatus$er6 = _playabilityStatus$er5.navigationEndpoint) === null || _playabilityStatus$er6 === void 0 ? void 0 : (_playabilityStatus$er7 = _playabilityStatus$er6.urlEndpoint) === null || _playabilityStatus$er7 === void 0 ? void 0 : (_playabilityStatus$er8 = _playabilityStatus$er7.url) === null || _playabilityStatus$er8 === void 0 ? void 0 : _playabilityStatus$er8.includes("/2802167"));
}

Expand Down Expand Up @@ -457,7 +459,7 @@
clientName: getMainPageClientName(),
clientVersion: getYtcfgValue('INNERTUBE_CLIENT_VERSION'),
signatureTimestamp: getSignatureTimestamp(),
isEmbed: +location.pathname.includes("/embed/") }).
isEmbed: +isEmbed }).
toString();

const proxyUrl = ACCOUNT_PROXY_SERVER_HOST + '/getPlayer?' + queryParams;
Expand Down
7 changes: 4 additions & 3 deletions src/components/inspector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isDesktop } from "../utils";
import { isDesktop, isEmbed } from "../utils";
import * as Config from "../config"

export function isPlayerObject(parsedData) {
Expand All @@ -14,8 +14,9 @@ export function isAgeRestricted(playabilityStatus) {
if (playabilityStatus.desktopLegacyAgeGateReason) return true;
if (Config.UNLOCKABLE_PLAYER_STATES.includes(playabilityStatus.status)) return true;

// Fix for embed player, see https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass/issues/85#issuecomment-946853553
return location.href.includes("/embed/") && playabilityStatus.errorScreen?.playerErrorMessageRenderer?.reason?.runs
// Fix to detect age restrictions on embed player
// see https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass/issues/85#issuecomment-946853553
return isEmbed && playabilityStatus.errorScreen?.playerErrorMessageRenderer?.reason?.runs
?.find(x => x.navigationEndpoint)?.navigationEndpoint?.urlEndpoint?.url?.includes("/2802167");
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/proxy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isEmbed } from "../utils";
import { nativeJSONParse } from "../utils/natives";
import * as innertube from "./innertubeClient";
import * as Config from "../config";
Expand All @@ -13,7 +14,7 @@ export function getPlayer(videoId, reason) {
clientName: innertube.getMainPageClientName(),
clientVersion: innertube.getYtcfgValue('INNERTUBE_CLIENT_VERSION'),
signatureTimestamp: innertube.getSignatureTimestamp(),
isEmbed: +location.pathname.includes("/embed/")
isEmbed: +isEmbed
}).toString();

const proxyUrl = Config.ACCOUNT_PROXY_SERVER_HOST + '/getPlayer?' + queryParams;
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const isDesktop = window.location.host !== "m.youtube.com";
export const isEmbed = window.location.pathname.includes("/embed/");

export class Deferred {
constructor() {
Expand Down

0 comments on commit 0d63cae

Please sign in to comment.