YT: do not check player ID if actions are cached

This commit is contained in:
Rafał Dzięgiel
2021-03-15 13:07:12 +01:00
parent 06f8e5d259
commit 5b6141ee8c

View File

@@ -52,7 +52,8 @@ var YouTubeClient = GObject.registerClass({
debug(`obtaining YouTube video info: ${videoId}`);
this.downloadingVideoId = videoId;
const [info, isAborted] = await this._getInfoPromise(videoId).catch(debug);
let [info, isAborted] = await this._getInfoPromise(videoId).catch(debug);
if(!info) {
if(isAborted)
return reject(new Error('download aborted'));
@@ -84,18 +85,19 @@ var YouTubeClient = GObject.registerClass({
if(!info.streamingData.adaptiveFormats)
info.streamingData.adaptiveFormats = [];
const isCipher = this._getIsCipher(info.streamingData);
if(isCipher) {
if(this._getIsCipher(info.streamingData)) {
debug('video requires deciphering');
/* Decipher actions do not change too often, so try
* to reuse without triggering too many requests ban */
let actions = this.cachedSig.actions;
if(!actions) {
const embedUri = `https://www.youtube.com/embed/${videoId}`;
const [body, isAbortedBody] =
await this._downloadDataPromise(embedUri).catch(debug);
if(isAbortedBody)
break;
/* We need matching info, so start from beginning */
if(!body)
continue;
@@ -116,12 +118,6 @@ var YouTubeClient = GObject.registerClass({
debug(`found player URI: ${ytUri}`);
const ytId = ytPath.split('/').find(el => Misc.isHex(el));
let actions;
if(this.cachedSig.id === ytId) {
debug('reusing cached cipher actions');
actions = this.cachedSig.actions;
}
/* TODO: load cache from file */
@@ -135,7 +131,6 @@ var YouTubeClient = GObject.registerClass({
actions = YTDL.sig.extractActions(pBody);
this._createCacheFileAsync(ytId, actions);
}
if(!actions || !actions.length) {
debug(new Error('could not extract decipher actions'));
break;
@@ -145,7 +140,8 @@ var YouTubeClient = GObject.registerClass({
if(this.cachedSig.id !== ytId) {
this.cachedSig.id = ytId;
this.cachedSig.actions = actions;
debug('set current decipher actions for reuse');
debug('remembered current decipher actions for reuse');
}
}
const isDeciphered = this._decipherStreamingData(
@@ -214,6 +210,8 @@ var YouTubeClient = GObject.registerClass({
debug(`got chunk of data, length: ${chunk.length}`);
const chunkData = chunk.get_data();
if(!chunkData) return;
data += (chunkData instanceof Uint8Array)
? ByteArray.toString(chunkData)
: chunkData;