Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into update-packages
Browse files Browse the repository at this point in the history
  • Loading branch information
grqx committed Dec 26, 2024
2 parents 80fa62d + 76f7a08 commit e2504b3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 30 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ docker run --name bgutil-provider -d -p 4416:4416 brainicism/bgutil-ytdlp-pot-pr
**Native:**

```shell
# Replace 0.6.0 with the latest version or the one that matches the plugin
git clone --single-branch --branch 0.6.0 https://github.com/Brainicism/bgutil-ytdlp-pot-provider.git
# Replace 0.7.0 with the latest version or the one that matches the plugin
git clone --single-branch --branch 0.7.0 https://github.com/Brainicism/bgutil-ytdlp-pot-provider.git
cd bgutil-ytdlp-pot-provider/server/
yarn install --frozen-lockfile
npx tsc
Expand Down Expand Up @@ -80,8 +80,8 @@ node build/main.js
# on each yt-dlp invocation, clone/extract the source code into your home directory.
# Replace `~` with `%USERPROFILE%` if using Windows
cd ~
# Replace 0.6.0 with the latest version or the one that matches the plugin
git clone --single-branch --branch 0.6.0 https://github.com/Brainicism/bgutil-ytdlp-pot-provider.git
# Replace 0.7.0 with the latest version or the one that matches the plugin
git clone --single-branch --branch 0.7.0 https://github.com/Brainicism/bgutil-ytdlp-pot-provider.git
cd bgutil-ytdlp-pot-provider/server/
yarn install --frozen-lockfile
npx tsc
Expand Down
2 changes: 1 addition & 1 deletion plugin/yt_dlp_plugins/extractor/getpot_bgutil.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.6.1'
__version__ = '0.7.0'
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"name": "grqz"
}
],
"version": "0.6.1",
"version": "0.7.0",
"scripts": {
"lint": "npx eslint --max-warnings=0 src/",
"lint-fix": "npx eslint --fix --max-warnings=0 src/",
Expand Down
36 changes: 24 additions & 12 deletions server/src/generate_once.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,32 @@ const options = program.opts();
visitIdentifier = generatedVisitorData;
}

const sessionData = await sessionManager.generatePoToken(
visitIdentifier,
proxy,
);

try {
fs.writeFileSync(
CACHE_PATH,
JSON.stringify(sessionManager.getYoutubeSessionDataCaches(true)),
"utf8",
const sessionData = await sessionManager.generatePoToken(
visitIdentifier,
proxy,
);

try {
fs.writeFileSync(
CACHE_PATH,
JSON.stringify(
sessionManager.getYoutubeSessionDataCaches(true),
),
"utf8",
);
} catch (e) {
console.warn(
`Error writing cache. err.name = ${e.name}. err.message = ${e.message}. err.stack = ${e.stack}`,
);
} finally {
console.log(JSON.stringify(sessionData));
}
} catch (e) {
console.warn(`Error writing cache. e = ${e}`);
} finally {
console.log(JSON.stringify(sessionData));
console.error(
`Failed while generating POT. err.name = ${e.name}. err.message = ${e.message}. err.stack = ${e.stack}`,
);
console.log(JSON.stringify({}));
process.exit(1);
}
})();
24 changes: 16 additions & 8 deletions server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,22 @@ httpServer.post("/get_pot", async (request, response) => {
visitIdentifier = generatedVisitorData;
}

const sessionData = await sessionManager.generatePoToken(
visitIdentifier,
proxy,
);
response.send({
po_token: sessionData.poToken,
visit_identifier: sessionData.visitIdentifier,
});
try {
const sessionData = await sessionManager.generatePoToken(
visitIdentifier,
proxy,
);

response.send({
po_token: sessionData.poToken,
visit_identifier: sessionData.visitIdentifier,
});
} catch (e) {
console.error(
`Failed while generating POT. err.name = ${e.name}. err.message = ${e.message}. err.stack = ${e.stack}`,
);
response.status(500).send({ error: JSON.stringify(e) });
}
});

httpServer.post("/invalidate_caches", async (request, response) => {
Expand Down
14 changes: 10 additions & 4 deletions server/src/session_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ export class SessionManager {
fetch: async (url: any, options: any): Promise<any> => {
try {
const response = await axios.post(url, options.body, {
headers: options.headers,
headers: {
...options.headers,
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
},
httpsAgent: dispatcher,
});

Expand All @@ -177,13 +181,13 @@ export class SessionManager {
return response.data;
},
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return {
ok: false,
json: async () => {
return null;
},
status: e.response?.status || e.code,
};
}
},
Expand All @@ -197,7 +201,8 @@ export class SessionManager {
challenge = await BG.Challenge.create(bgConfig);
} catch (e) {
throw new Error(
`Error while attempting to retrieve BG challenge. err = ${e}`,
`Error while attempting to retrieve BG challenge. err = ${JSON.stringify(e)}`,
{ cause: e },
);
}
if (!challenge) throw new Error("Could not get Botguard challenge");
Expand All @@ -221,7 +226,8 @@ export class SessionManager {
poToken = poTokenResult.poToken;
} catch (e) {
throw new Error(
`Error while trying to generate PO token. e = ${e}`,
`Error while trying to generate PO token. err.name = ${e.name}. err.message = ${e.message}. err.stack = ${e.stack}`,
{ cause: e },
);
}

Expand Down

0 comments on commit e2504b3

Please sign in to comment.