mirror of https://github.com/FreeTubeApp/FreeTube
Get Video URL based on user IP instead of Inividious IP
This commit is contained in:
parent
7b530b0dcb
commit
faf1a85731
|
@ -102,6 +102,6 @@
|
|||
"opml-to-json": "0.0.3",
|
||||
"tor-request": "^2.3.0",
|
||||
"vue": "^2.5.17",
|
||||
"ytdl-core": "^0.20.4"
|
||||
"ytdl-core": "^0.29.1"
|
||||
}
|
||||
}
|
||||
|
|
123
src/js/player.js
123
src/js/player.js
|
@ -32,10 +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.embededHtml = "<iframe width='560' height='315' src='https://www.youtube-nocookie.com/embed/" + videoId + "?rel=0' frameborder='0' allow='autoplay; encrypted-media' allowfullscreen></iframe>";
|
||||
|
@ -54,8 +57,68 @@ function playVideo(videoId, playlistId = '') {
|
|||
playerView.savedIconType = 'fas saved';
|
||||
}
|
||||
});
|
||||
//"kpkXPy_jXmU"
|
||||
invidiousAPI('videos', videoId, {}, function (data) {
|
||||
|
||||
youtubedlGetInfo(videoId, (data) => {
|
||||
console.log(data);
|
||||
|
||||
let videoUrls = data.formats;
|
||||
let formatUrls = data.player_response.streamingData.adaptiveFormats;
|
||||
|
||||
// Search through the returned object to get the 480p and 720p video URLs (If available)
|
||||
Object.keys(videoUrls).forEach((key) => {
|
||||
switch (videoUrls[key]['itag']) {
|
||||
case '18':
|
||||
playerView.video480p = decodeURIComponent(videoUrls[key]['url']);
|
||||
//console.log(video480p);
|
||||
break;
|
||||
case '22':
|
||||
playerView.video720p = decodeURIComponent(videoUrls[key]['url']);
|
||||
//console.log(video720p);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// Last adaptive format will be best the quality audio stream (migrate fully to adaptive formats later)
|
||||
playerView.videoAudio = decodeURIComponent(formatUrls[formatUrls.length - 1]['url']);
|
||||
|
||||
if (typeof(playerView.videoAudio) === 'undefined') {
|
||||
playerView.validAudio = false;
|
||||
}
|
||||
|
||||
let useEmbedPlayer = false;
|
||||
|
||||
// Default to the embeded player if the URLs cannot be found.
|
||||
if (typeof (playerView.video720p) === 'undefined' && typeof (playerView.video480p) === 'undefined') {
|
||||
//useEmbedPlayer = true;
|
||||
playerView.currentQuality = 'EMBED';
|
||||
playerView.playerSeen = false;
|
||||
//useEmbedPlayer = true;
|
||||
showToast('Unable to get video file. Reverting to embeded player.');
|
||||
}
|
||||
else if (typeof (playerView.video720p) === 'undefined' && typeof (playerView.video480p) !== 'undefined') {
|
||||
// Default to the 480p video if the 720p URL cannot be found.
|
||||
console.log('Found');
|
||||
playerView.videoUrl = playerView.video480p;
|
||||
playerView.currentQuality = '480p';
|
||||
} else {
|
||||
// Default to the 720p video.
|
||||
playerView.videoUrl = playerView.video720p;
|
||||
playerView.currentQuality = '720p';
|
||||
//playerView.videoUrl = playerView.liveManifest;
|
||||
}
|
||||
|
||||
if (!useEmbedPlayer && data.player_response.captions !== undefined) {
|
||||
data.player_response.captions.playerCaptionsTracklistRenderer.captionTracks.forEach((caption) => {
|
||||
let subtitleUrl = 'https://www.invidio.us/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;
|
||||
}
|
||||
});
|
||||
|
||||
invidiousAPI('videos', videoId, {}, (data) => {
|
||||
|
||||
console.log(data);
|
||||
|
||||
|
@ -68,9 +131,6 @@ function playVideo(videoId, playlistId = '') {
|
|||
playerView.channelName = data.author;
|
||||
playerView.channelId = data.authorId;
|
||||
playerView.channelIcon = data.authorThumbnails[2].url;
|
||||
|
||||
let videoUrls = data.formatStreams;
|
||||
let formatUrls = data.adaptiveFormats;
|
||||
|
||||
// Add commas to the video view count.
|
||||
playerView.videoViews = data.viewCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
|
@ -84,59 +144,6 @@ function playVideo(videoId, playlistId = '') {
|
|||
|
||||
playerView.description = parseDescription(data.descriptionHtml);
|
||||
|
||||
// Search through the returned object to get the 480p and 720p video URLs (If available)
|
||||
Object.keys(videoUrls).forEach((key) => {
|
||||
switch (videoUrls[key]['itag']) {
|
||||
case '18':
|
||||
playerView.video480p = decodeURIComponent(videoUrls[key]['url']);
|
||||
//console.log(video480p);
|
||||
break;
|
||||
case '22':
|
||||
playerView.video720p = decodeURIComponent(videoUrls[key]['url']);
|
||||
//console.log(video720p);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// Last adaptive format will be best the quality audio stream (migrate fully to adaptive formats later)
|
||||
playerView.videoAudio = decodeURIComponent(formatUrls[formatUrls.length - 1]['url']);
|
||||
|
||||
if (typeof(playerView.videoAudio) === 'undefined') {
|
||||
playerView.validAudio = false;
|
||||
}
|
||||
|
||||
let useEmbedPlayer = false;
|
||||
|
||||
// Default to the embeded player if the URLs cannot be found.
|
||||
if (typeof (playerView.video720p) === 'undefined' && typeof (playerView.video480p) === 'undefined') {
|
||||
//useEmbedPlayer = true;
|
||||
playerView.currentQuality = 'EMBED';
|
||||
playerView.playerSeen = false;
|
||||
//useEmbedPlayer = true;
|
||||
showToast('Unable to get video file. Reverting to embeded player.');
|
||||
}
|
||||
else if (typeof (playerView.video720p) === 'undefined' && typeof (playerView.video480p) !== 'undefined') {
|
||||
// Default to the 480p video if the 720p URL cannot be found.
|
||||
console.log('Found');
|
||||
playerView.videoUrl = playerView.video480p;
|
||||
playerView.currentQuality = '480p';
|
||||
} else {
|
||||
// Default to the 720p video.
|
||||
playerView.videoUrl = playerView.video720p;
|
||||
playerView.currentQuality = '720p';
|
||||
//playerView.videoUrl = playerView.liveManifest;
|
||||
}
|
||||
|
||||
if (!useEmbedPlayer) {
|
||||
data.captions.forEach((caption) => {
|
||||
let subtitleUrl = 'https://www.invidio.us/api/v1/captions/' + videoId + '?label=' + caption.label;
|
||||
|
||||
videoHtml = videoHtml + '<track kind="subtitles" src="' + subtitleUrl + '" srclang="' + caption.languageCode + '" label="' + caption.label + '">';
|
||||
});
|
||||
|
||||
playerView.subtitleHtml = videoHtml;
|
||||
}
|
||||
|
||||
const checkSubscription = isSubscribed(playerView.channelId);
|
||||
|
||||
checkSubscription.then((results) => {
|
||||
|
|
Loading…
Reference in New Issue