mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-07-03 09:35:05 +00:00
Now downloads are possible
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user