From eaf090d2e2ad2ab6a27ffc2bfd2df8b35fe6e330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Sun, 18 Apr 2021 14:04:53 +0200 Subject: [PATCH] YT: be a little more quiet about some errors Some errors are to be expected for some videos. Quietly use fallback methods for them without printing those errors. --- src/youtube.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/youtube.js b/src/youtube.js index 78e79fd1..5d7cdfed 100644 --- a/src/youtube.js +++ b/src/youtube.js @@ -373,7 +373,8 @@ var YouTubeClient = GObject.registerClass({ const hlsUri = info.streamingData.hlsManifestUrl; if(!hlsUri) { - debug(new Error('no HLS manifest URL')); + /* HLS may be unavailable on finished live streams */ + debug('no HLS manifest URL'); return null; } @@ -466,8 +467,16 @@ var YouTubeClient = GObject.registerClass({ for(let stream of fmtArr) { debug(`initial URL: ${stream.url}`); - const result = await this._downloadDataPromise(stream.url, 'HEAD').catch(debug); - if(!result) return null; + /* Errors in some cases are to be expected here, + * so be quiet about them and use fallback methods */ + const result = await this._downloadDataPromise( + stream.url, 'HEAD' + ).catch(err => debug(err.message)); + + if(!result || !result.uri) { + debug('redirect could not be resolved'); + return null; + } stream.url = Misc.encodeHTML(result.uri) .replace('?', '/') @@ -577,7 +586,7 @@ var YouTubeClient = GObject.registerClass({ return resolve(result); } - debug(new Error(`response code: ${statusCode}`)); + debug(`response code: ${statusCode}`); /* Internal Soup codes mean download aborted * or some other error that cannot be handled