From 6dc825dfb364c7f2d01223007db0afbd6fdf65bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Fri, 19 Mar 2021 11:25:36 +0100 Subject: [PATCH] YT: reduce amount of temp data stored per video --- src/youtube.js | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/youtube.js b/src/youtube.js index 3194a9b8..69c23e3e 100644 --- a/src/youtube.js +++ b/src/youtube.js @@ -136,30 +136,22 @@ var YouTubeClient = GObject.registerClass({ break; } - const info = result.data; const invalidInfoMsg = ( - !info.playabilityStatus - || !info.playabilityStatus.status === 'OK' + !result.data.playabilityStatus + || !result.data.playabilityStatus.status === 'OK' ) ? 'video is not playable' - : (!info.streamingData) + : (!result.data.streamingData) ? 'video response data is missing streaming data' : null; if(invalidInfoMsg) { - this.lastInfo = null; - debug(new Error(invalidInfoMsg)); break; } - /* Make sure we have all formats arrays, - * so we will not have to keep checking */ - if(!info.streamingData.formats) - info.streamingData.formats = []; - if(!info.streamingData.adaptiveFormats) - info.streamingData.adaptiveFormats = []; + const info = this._getReducedInfo(result.data); if(this._getIsCipher(info.streamingData)) { debug('video requires deciphering'); @@ -360,6 +352,28 @@ var YouTubeClient = GObject.registerClass({ }); } + _getReducedInfo(info) + { + const reduced = { + videoDetails: { + videoId: info.videoDetails.videoId, + title: info.videoDetails.title, + lengthSeconds: info.videoDetails.lengthSeconds, + isLiveContent: info.videoDetails.isLiveContent + }, + streamingData: info.streamingData + }; + + /* Make sure we have all formats arrays, + * so we will not have to keep checking */ + if(!reduced.streamingData.formats) + reduced.streamingData.formats = []; + if(!reduced.streamingData.adaptiveFormats) + reduced.streamingData.adaptiveFormats = []; + + return reduced; + } + _getPlayerInfoPromise(videoId) { const data = this._getPlayerPostData(videoId);