From a5e1db960c6c50e2ab65f2f1bfabc409b00d83fe Mon Sep 17 00:00:00 2001 From: FreeTube Date: Mon, 11 Jun 2018 14:00:04 -0400 Subject: [PATCH] Fix: Videos not playing and opening YouTube and HookTube links. --- src/js/layout.js | 3 ++- src/js/player.js | 23 ++++++++++++----------- src/templates/player.html | 4 +++- src/templates/settings.html | 2 +- src/templates/videoList.html | 4 ++-- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/js/layout.js b/src/js/layout.js index 5ce1ab1cc..75734d019 100644 --- a/src/js/layout.js +++ b/src/js/layout.js @@ -83,9 +83,10 @@ const settingsDb = new Datastore({ checkDefaultSettings(); require('electron').ipcRenderer.on('ping', function(event, message) { + console.log(message); let url = message[1].replace('freetube://', ''); parseSearchText(url); - console.log(message); // Prints "whoooooooh!" + console.log(message); }); // Open links externally by default diff --git a/src/js/player.js b/src/js/player.js index 0ce731c01..3133709e7 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -119,11 +119,11 @@ function playVideo(videoId, videoThumbnail = '', useWindowPlayer = false) { Object.keys(videoUrls).forEach((key) => { switch (videoUrls[key]['itag']) { case '18': - video480p = videoUrls[key]['url']; + video480p = decodeURIComponent(videoUrls[key]['url']); console.log(video480p); break; case '22': - video720p = videoUrls[key]['url']; + video720p = decodeURIComponent(videoUrls[key]['url']); console.log(video720p); break; } @@ -148,7 +148,7 @@ function playVideo(videoId, videoThumbnail = '', useWindowPlayer = false) { } if (!useEmbedPlayer) { - videoHtml = ''; } const checkSubscription = isSubscribed(channelId); @@ -192,8 +192,9 @@ function playVideo(videoId, videoThumbnail = '', useWindowPlayer = false) { const playerTemplate = require('./templates/player.html') mustache.parse(playerTemplate); const rendered = mustache.render(playerTemplate, { - videoHtml: videoHtml, videoQuality: defaultQuality, + subtitleHtml: videoHtml, + defaultUrl: defaultUrl, videoTitle: info['title'], videoViews: videoViews, videoThumbnail: videoThumbnail, @@ -234,7 +235,7 @@ function playVideo(videoId, videoThumbnail = '', useWindowPlayer = false) { videoId: videoId, channelId: channelId }); - + newWindow.loadURL('data:text/html;charset=UTF-8,' + encodeURIComponent(playerHeaderRender + rendered), { baseURLForDataURL: `file://${__dirname}/src` }); @@ -245,11 +246,6 @@ function playVideo(videoId, videoThumbnail = '', useWindowPlayer = false) { showVideoRecommendations(videoId); - // Sometimes a video URL is found, but the video will not play. I believe the issue is - // that the video has yet to render for that quality, as the video will be available at a later time. - // This will check the URLs and switch video sources if there is an error. - checkVideoUrls(video480p, video720p); - // Hide subtitles by default if (typeof(info['subtitles']) !== 'undefined' && Object.keys(info['subtitles']).length > 0) { let textTracks = $('.videoPlayer').get(0).textTracks; @@ -259,7 +255,12 @@ function playVideo(videoId, videoThumbnail = '', useWindowPlayer = false) { } } + // Sometimes a video URL is found, but the video will not play. I believe the issue is + // that the video has yet to render for that quality, as the video will be available at a later time. + // This will check the URLs and switch video sources if there is an error. + //checkVideoUrls(video480p, video720p); + window.setTimeout(checkVideoUrls, 5000, video480p, video720p); }); } diff --git a/src/templates/player.html b/src/templates/player.html index 342974662..84bd05131 100644 --- a/src/templates/player.html +++ b/src/templates/player.html @@ -1,4 +1,6 @@ -{{{videoHtml}}} +
MINI PLAYER diff --git a/src/templates/settings.html b/src/templates/settings.html index 5babcfcc8..a9e4f178d 100644 --- a/src/templates/settings.html +++ b/src/templates/settings.html @@ -7,7 +7,7 @@ - +
diff --git a/src/templates/videoList.html b/src/templates/videoList.html index 88be73e51..2c0d01791 100644 --- a/src/templates/videoList.html +++ b/src/templates/videoList.html @@ -4,8 +4,8 @@