Fix: Videos not playing and opening YouTube and HookTube links.

This commit is contained in:
FreeTube 2018-06-11 14:00:04 -04:00
parent 96bd02ad24
commit a5e1db960c
5 changed files with 20 additions and 16 deletions

View File

@ -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

View File

@ -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 = '<video class="videoPlayer" type="application/x-mpegURL" onmousemove="hideMouseTimeout()" onmouseleave="removeMouseTimeout()" controls="" src="' + defaultUrl + '" poster="' + videoThumbnail + '" autoplay>';
//videoHtml = '<video class="videoPlayer" type="application/x-mpegURL" onmousemove="hideMouseTimeout()" onmouseleave="removeMouseTimeout()" controls="" src="' + defaultUrl + '" poster="' + videoThumbnail + '" autoplay>';
if (typeof(info.player_response.captions) === 'object') {
@ -168,7 +168,7 @@ function playVideo(videoId, videoThumbnail = '', useWindowPlayer = false) {
}
}
videoHtml = videoHtml + '</video>';
//videoHtml = videoHtml + '</video>';
}
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);
});
}

View File

@ -1,4 +1,6 @@
{{{videoHtml}}}
<video class="videoPlayer" type="application/x-mpegURL" onmousemove="hideMouseTimeout()" onmouseleave="removeMouseTimeout()" controls="" src="{{defaultUrl}}" poster="{{videoThumbnail}}" autoplay>
{{{subtitleHtml}}}
</video>
<div class='statistics'>
<div class='smallButton' onclick="openMiniPlayer('{{videoThumbnail}}')">
MINI PLAYER <i class="fas fa-external-link-alt"></i>

View File

@ -7,7 +7,7 @@
<input type="checkbox" id="themeSwitch" name="set-name" class="switch-input" onchange='toggleTheme(this)' {{isChecked}}>
<label for="themeSwitch" class="switch-label">Use Dark Theme</label>
<input type="checkbox" id="torSwitch" name="set-name" class="switch-input" {{isChecked}}>
<label for="torSwitch" class="switch-label">Use TOR for API calls</label>
<label for="torSwitch" class="switch-label">Use Tor for API calls</label>
</div>
<div class='center'>
<div onclick='importSubscriptions()' class='settingsButton'>

View File

@ -4,8 +4,8 @@
<ul>
<li onclick='playVideo("{{videoId}}", "", true); showVideoOptions(this.parentNode.previousSibling);'>Open (New Window)</li>
<li onclick='addSavedVideo("{{videoId}}"); showVideoOptions(this.parentNode.previousSibling);'>Save Video</li>
<a href='https://youtube.com/watch?v={{videoId}}; showVideoOptions(this.parentNode.previousSibling);' ><li>Open in YouTube</li></a>
<a href='https://hooktube.com/watch?v={{videoId}}; showVideoOptions(this.parentNode.previousSibling);' ><li>Open in HookTube</li></a>
<a href='https://youtube.com/watch?v={{videoId}}' ><li>Open in YouTube</li></a>
<a href='https://hooktube.com/watch?v={{videoId}}' ><li>Open in HookTube</li></a>
{{{deleteHtml}}}
</ul>
</div>