Skip to content

Commit

Permalink
fix: handle YT new signature decode. Fixed #25
Browse files Browse the repository at this point in the history
  • Loading branch information
dangdungcntt committed Oct 9, 2023
1 parent 1dc31e5 commit 94e1273
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,5 @@ fabric.properties
# End of https://www.gitignore.io/api/node,webstorm,visualstudiocode

.DS_Store
.parcel-cache
.parcel-cache
.vscode
10 changes: 7 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

44 changes: 24 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "youtube-stream-url",
"version": "2.4.1",
"version": "2.4.2",
"description": "Get stream url from youtube link",
"source": "src/index.js",
"main": "dist/index.js",
Expand Down Expand Up @@ -28,5 +28,8 @@
},
"devDependencies": {
"parcel": "^2.7.0"
},
"volta": {
"node": "18.18.0"
}
}
}
15 changes: 12 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,18 @@ const buildDecoder = async (watchHtml) => {
return null;
}

let varDeclaresMatches = jsFileContent.match(new RegExp(`(var ${varNameMatches[1]}={[\\s\\S]+}};)[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.prototype`));
let varStartIndex = jsFileContent.indexOf(`var ${varNameMatches[1]}={`);
if (varStartIndex < 0) {
return null;
}
let varEndIndex = jsFileContent.indexOf('}};', varStartIndex);
if (varEndIndex < 0) {
return null
}

let varDeclares = jsFileContent.substring(varStartIndex, varEndIndex + 3);

if (!varDeclaresMatches) {
if (!varDeclares) {
return null;
}

Expand All @@ -67,7 +76,7 @@ const buildDecoder = async (watchHtml) => {
let { s: signature, sp: signatureParam = 'signature', url } = Object.fromEntries(params);
let decodedSignature = new Function(`
"use strict";
${varDeclaresMatches[1]}
${varDeclares}
return (${decodeFunction})("${signature}");
`)();

Expand Down

0 comments on commit 94e1273

Please sign in to comment.