Now downloads are possible

This commit is contained in:
LuanRT
2021-09-30 19:22:28 -03:00
parent f173064eb9
commit 18bab48c7d
6 changed files with 320 additions and 320 deletions

View File

@@ -9,31 +9,31 @@ class Player {
constructor(innertube_session) {
this.session = innertube_session;
this.player_name = Utils.getStringBetweenStrings(this.session.player_url, '/player/', '/');
this.tmp_cache_dir = __dirname.slice(0, -3)+'cache';
this.tmp_cache_dir = __dirname.slice(0, -3) + 'cache';
}
async init() {
if (fs.existsSync(this.tmp_cache_dir+'/'+this.player_name+'.js')) {
const player_data = fs.readFileSync(this.tmp_cache_dir+'/'+this.player_name+'.js').toString();
if (fs.existsSync(this.tmp_cache_dir + '/' + this.player_name + '.js')) {
const player_data = fs.readFileSync(this.tmp_cache_dir + '/' + this.player_name + '.js').toString();
this.getSigDecipherCode(player_data);
this.getNEncoder(player_data);
} else {
const response = await axios.get(Constants.urls.YT_BASE_URL+this.session.player_url, { path: this.session.playerUrl, headers: { 'content-type': 'text/javascript', 'user-agent': Utils.getRandomUserAgent('desktop').userAgent } }).catch((error) => error);
if (response instanceof Error) throw new Error ('Could not get player data: ' + response.message);
const response = await axios.get(Constants.urls.YT_BASE_URL + this.session.player_url, { path: this.session.playerUrl, headers: { 'content-type': 'text/javascript', 'user-agent': Utils.getRandomUserAgent('desktop').userAgent } }).catch((error) => error);
if (response instanceof Error) throw new Error('Could not get player data: ' + response.message);
fs.mkdirSync(this.tmp_cache_dir, { recursive: true });
fs.writeFileSync(this.tmp_cache_dir+'/'+this.player_name+'.js', response.data);
fs.writeFileSync(this.tmp_cache_dir + '/' + this.player_name + '.js', response.data);
this.getSigDecipherCode(response.data);
this.getNEncoder(response.data);
}
}
getSigDecipherCode (data) {
const function_name = Utils.getStringBetweenStrings(data,'a.set("alr","yes");c&&(c=', '(decodeURIC');
getSigDecipherCode(data) {
const function_name = Utils.getStringBetweenStrings(data, 'a.set("alr","yes");c&&(c=', '(decodeURIC');
const func = Utils.getStringBetweenStrings(data, function_name + '=function(a)', '};') + '}';
this.dec_func = Utils.getStringBetweenStrings(data, 'var ' + Utils.getStringBetweenStrings(data, 'a=a.split("");', '.'), '};') + ';' + func + ';';
}
getNEncoder (data) {
getNEncoder(data) {
const raw_code = 'var b=a.split("")' + Utils.getStringBetweenStrings(data, 'b=a.split("")', '}return b.join("")}') + '} return b.join("");';
this.encodeN = Utils.createFunction('a', raw_code);
}