mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-14 20:01:28 +03:00
Merge pull request #336 from Tzahi12345/add-yt-dlp
Added yt-dlp support
This commit is contained in:
@@ -1184,6 +1184,11 @@ async function generateArgs(url, type, options) {
|
|||||||
}
|
}
|
||||||
downloadConfig = downloadConfig.concat(globalArgs.split(',,'));
|
downloadConfig = downloadConfig.concat(globalArgs.split(',,'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const default_downloader = getCurrentDownloader() || config_api.getConfigItem('ytdl_default_downloader');
|
||||||
|
if (default_downloader === 'yt-dlp') {
|
||||||
|
downloadConfig.push('--no-clean-infojson');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1343,21 +1348,33 @@ async function startYoutubeDL() {
|
|||||||
|
|
||||||
// auto updates the underlying youtube-dl binary, not YoutubeDL-Material
|
// auto updates the underlying youtube-dl binary, not YoutubeDL-Material
|
||||||
async function autoUpdateYoutubeDL() {
|
async function autoUpdateYoutubeDL() {
|
||||||
|
const download_sources = {
|
||||||
|
'youtube-dl': {
|
||||||
|
'tags_url': 'https://api.github.com/repos/ytdl-org/youtube-dl/tags',
|
||||||
|
'func': downloadLatestYoutubeDLBinary
|
||||||
|
},
|
||||||
|
'youtube-dlc': {
|
||||||
|
'tags_url': 'https://api.github.com/repos/blackjack4494/yt-dlc/tags',
|
||||||
|
'func': downloadLatestYoutubeDLCBinary
|
||||||
|
},
|
||||||
|
'yt-dlp': {
|
||||||
|
'tags_url': 'https://api.github.com/repos/yt-dlp/yt-dlp/tags',
|
||||||
|
'func': downloadLatestYoutubeDLPBinary
|
||||||
|
}
|
||||||
|
}
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
const default_downloader = config_api.getConfigItem('ytdl_default_downloader');
|
const default_downloader = config_api.getConfigItem('ytdl_default_downloader');
|
||||||
const using_youtube_dlc = default_downloader === 'youtube-dlc';
|
const tags_url = download_sources[default_downloader]['tags_url'];
|
||||||
const youtube_dl_tags_url = 'https://api.github.com/repos/ytdl-org/youtube-dl/tags'
|
|
||||||
const youtube_dlc_tags_url = 'https://api.github.com/repos/blackjack4494/yt-dlc/tags'
|
|
||||||
// get current version
|
// get current version
|
||||||
let current_app_details_path = 'node_modules/youtube-dl/bin/details';
|
let current_app_details_path = 'node_modules/youtube-dl/bin/details';
|
||||||
let current_app_details_exists = fs.existsSync(current_app_details_path);
|
let current_app_details_exists = fs.existsSync(current_app_details_path);
|
||||||
if (!current_app_details_exists) {
|
if (!current_app_details_exists) {
|
||||||
logger.error(`Failed to get youtube-dl binary details at location '${current_app_details_path}'. Cancelling update check.`);
|
logger.warn(`Failed to get youtube-dl binary details at location '${current_app_details_path}'. Generating file...`);
|
||||||
resolve(false);
|
fs.writeJSONSync('node_modules/youtube-dl/bin/details', {"version":"2020.00.00", "downloader": default_downloader});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
let current_app_details = JSON.parse(fs.readFileSync(current_app_details_path));
|
let current_app_details = JSON.parse(fs.readFileSync(current_app_details_path));
|
||||||
let current_version = current_app_details['version'];
|
let current_version = current_app_details['version'];
|
||||||
|
let current_downloader = current_app_details['downloader'];
|
||||||
let stored_binary_path = current_app_details['path'];
|
let stored_binary_path = current_app_details['path'];
|
||||||
if (!stored_binary_path || typeof stored_binary_path !== 'string') {
|
if (!stored_binary_path || typeof stored_binary_path !== 'string') {
|
||||||
// logger.info(`INFO: Failed to get youtube-dl binary path at location: ${current_app_details_path}, attempting to guess actual path...`);
|
// logger.info(`INFO: Failed to get youtube-dl binary path at location: ${current_app_details_path}, attempting to guess actual path...`);
|
||||||
@@ -1374,15 +1391,9 @@ async function autoUpdateYoutubeDL() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// got version, now let's check the latest version from the youtube-dl API
|
// got version, now let's check the latest version from the youtube-dl API
|
||||||
let youtubedl_api_path = using_youtube_dlc ? youtube_dlc_tags_url : youtube_dl_tags_url;
|
|
||||||
|
|
||||||
if (default_downloader === 'youtube-dl') {
|
|
||||||
await downloadLatestYoutubeDLBinary('unknown', 'unknown');
|
|
||||||
resolve(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fetch(youtubedl_api_path, {method: 'Get'})
|
fetch(tags_url, {method: 'Get'})
|
||||||
.then(async res => res.json())
|
.then(async res => res.json())
|
||||||
.then(async (json) => {
|
.then(async (json) => {
|
||||||
// check if the versions are different
|
// check if the versions are different
|
||||||
@@ -1392,16 +1403,16 @@ async function autoUpdateYoutubeDL() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const latest_update_version = json[0]['name'];
|
const latest_update_version = json[0]['name'];
|
||||||
if (current_version !== latest_update_version) {
|
if (current_version !== latest_update_version || default_downloader !== current_downloader) {
|
||||||
// versions different, download new update
|
// versions different or different downloader is being used, download new update
|
||||||
logger.info(`Found new update for ${default_downloader}. Updating binary...`);
|
logger.info(`Found new update for ${default_downloader}. Updating binary...`);
|
||||||
try {
|
try {
|
||||||
await checkExistsWithTimeout(stored_binary_path, 10000);
|
await checkExistsWithTimeout(stored_binary_path, 10000);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
logger.error(`Failed to update ${default_downloader} - ${e}`);
|
logger.error(`Failed to update ${default_downloader} - ${e}`);
|
||||||
}
|
}
|
||||||
if (using_youtube_dlc) await downloadLatestYoutubeDLCBinary(latest_update_version);
|
|
||||||
else await downloadLatestYoutubeDLBinary(current_version, latest_update_version);
|
await download_sources[default_downloader]['func'](latest_update_version);
|
||||||
|
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
@@ -1415,19 +1426,15 @@ async function autoUpdateYoutubeDL() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadLatestYoutubeDLBinary(current_version, new_version) {
|
async function downloadLatestYoutubeDLBinary(new_version) {
|
||||||
return new Promise(resolve => {
|
const file_ext = is_windows ? '.exe' : '';
|
||||||
let binary_path = 'node_modules/youtube-dl/bin';
|
|
||||||
downloader(binary_path, function error(err, done) {
|
const download_url = `https://github.com/ytdl-org/youtube-dl/releases/latest/download/youtube-dl${file_ext}`;
|
||||||
if (err) {
|
const output_path = `node_modules/youtube-dl/bin/youtube-dl${file_ext}`;
|
||||||
logger.error(`youtube-dl failed to update. Restart the server to try again.`);
|
|
||||||
logger.error(err);
|
await fetchFile(download_url, output_path, `youtube-dl ${new_version}`);
|
||||||
resolve(false);
|
|
||||||
}
|
updateDetailsJSON(new_version, 'youtube-dl');
|
||||||
logger.info(`youtube-dl successfully updated!`);
|
|
||||||
resolve(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadLatestYoutubeDLCBinary(new_version) {
|
async function downloadLatestYoutubeDLCBinary(new_version) {
|
||||||
@@ -1438,13 +1445,34 @@ async function downloadLatestYoutubeDLCBinary(new_version) {
|
|||||||
|
|
||||||
await fetchFile(download_url, output_path, `youtube-dlc ${new_version}`);
|
await fetchFile(download_url, output_path, `youtube-dlc ${new_version}`);
|
||||||
|
|
||||||
const details_path = 'node_modules/youtube-dl/bin/details';
|
updateDetailsJSON(new_version, 'youtube-dlc');
|
||||||
const details_json = fs.readJSONSync('node_modules/youtube-dl/bin/details');
|
}
|
||||||
details_json['version'] = new_version;
|
|
||||||
|
|
||||||
|
async function downloadLatestYoutubeDLPBinary(new_version) {
|
||||||
|
const file_ext = is_windows ? '.exe' : '';
|
||||||
|
|
||||||
|
const download_url = `https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp${file_ext}`;
|
||||||
|
const output_path = `node_modules/youtube-dl/bin/youtube-dl${file_ext}`;
|
||||||
|
|
||||||
|
await fetchFile(download_url, output_path, `yt-dlp ${new_version}`);
|
||||||
|
|
||||||
|
updateDetailsJSON(new_version, 'yt-dlp');
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateDetailsJSON(new_version, downloader) {
|
||||||
|
const details_path = 'node_modules/youtube-dl/bin/details';
|
||||||
|
const details_json = fs.readJSONSync(details_path);
|
||||||
|
if (new_version) details_json['version'] = new_version;
|
||||||
|
details_json['downloader'] = downloader;
|
||||||
fs.writeJSONSync(details_path, details_json);
|
fs.writeJSONSync(details_path, details_json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCurrentDownloader() {
|
||||||
|
const details_path = 'node_modules/youtube-dl/bin/details';
|
||||||
|
const details_json = fs.readJSONSync(details_path);
|
||||||
|
return details_json['downloader'];
|
||||||
|
}
|
||||||
|
|
||||||
async function checkExistsWithTimeout(filePath, timeout) {
|
async function checkExistsWithTimeout(filePath, timeout) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
|||||||
@@ -326,8 +326,9 @@
|
|||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label><ng-container i18n="Default downloader select label">Select a downloader</ng-container></mat-label>
|
<mat-label><ng-container i18n="Default downloader select label">Select a downloader</ng-container></mat-label>
|
||||||
<mat-select color="accent" [(ngModel)]="new_config['Advanced']['default_downloader']">
|
<mat-select color="accent" [(ngModel)]="new_config['Advanced']['default_downloader']">
|
||||||
<mat-option value="youtube-dlc">youtube-dlc</mat-option>
|
|
||||||
<mat-option value="youtube-dl">youtube-dl</mat-option>
|
<mat-option value="youtube-dl">youtube-dl</mat-option>
|
||||||
|
<mat-option value="youtube-dlc">youtube-dlc</mat-option>
|
||||||
|
<mat-option value="yt-dlp">yt-dlp</mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user