Get Video URL based on user IP instead of Inividious IP

This commit is contained in:
PrestonN 2019-02-26 09:53:18 -05:00
parent 7b530b0dcb
commit faf1a85731
2 changed files with 66 additions and 59 deletions

View File

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

View File

@ -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,35 +57,12 @@ function playVideo(videoId, playlistId = '') {
playerView.savedIconType = 'fas saved';
}
});
//"kpkXPy_jXmU"
invidiousAPI('videos', videoId, {}, function (data) {
youtubedlGetInfo(videoId, (data) => {
console.log(data);
// Figure out the width for the like/dislike bar.
playerView.videoLikes = data.likeCount;
playerView.videoDislikes = data.dislikeCount;
let totalLikes = parseInt(playerView.videoLikes) + parseInt(playerView.videoDislikes);
playerView.likePercentage = parseInt((playerView.videoLikes / totalLikes) * 100);
playerView.videoTitle = data.title;
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, ",");
playerView.videoThumbnail = data.videoThumbnails[0].url;
// Format the date to a more readable format.
let dateString = new Date(data.published * 1000);
dateString.setDate(dateString.getDate() + 1);
playerView.publishedDate = dateFormat(dateString, "mmm dS, yyyy");
playerView.description = parseDescription(data.descriptionHtml);
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) => {
@ -127,15 +107,42 @@ function playVideo(videoId, playlistId = '') {
//playerView.videoUrl = playerView.liveManifest;
}
if (!useEmbedPlayer) {
data.captions.forEach((caption) => {
let subtitleUrl = 'https://www.invidio.us/api/v1/captions/' + videoId + '?label=' + caption.label;
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.label + '">';
videoHtml = videoHtml + '<track kind="subtitles" src="' + subtitleUrl + '" srclang="' + caption.languageCode + '" label="' + caption.name.simpleText + '">';
});
playerView.subtitleHtml = videoHtml;
}
});
invidiousAPI('videos', videoId, {}, (data) => {
console.log(data);
// Figure out the width for the like/dislike bar.
playerView.videoLikes = data.likeCount;
playerView.videoDislikes = data.dislikeCount;
let totalLikes = parseInt(playerView.videoLikes) + parseInt(playerView.videoDislikes);
playerView.likePercentage = parseInt((playerView.videoLikes / totalLikes) * 100);
playerView.videoTitle = data.title;
playerView.channelName = data.author;
playerView.channelId = data.authorId;
playerView.channelIcon = data.authorThumbnails[2].url;
// Add commas to the video view count.
playerView.videoViews = data.viewCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
playerView.videoThumbnail = data.videoThumbnails[0].url;
// Format the date to a more readable format.
let dateString = new Date(data.published * 1000);
dateString.setDate(dateString.getDate() + 1);
playerView.publishedDate = dateFormat(dateString, "mmm dS, yyyy");
playerView.description = parseDescription(data.descriptionHtml);
const checkSubscription = isSubscribed(playerView.channelId);