Feature: Run youtube-dl locally instead of calling a server.

This commit is contained in:
Preston 2018-03-11 21:08:35 -04:00
parent 9478917493
commit c0ff1cef57
4 changed files with 37 additions and 14 deletions

View File

@ -66,6 +66,7 @@
"mustache": "^2.3.0",
"nedb": "^1.8.0",
"node-async-loop": "^1.2.2",
"opml-to-json": "0.0.3"
"opml-to-json": "0.0.3",
"youtube-dl": "^1.12.2"
}
}

View File

@ -35,6 +35,7 @@ const electron = require('electron');
// Used for getting the user's subscriptions. Can probably remove this when that function
// is rewritten.
const asyncLoop = require('node-async-loop');
const youtubedl = require('youtube-dl');
const shell = electron.shell; // Used to open external links into the user's native browser.
const localDataStorage = electron.remote.app.getPath('userData'); // Grabs the userdata directory based on the user's OS
const clipboard = electron.clipboard;

View File

@ -67,11 +67,8 @@ function playVideo(videoId) {
/*
* FreeTube calls an instance of a youtube-dl server to grab the direct video URL. Please do not use this API in third party projects.
*/
const url = 'https://stormy-inlet-41826.herokuapp.com/api/info?url=https://www.youtube.com/watch?v=' + videoId + 'flatten=True&writesubtitles=true';
$.getJSON(url, (response) => {//https://stormy-inlet-41826.herokuapp.com/api/info?url=https://www.youtube.com/watch?v=bT1BSfP-NTcflatten=True&writesubtitles=True
console.log(response);
const info = response['info'];
youtubedlGetInfo(videoId, (info) => {
console.log(info);
videoThumbnail = info['thumbnail'];
let videoUrls = info['formats'];

View File

@ -1,12 +1,12 @@
/**
* List a YouTube HTTP API resource.
*
* @param {string} resource - The path of the resource.
* @param {object} params - The API parameters.
* @param {function} success - The function to be called on success.
*
* @return {Void}
*/
* List a YouTube HTTP API resource.
*
* @param {string} resource - The path of the resource.
* @param {object} params - The API parameters.
* @param {function} success - The function to be called on success.
*
* @return {Void}
*/
function youtubeAPI(resource, params, success) {
params.key = apiKey;
console.log(resource, params, success)
@ -20,3 +20,27 @@ function youtubeAPI(resource, params, success) {
stopLoadingAnimation();
});
}
/**
* Use youtube-dl to get the info for a video.
*
* @param {string} videoId - The video Id to get info from.
* @param {function} callback - The callback function when the call is finished.
*
* @return {Void}
*/
function youtubedlGetInfo(videoId, callback) {
let url = 'https://youtube.com/watch?v=' + videoId;
let options = ['--all-subs', '--geo-bypass'];
youtubedl.getInfo(url, options, function(err, info) {
if (err){
showToast('There was an issue calling youtube-dl.');
stopLoadingAnimation();
console.log(err);
}
console.log('Success');
callback(info);
});
}