mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-16 06:41:29 +03:00
Added ability to use youtube-dl forks
Downloader now defaults to youtube-dlc because of the recent DMCA requests
This commit is contained in:
@@ -155,8 +155,8 @@ if (just_restarted) {
|
|||||||
fs.unlinkSync('restart.json');
|
fs.unlinkSync('restart.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
// updates & starts youtubedl
|
// updates & starts youtubedl (commented out b/c of repo takedown)
|
||||||
startYoutubeDL();
|
// startYoutubeDL();
|
||||||
|
|
||||||
var validDownloadingAgents = [
|
var validDownloadingAgents = [
|
||||||
'aria2c',
|
'aria2c',
|
||||||
@@ -558,6 +558,9 @@ async function loadConfig() {
|
|||||||
// creates archive path if missing
|
// creates archive path if missing
|
||||||
await fs.ensureDir(archivePath);
|
await fs.ensureDir(archivePath);
|
||||||
|
|
||||||
|
// now this is done here due to youtube-dl's repo takedown
|
||||||
|
await startYoutubeDL();
|
||||||
|
|
||||||
// get subscriptions
|
// get subscriptions
|
||||||
if (allowSubscriptions) {
|
if (allowSubscriptions) {
|
||||||
// runs initially, then runs every ${subscriptionCheckInterval} seconds
|
// runs initially, then runs every ${subscriptionCheckInterval} seconds
|
||||||
@@ -1613,12 +1616,16 @@ function checkDownloadPercent(download) {
|
|||||||
|
|
||||||
async function startYoutubeDL() {
|
async function startYoutubeDL() {
|
||||||
// auto update youtube-dl
|
// auto update youtube-dl
|
||||||
if (!debugMode) await autoUpdateYoutubeDL();
|
await autoUpdateYoutubeDL();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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() {
|
||||||
return new Promise(resolve => {
|
return new Promise(async resolve => {
|
||||||
|
const default_downloader = config_api.getConfigItem('ytdl_default_downloader');
|
||||||
|
const using_youtube_dlc = default_downloader === 'youtube-dlc';
|
||||||
|
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);
|
||||||
@@ -1645,42 +1652,69 @@ 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 = 'https://api.github.com/repos/ytdl-org/youtube-dl/tags';
|
let youtubedl_api_path = using_youtube_dlc ? youtube_dlc_tags_url : youtube_dl_tags_url;
|
||||||
fetch(youtubedl_api_path, {method: 'Get'})
|
fetch(youtubedl_api_path, {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
|
||||||
if (!json || !json[0]) {
|
if (!json || !json[0]) {
|
||||||
|
logger.error(`Failed to check ${default_downloader} version for an update.`)
|
||||||
resolve(false);
|
resolve(false);
|
||||||
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) {
|
||||||
let binary_path = 'node_modules/youtube-dl/bin';
|
|
||||||
// versions different, download new update
|
// versions different, download new update
|
||||||
logger.info('Found new update for youtube-dl. 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 youtube-dl - ${e}`);
|
logger.error(`Failed to update ${default_downloader} - ${e}`);
|
||||||
}
|
}
|
||||||
downloader(binary_path, function error(err, done) {
|
if (using_youtube_dlc) await downloadLatestYoutubeDLCBinary(latest_update_version);
|
||||||
if (err) {
|
else await downloadLatestYoutubeDLBinary(current_version, latest_update_version);
|
||||||
logger.error(err);
|
|
||||||
resolve(false);
|
resolve(true);
|
||||||
}
|
} else {
|
||||||
logger.info(`Binary successfully updated: ${current_version} -> ${latest_update_version}`);
|
resolve(false);
|
||||||
resolve(true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
logger.error('Failed to check youtube-dl version for an update.')
|
logger.error(`Failed to check ${default_downloader} version for an update.`)
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function downloadLatestYoutubeDLBinary(current_version, new_version) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
let binary_path = 'node_modules/youtube-dl/bin';
|
||||||
|
downloader(binary_path, function error(err, done) {
|
||||||
|
if (err) {
|
||||||
|
logger.error(err);
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
logger.info(`youtube-dl successfully updated: ${current_version} -> ${new_version}`);
|
||||||
|
resolve(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadLatestYoutubeDLCBinary(new_version) {
|
||||||
|
const file_ext = is_windows ? '.exe' : '';
|
||||||
|
|
||||||
|
const download_url = `https://github.com/blackjack4494/yt-dlc/releases/latest/download/youtube-dlc${file_ext}`;
|
||||||
|
const output_path = `node_modules/youtube-dl/bin/youtube-dl${file_ext}`;
|
||||||
|
|
||||||
|
await fetchFile(download_url, output_path, `youtube-dlc ${new_version}`);
|
||||||
|
|
||||||
|
const details_path = 'node_modules/youtube-dl/bin/details';
|
||||||
|
const details_json = fs.readJSONSync('node_modules/youtube-dl/bin/details');
|
||||||
|
details_json['version'] = new_version;
|
||||||
|
|
||||||
|
fs.writeJSONSync(details_path, details_json);
|
||||||
|
}
|
||||||
|
|
||||||
async function checkExistsWithTimeout(filePath, timeout) {
|
async function checkExistsWithTimeout(filePath, timeout) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
|||||||
@@ -226,6 +226,7 @@ DEFAULT_CONFIG = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Advanced": {
|
"Advanced": {
|
||||||
|
"default_downloader": "youtube-dlc",
|
||||||
"use_default_downloading_agent": true,
|
"use_default_downloading_agent": true,
|
||||||
"custom_downloading_agent": "",
|
"custom_downloading_agent": "",
|
||||||
"multi_user_mode": false,
|
"multi_user_mode": false,
|
||||||
|
|||||||
@@ -130,6 +130,10 @@ let CONFIG_ITEMS = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Advanced
|
// Advanced
|
||||||
|
'ytdl_default_downloader': {
|
||||||
|
'key': 'ytdl_default_downloader',
|
||||||
|
'path': 'YoutubeDLMaterial.Advanced.default_downloader'
|
||||||
|
},
|
||||||
'ytdl_use_default_downloading_agent': {
|
'ytdl_use_default_downloading_agent': {
|
||||||
'key': 'ytdl_use_default_downloading_agent',
|
'key': 'ytdl_use_default_downloading_agent',
|
||||||
'path': 'YoutubeDLMaterial.Advanced.use_default_downloading_agent'
|
'path': 'YoutubeDLMaterial.Advanced.use_default_downloading_agent'
|
||||||
|
|||||||
@@ -258,11 +258,20 @@
|
|||||||
<div *ngIf="new_config" class="container-fluid">
|
<div *ngIf="new_config" class="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 mt-3">
|
<div class="col-12 mt-3">
|
||||||
|
<mat-form-field>
|
||||||
|
<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-option value="youtube-dlc">youtube-dlc</mat-option>
|
||||||
|
<mat-option value="youtube-dl">youtube-dl</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 mt-1">
|
||||||
<mat-checkbox color="accent" [(ngModel)]="new_config['Advanced']['use_default_downloading_agent']"><ng-container i18n="Use default downloading agent setting">Use default downloading agent</ng-container></mat-checkbox>
|
<mat-checkbox color="accent" [(ngModel)]="new_config['Advanced']['use_default_downloading_agent']"><ng-container i18n="Use default downloading agent setting">Use default downloading agent</ng-container></mat-checkbox>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label><ng-container i18n="Custom downloader select label">Select a downloader</ng-container></mat-label>
|
<mat-label><ng-container i18n="Custom downloader select label">Select a download agent</ng-container></mat-label>
|
||||||
<mat-select [disabled]="new_config['Advanced']['use_default_downloading_agent']" color="accent" [(ngModel)]="new_config['Advanced']['custom_downloading_agent']">
|
<mat-select [disabled]="new_config['Advanced']['use_default_downloading_agent']" color="accent" [(ngModel)]="new_config['Advanced']['custom_downloading_agent']">
|
||||||
<mat-option value="aria2c">aria2c</mat-option>
|
<mat-option value="aria2c">aria2c</mat-option>
|
||||||
<mat-option value="avconv">avconv</mat-option>
|
<mat-option value="avconv">avconv</mat-option>
|
||||||
@@ -274,7 +283,7 @@
|
|||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 mt-2 mb-1">
|
<div class="col-12 mt-2">
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label><ng-container i18n="Log Level label">Log Level</ng-container></mat-label>
|
<mat-label><ng-container i18n="Log Level label">Log Level</ng-container></mat-label>
|
||||||
<mat-select color="accent" [(ngModel)]="new_config['Advanced']['logger_level']">
|
<mat-select color="accent" [(ngModel)]="new_config['Advanced']['logger_level']">
|
||||||
@@ -286,7 +295,7 @@
|
|||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 mt-2 mb-1">
|
<div class="col-12 mb-1">
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label><ng-container i18n="Login expiration select label">Login expiration</ng-container></mat-label>
|
<mat-label><ng-container i18n="Login expiration select label">Login expiration</ng-container></mat-label>
|
||||||
<mat-select color="accent" [(ngModel)]="new_config['Advanced']['jwt_expiration']">
|
<mat-select color="accent" [(ngModel)]="new_config['Advanced']['jwt_expiration']">
|
||||||
|
|||||||
Reference in New Issue
Block a user