Prefetch YouTube video info on hover

Speed up loading of YouTube videos by downloading and parsing their info before video is dropped into player.
This commit is contained in:
Rafał Dzięgiel
2021-03-12 13:05:58 +01:00
parent 01c26cbbc3
commit c89d488c30
3 changed files with 129 additions and 14 deletions

View File

@@ -26,6 +26,7 @@ class ClapperPlayer extends PlayerBase
this.needsTocUpdate = true;
this.keyPressCount = 0;
this.ytClient = null;
const keyController = new Gtk.EventControllerKey();
keyController.connect('key-pressed', this._onWidgetKeyPressed.bind(this));
@@ -78,8 +79,10 @@ class ClapperPlayer extends PlayerBase
async getYouTubeUriAsync(videoId)
{
const client = new YouTube.YouTubeClient();
const info = await client.getVideoInfoPromise(videoId).catch(debug);
if(!this.ytClient)
this.ytClient = new YouTube.YouTubeClient();
const info = await this.ytClient.getVideoInfoPromise(videoId).catch(debug);
if(!info)
throw new Error('no YouTube video info');
@@ -87,7 +90,7 @@ class ClapperPlayer extends PlayerBase
const dash = Dash.generateDash(info);
const videoUri = (dash)
? await Dash.saveDashPromise(dash).catch(debug)
: client.getBestCombinedUri(info);
: this.ytClient.getBestCombinedUri(info);
if(!videoUri)
throw new Error('no YouTube video URI');