mirror of https://github.com/FreeTubeApp/FreeTube
Allow use of self-hosted Invidious Instance
This commit is contained in:
parent
47094ecb85
commit
942c39a687
|
@ -39,21 +39,6 @@ const clipboard = electron.clipboard;
|
|||
const getOpml = require('opml-to-json'); // Gets the file type for imported files.
|
||||
const fs = require('fs'); // Used to read files. Specifically in the settings page.
|
||||
|
||||
// User Defaults
|
||||
let currentTheme = '';
|
||||
let useTor = false;
|
||||
let rememberHistory = true;
|
||||
let autoplay = true;
|
||||
let enableSubtitles = false;
|
||||
let checkForUpdates = true;
|
||||
let currentVolume = 1;
|
||||
let defaultQuality = 720;
|
||||
let defaultPlaybackRate = '1';
|
||||
// Proxy address variable
|
||||
let defaultProxy = false;
|
||||
// This variable is to make sure that proxy was set before making any API calls
|
||||
let proxyAvailable = false;
|
||||
|
||||
let dialog = electron.remote.dialog; // Used for opening file browser to export / import subscriptions.
|
||||
let toastTimeout; // Timeout for toast notifications.
|
||||
let mouseTimeout; // Timeout for hiding the mouse cursor on video playback
|
||||
|
@ -225,12 +210,12 @@ function showVideoOptions(element) {
|
|||
function proxyRequest(callback) {
|
||||
let proxyCheckingInterval;
|
||||
let counter = 0;
|
||||
|
||||
|
||||
// Wait for proxy to become available
|
||||
proxyCheckingInterval = setInterval(function() {
|
||||
if(proxyAvailable) {
|
||||
clearInterval(proxyCheckingInterval)
|
||||
|
||||
|
||||
callback();
|
||||
|
||||
} else {
|
||||
|
@ -241,4 +226,4 @@ function proxyRequest(callback) {
|
|||
counter++;
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,15 +32,13 @@ function playVideo(videoId, playlistId = '') {
|
|||
playerView.playerSeen = true;
|
||||
playerView.firstLoad = true;
|
||||
playerView.videoId = videoId;
|
||||
playerView.videoAudio = '';
|
||||
playerView.videoAudio = undefined;
|
||||
playerView.validAudio = true;
|
||||
playerView.video480p = '';
|
||||
playerView.video480p = undefined;
|
||||
playerView.valid480p = true;
|
||||
playerView.video720p = '';
|
||||
playerView.video720p = undefined;
|
||||
playerView.valid720p = true;
|
||||
playerView.videoUrl = '';
|
||||
playerView.embededHtml = "<iframe width='560' height='315' src='https://www.youtube-nocookie.com/embed/" + videoId + "?rel=0' frameborder='0' allow='autoplay; encrypted-media' allowfullscreen></iframe>";
|
||||
|
||||
let videoHtml = '';
|
||||
|
@ -69,11 +67,11 @@ function playVideo(videoId, playlistId = '') {
|
|||
switch (videoUrls[key]['itag']) {
|
||||
case '18':
|
||||
playerView.video480p = decodeURIComponent(videoUrls[key]['url']);
|
||||
//console.log(video480p);
|
||||
// console.log(playerView.video480p);
|
||||
break;
|
||||
case '22':
|
||||
playerView.video720p = decodeURIComponent(videoUrls[key]['url']);
|
||||
//console.log(video720p);
|
||||
// console.log(playerView.video720p);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
@ -82,6 +80,7 @@ function playVideo(videoId, playlistId = '') {
|
|||
playerView.videoAudio = decodeURIComponent(formatUrls[formatUrls.length - 1]['url']);
|
||||
|
||||
if (typeof(playerView.videoAudio) === 'undefined') {
|
||||
console.log(playerView.videoAudio);
|
||||
playerView.validAudio = false;
|
||||
}
|
||||
|
||||
|
@ -107,15 +106,25 @@ function playVideo(videoId, playlistId = '') {
|
|||
//playerView.videoUrl = playerView.liveManifest;
|
||||
}
|
||||
|
||||
if (!useEmbedPlayer && data.player_response.captions !== undefined) {
|
||||
if (!useEmbedPlayer && data.player_response.captions.playerCaptionsTracklistRenderer.captionTracks !== undefined) {
|
||||
data.player_response.captions.playerCaptionsTracklistRenderer.captionTracks.forEach((caption) => {
|
||||
let subtitleUrl = 'https://www.invidio.us/api/v1/captions/' + videoId + '?label=' + caption.name.simpleText;
|
||||
let subtitleUrl = invidiousInstance + '/api/v1/captions/' + videoId + '?label=' + caption.name.simpleText;
|
||||
|
||||
videoHtml = videoHtml + '<track kind="subtitles" src="' + subtitleUrl + '" srclang="' + caption.languageCode + '" label="' + caption.name.simpleText + '">';
|
||||
});
|
||||
|
||||
playerView.subtitleHtml = videoHtml;
|
||||
}
|
||||
|
||||
loadingView.seen = false;
|
||||
|
||||
if (subscriptionView.seen === false && aboutView.seen === false && headerView.seen === false && searchView.seen === false && settingsView.seen === false && popularView.seen === false && savedView.seen === false && historyView.seen === false && channelView.seen === false && channelVideosView.seen === false) {
|
||||
playerView.seen = true;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
window.setTimeout(checkVideoUrls, 5000, playerView.video480p, playerView.video720p, playerView.videoAudio);
|
||||
});
|
||||
|
||||
invidiousAPI('videos', videoId, {}, (data) => {
|
||||
|
@ -148,13 +157,9 @@ function playVideo(videoId, playlistId = '') {
|
|||
|
||||
checkSubscription.then((results) => {
|
||||
if (results === false) {
|
||||
if (subscribeButton != null) {
|
||||
playerView.subscribedText = 'SUBSCRIBE';
|
||||
}
|
||||
playerView.subscribedText = 'SUBSCRIBE';
|
||||
} else {
|
||||
if (subscribeButton != null) {
|
||||
playerView.subscribedText = 'UNSUBSCRIBE';
|
||||
}
|
||||
playerView.subscribedText = 'UNSUBSCRIBE';
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -234,20 +239,9 @@ function playVideo(videoId, playlistId = '') {
|
|||
playerView.playlistId = '';
|
||||
}
|
||||
|
||||
loadingView.seen = false;
|
||||
|
||||
if (subscriptionView.seen === false && aboutView.seen === false && headerView.seen === false && searchView.seen === false && settingsView.seen === false && popularView.seen === false && savedView.seen === false && historyView.seen === false && channelView.seen === false && channelVideosView.seen === false) {
|
||||
playerView.seen = true;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rememberHistory === true){
|
||||
addToHistory(videoId);
|
||||
}
|
||||
|
||||
window.setTimeout(checkVideoUrls, 5000, playerView.video480p, playerView.video720p, playerView.videoAudio);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,23 @@ along with FreeTube. If not, see <http://www.gnu.org/licenses/>.
|
|||
* A file for functions used for settings.
|
||||
*/
|
||||
|
||||
// User Defaults
|
||||
let currentTheme = '';
|
||||
let useTor = false;
|
||||
let rememberHistory = true;
|
||||
let autoplay = true;
|
||||
let enableSubtitles = false;
|
||||
let checkForUpdates = true;
|
||||
let currentVolume = 1;
|
||||
let defaultQuality = 720;
|
||||
let defaultPlaybackRate = '1';
|
||||
// Proxy address variable
|
||||
let defaultProxy = false;
|
||||
// This variable is to make sure that proxy was set before making any API calls
|
||||
let proxyAvailable = false;
|
||||
let invidiousInstance = 'https://invidio.us';
|
||||
let checkedSettings = false; // Used to prevent data leak when using self-hosted Invidious Instance
|
||||
|
||||
/**
|
||||
* Display the settings screen to the user.
|
||||
*
|
||||
|
@ -104,6 +121,7 @@ function checkDefaultSettings() {
|
|||
'updates': true,
|
||||
'quality': '720',
|
||||
'rate': '1',
|
||||
'invidious': 'https://invidio.us',
|
||||
'proxy': "SOCKS5://127.0.0.1:9050" // This is default value for tor client
|
||||
};
|
||||
|
||||
|
@ -160,11 +178,15 @@ function checkDefaultSettings() {
|
|||
break;
|
||||
case 'proxy':
|
||||
defaultProxy = docs[0]['value'];
|
||||
|
||||
|
||||
if(useTor && defaultProxy) {
|
||||
electron.ipcRenderer.send("setProxy", defaultProxy);
|
||||
}
|
||||
break;
|
||||
case 'invidious':
|
||||
settingsView.invidiousInstance = docs[0]['value'];
|
||||
invidiousInstance = docs[0]['value'];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -188,6 +210,7 @@ function updateSettings() {
|
|||
let qualitySelect = document.getElementById('qualitySelect').value;
|
||||
let rateSelect = document.getElementById('rateSelect').value;
|
||||
let proxyAddress = document.getElementById('proxyAddress').value;
|
||||
let invidious = document.getElementById('invidiousInstance').value;
|
||||
let theme = 'light';
|
||||
|
||||
settingsView.useTor = torSwitch;
|
||||
|
@ -236,6 +259,18 @@ function updateSettings() {
|
|||
defaultProxy = proxyAddress;
|
||||
});
|
||||
|
||||
// Update Invidious Instance
|
||||
settingsDb.update({
|
||||
_id: 'invidious'
|
||||
}, {
|
||||
value: invidious
|
||||
}, {}, function(err, numReplaced) {
|
||||
console.log(err);
|
||||
console.log(numReplaced);
|
||||
settingsView.invidiousInstance = invidious;
|
||||
invidiousInstance = invidious;
|
||||
});
|
||||
|
||||
// Update history
|
||||
settingsDb.update({
|
||||
_id: 'history'
|
||||
|
|
|
@ -238,19 +238,14 @@ function toggleSubscription(channelId) {
|
|||
event.stopPropagation();
|
||||
|
||||
const checkIfSubscribed = isSubscribed(channelId);
|
||||
const subscribeButton = document.getElementById('subscribeButton');
|
||||
|
||||
checkIfSubscribed.then((results) => {
|
||||
|
||||
if (results === false) {
|
||||
if (subscribeButton != null) {
|
||||
subscribeButton.innerHTML = 'UNSUBSCRIBE';
|
||||
}
|
||||
playerView.subscribedText = 'SUBSCRIBE';
|
||||
addSubscription(channelId);
|
||||
} else {
|
||||
if (subscribeButton != null) {
|
||||
subscribeButton.innerHTML = 'SUBSCRIBE';
|
||||
}
|
||||
playerView.subscribedText = 'UNSUBSCRIBE';
|
||||
removeSubscription(channelId);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -369,6 +369,7 @@ let settingsView = new Vue({
|
|||
subtitles: false,
|
||||
updates: true,
|
||||
proxyAddress: false,
|
||||
invidiousInstance: 'https://invidio.us',
|
||||
checkProxyResult: false,
|
||||
proxyTestLoading: false
|
||||
},
|
||||
|
@ -383,7 +384,7 @@ let settingsView = new Vue({
|
|||
url: "https://ifconfig.co/json",
|
||||
dataType: 'json',
|
||||
timeout: 3000 // 3 second timeout
|
||||
}).done(response => {
|
||||
}).done(response => {
|
||||
this.checkProxyResult = response;
|
||||
})
|
||||
.fail((xhr, textStatus, error) => {
|
||||
|
|
|
@ -29,10 +29,10 @@ function invidiousAPI(resource, id, params, success, fail = function(){
|
|||
showToast('There was an error calling the Invidious API.');
|
||||
loadingView.seen = false;
|
||||
}) {
|
||||
let requestUrl = 'https://www.invidio.us/api/v1/' + resource + '/' + id + '?' + $.param(params);
|
||||
let requestUrl = invidiousInstance + '/api/v1/' + resource + '/' + id + '?' + $.param(params);
|
||||
|
||||
if (useTor) {
|
||||
|
||||
|
||||
proxyRequest(() => {
|
||||
$.getJSON(
|
||||
requestUrl,
|
||||
|
@ -42,7 +42,7 @@ function invidiousAPI(resource, id, params, success, fail = function(){
|
|||
console.log(xhr);
|
||||
console.log(textStatus);
|
||||
console.log(requestUrl);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
} else {
|
||||
|
|
|
@ -41,15 +41,20 @@
|
|||
</div>
|
||||
<br />
|
||||
</div>
|
||||
<div class='center'>
|
||||
<div class="input-text-settings">
|
||||
<label for="invidiousInstance">Current Invidious Instance (Defaults to https://invidio.us)</label>
|
||||
<input type="text" id="invidiousInstance" name="set-name" v-model="invidiousInstance">
|
||||
</div>
|
||||
</div>
|
||||
<div class="center">
|
||||
<input type="checkbox" id="torSwitch" name="set-name" class="switch-input" :checked='useTor'>
|
||||
<label for="torSwitch" class="switch-label">Use Tor / Proxy for API calls</label>
|
||||
|
||||
<div class="input-text-settings">
|
||||
<label for="proxyAddress">Proxy Address (Example: SOCKS5://127.0.0.1:9050):</label>
|
||||
<input type="text" id="proxyAddress" name="set-name" v-model="proxyAddress">
|
||||
</div>
|
||||
|
||||
|
||||
<div id="ipInfoSettings" v-if="checkProxyResult">
|
||||
<h4>Your Info:</h4>
|
||||
<p>ip: {{checkProxyResult.ip}}</p>
|
||||
|
|
Loading…
Reference in New Issue