mirror of
https://github.com/jely2002/youtube-dl-gui.git
synced 2021-11-01 22:46:21 +03:00
feat: add filename format customisation (#48)
This commit is contained in:
@@ -17,9 +17,9 @@ class DownloadQuery extends Query {
|
||||
|
||||
async connect() {
|
||||
let args = [];
|
||||
let output = path.join(this.environment.paths.downloadPath, this.environment.settings.nameFormat);
|
||||
if(this.video.audioOnly) {
|
||||
let numeralAudioQuality = (this.video.audioQuality === "best") ? "0" : "9";
|
||||
let output = path.join(this.environment.paths.downloadPath, "%(title).200s.%(ext)s") //.200 is to limit the max title length to 200 characters
|
||||
args = [
|
||||
'--extract-audio', '--audio-quality', numeralAudioQuality,
|
||||
'--audio-format', 'mp3',
|
||||
@@ -31,7 +31,6 @@ class DownloadQuery extends Query {
|
||||
];
|
||||
} else {
|
||||
if (this.video.formats.length !== 0) {
|
||||
let output = path.join(this.environment.paths.downloadPath, "%(title).200s-(%(height)sp%(fps).0d).%(ext)s");
|
||||
let format;
|
||||
if(this.video.videoOnly) {
|
||||
format = `bestvideo[height=${this.format.height}][fps=${this.format.fps}]/bestvideo[height=${this.format.height}]/best[height=${this.format.height}]/bestvideo/best`;
|
||||
@@ -52,7 +51,6 @@ class DownloadQuery extends Query {
|
||||
'--output-na-placeholder', ""
|
||||
];
|
||||
} else {
|
||||
let output = path.join(this.environment.paths.downloadPath, "%(title).200s-(%(height)sp%(fps).0d).%(ext)s")
|
||||
args = [
|
||||
"-o", output,
|
||||
'--ffmpeg-location', this.environment.paths.ffmpeg,
|
||||
|
||||
@@ -2,12 +2,14 @@ const os = require("os");
|
||||
const fs = require("fs").promises;
|
||||
|
||||
class Settings {
|
||||
constructor(paths, env, outputFormat, spoofUserAgent, taskList, sizeMode, splitMode, maxConcurrent, updateBinary, updateApplication, cookiePath, statSend, downloadMetadata, downloadThumbnail, keepUnmerged, calculateTotalSize, theme) {
|
||||
constructor(paths, env, outputFormat, spoofUserAgent, taskList, nameFormat, nameFormatMode, sizeMode, splitMode, maxConcurrent, updateBinary, updateApplication, cookiePath, statSend, downloadMetadata, downloadThumbnail, keepUnmerged, calculateTotalSize, theme) {
|
||||
this.paths = paths;
|
||||
this.env = env
|
||||
this.outputFormat = outputFormat == null ? "none" : outputFormat;
|
||||
this.spoofUserAgent = spoofUserAgent == null ? true : spoofUserAgent;
|
||||
this.taskList = taskList == null ? true : taskList;
|
||||
this.nameFormat = nameFormat == null ? "%(title).200s-(%(height)sp%(fps).0d).%(ext)s" : nameFormat;
|
||||
this.nameFormatMode = nameFormatMode == null ? "%(title).200s-(%(height)sp%(fps).0d).%(ext)s" : nameFormatMode;
|
||||
this.downloadMetadata = downloadMetadata == null ? true : downloadMetadata;
|
||||
this.downloadThumbnail = downloadThumbnail == null ? false : downloadThumbnail;
|
||||
this.keepUnmerged = keepUnmerged == null ? false : keepUnmerged;
|
||||
@@ -26,7 +28,7 @@ class Settings {
|
||||
try {
|
||||
let result = await fs.readFile(paths.settings, "utf8");
|
||||
let data = JSON.parse(result);
|
||||
return new Settings(paths, env, data.outputFormat, data.spoofUserAgent, data.taskList, data.sizeMode, data.splitMode, data.maxConcurrent, data.updateBinary, data.updateApplication, data.cookiePath, data.statSend, data.downloadMetadata, data.downloadThumbnail, data.keepUnmerged, data.calculateTotalSize, data.theme);
|
||||
return new Settings(paths, env, data.outputFormat, data.spoofUserAgent, data.taskList, data.nameFormat, data.nameFormatMode, data.sizeMode, data.splitMode, data.maxConcurrent, data.updateBinary, data.updateApplication, data.cookiePath, data.statSend, data.downloadMetadata, data.downloadThumbnail, data.keepUnmerged, data.calculateTotalSize, data.theme);
|
||||
} catch(err) {
|
||||
console.log(err);
|
||||
let settings = new Settings(paths, env);
|
||||
@@ -40,6 +42,8 @@ class Settings {
|
||||
this.outputFormat = settings.outputFormat;
|
||||
this.spoofUserAgent = settings.spoofUserAgent;
|
||||
this.taskList = settings.taskList;
|
||||
this.nameFormat = settings.nameFormat;
|
||||
this.nameFormatMode = settings.nameFormatMode;
|
||||
this.downloadMetadata = settings.downloadMetadata;
|
||||
this.downloadThumbnail = settings.downloadThumbnail;
|
||||
this.keepUnmerged = settings.keepUnmerged;
|
||||
@@ -64,6 +68,8 @@ class Settings {
|
||||
outputFormat: this.outputFormat,
|
||||
spoofUserAgent: this.spoofUserAgent,
|
||||
taskList: this.taskList,
|
||||
nameFormat: this.nameFormat,
|
||||
nameFormatMode: this.nameFormatMode,
|
||||
sizeMode: this.sizeMode,
|
||||
splitMode: this.splitMode,
|
||||
maxConcurrent: this.maxConcurrent,
|
||||
|
||||
@@ -27,7 +27,11 @@ class Video {
|
||||
} else {
|
||||
let fps = (this.formats[this.selected_format_index].fps != null) ? this.formats[this.selected_format_index].fps : "";
|
||||
let height = this.formats[this.selected_format_index].height;
|
||||
return (this.title.substr(0, 200) + "-(" + height + "p" + fps.toString().substr(0,2) + ")").replace(sanitizeRegex, "_");
|
||||
if(this.environment.settings.nameFormatMode === "%(title).200s-(%(height)sp%(fps).0d).%(ext)s") {
|
||||
return (this.title.substr(0, 200) + "-(" + height + "p" + fps.toString().substr(0,2) + ")").replace(sanitizeRegex, "_");
|
||||
} else if(this.environment.settings.nameFormatMode !== "custom") {
|
||||
return this.title.substr(0, 200).replace(sanitizeRegex, "_");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,6 +475,10 @@ option.audio {
|
||||
transition: 200ms;
|
||||
}
|
||||
|
||||
#nameFormatCustom {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
/* AUTH MODAL */
|
||||
#fileInput {
|
||||
cursor: pointer;
|
||||
|
||||
@@ -235,10 +235,21 @@
|
||||
<label for="outputFormat" class="form-label">Attempt to use output format:</label>
|
||||
<select class="custom-select d-block rounded w-auto mb-2" id="outputFormat">
|
||||
<option value="none" selected>Auto</option>
|
||||
<option value="mp4" selected>MP4</option>
|
||||
<option value="mp4">MP4</option>
|
||||
<option value="mkv">MKV</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<label for="nameFormat" class="form-label">Filename format:</label>
|
||||
<select class="custom-select d-block rounded w-auto mb-2" id="nameFormat">
|
||||
<option value="%(title).200s-(%(height)sp%(fps).0d).%(ext)s" selected>Title + quality</option>
|
||||
<option value="%(title).200s.%(ext)s">Title</option>
|
||||
<option value="custom">Custom</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<input id="nameFormatCustom" class="form-control" type="text" value="%(title).200s-(%(height)sp%(fps).0d).%(ext)s" disabled>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<input class="check-input" type="checkbox" value="" id="downloadMetadata">
|
||||
<label class="check-label" for="downloadMetadata">Save metadata</label>
|
||||
|
||||
@@ -124,6 +124,8 @@ async function init() {
|
||||
outputFormat: $('#outputFormat').val(),
|
||||
spoofUserAgent: $('#spoofUserAgent').prop('checked'),
|
||||
taskList: $('#taskList').prop('checked'),
|
||||
nameFormatMode: $('#nameFormat').val(),
|
||||
nameFormat: $('#nameFormatCustom').val(),
|
||||
downloadMetadata: $('#downloadMetadata').prop('checked'),
|
||||
downloadThumbnail: $('#downloadThumbnail').prop('checked'),
|
||||
keepUnmerged: $('#keepUnmerged').prop('checked'),
|
||||
@@ -142,12 +144,23 @@ async function init() {
|
||||
$('#concurrentLabel').html(`Max concurrent jobs <strong>(${$('#maxConcurrent').val()})</strong>`);
|
||||
})
|
||||
|
||||
$('#nameFormat').on('change', function() {
|
||||
const value = this.selectedOptions[0].value
|
||||
if(value !== "custom") {
|
||||
$('#nameFormatCustom').val(value).prop("disabled", true)
|
||||
} else {
|
||||
$('#nameFormatCustom').val(window.settings.nameFormat).prop("disabled", false)
|
||||
}
|
||||
})
|
||||
|
||||
$('#settingsBtn').on('click', () => {
|
||||
window.main.invoke("settingsAction", {action: "get"}).then((settings) => {
|
||||
$('#updateBinary').prop('checked', settings.updateBinary);
|
||||
$('#updateApplication').prop('checked', settings.updateApplication);
|
||||
$('#spoofUserAgent').prop('checked', settings.spoofUserAgent);
|
||||
$('#taskList').prop('checked', settings.taskList);
|
||||
$('#nameFormatCustom').val(settings.nameFormat);
|
||||
$('#nameFormat').val(settings.nameFormatMode);
|
||||
$('#outputFormat').val(settings.outputFormat);
|
||||
$('#downloadMetadata').prop('checked', settings.downloadMetadata);
|
||||
$('#downloadThumbnail').prop('checked', settings.downloadThumbnail);
|
||||
@@ -593,6 +606,7 @@ function updateProgress(args) {
|
||||
$(card).find('.progress-bar').attr('aria-valuenow', 100).css('width', "100%");
|
||||
$(card).find('.options').addClass("d-none").removeClass("d-flex");
|
||||
$(card).find('.open').addClass("d-flex");
|
||||
if(window.settings.nameFormatMode === "custom") $(card).find('.open .item').prop("disabled", true)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user