mirror of
https://github.com/jely2002/youtube-dl-gui.git
synced 2021-11-01 22:46:21 +03:00
feat: show audio codec selection for the video+audio option as well (#47)
This commit is contained in:
2
main.js
2
main.js
@@ -161,7 +161,7 @@ function startCriticalHandlers(env) {
|
||||
queryManager.saveThumb(args.url);
|
||||
break;
|
||||
case "getSize":
|
||||
return await queryManager.getSize(args.identifier, args.formatLabel, args.audioOnly, args.videoOnly, args.clicked, args.encoding);
|
||||
return await queryManager.getSize(args.identifier, args.formatLabel, args.audioOnly, args.videoOnly, args.clicked, args.encoding, args.audioEncoding);
|
||||
case "setSubtitles":
|
||||
queryManager.setSubtitle(args);
|
||||
break;
|
||||
|
||||
@@ -143,6 +143,7 @@ class QueryManager {
|
||||
downloadVideo(args) {
|
||||
let downloadVideo = this.getVideo(args.identifier);
|
||||
downloadVideo.selectedEncoding = args.encoding;
|
||||
downloadVideo.selectedAudioEncoding = args.audioEncoding;
|
||||
downloadVideo.audioOnly = args.type === "audio";
|
||||
downloadVideo.videoOnly = args.type === "videoOnly";
|
||||
if(!downloadVideo.audioOnly) {
|
||||
@@ -172,6 +173,7 @@ class QueryManager {
|
||||
for(const videoObj of args.videos) {
|
||||
let video = this.getVideo(videoObj.identifier);
|
||||
video.selectedEncoding = videoObj.encoding;
|
||||
video.selectedAudioEncoding = videoObj.audioEncoding;
|
||||
if(video.videos == null) {
|
||||
if(video.downloaded || video.type !== "single") continue;
|
||||
video.audioOnly = videoObj.type === "audio";
|
||||
@@ -263,9 +265,10 @@ class QueryManager {
|
||||
});
|
||||
}
|
||||
|
||||
async getSize(identifier, formatLabel, audioOnly, videoOnly, clicked, encoding) {
|
||||
async getSize(identifier, formatLabel, audioOnly, videoOnly, clicked, encoding, audioEncoding) {
|
||||
const video = this.getVideo(identifier);
|
||||
video.selectedEncoding = encoding;
|
||||
video.selectedAudioEncoding = audioEncoding;
|
||||
const cachedSize = this.getCachedSize(video, formatLabel, audioOnly, videoOnly);
|
||||
if(cachedSize != null) {
|
||||
//The size for this format was already looked up
|
||||
|
||||
@@ -30,9 +30,9 @@ class DownloadQuery extends Query {
|
||||
'-o', output,
|
||||
'--output-na-placeholder', ""
|
||||
];
|
||||
if(this.video.selectedEncoding !== "none") {
|
||||
if(this.video.selectedAudioEncoding !== "none") {
|
||||
args.push("-f");
|
||||
args.push("bestaudio[acodec=" + this.video.selectedEncoding + "]/bestaudio");
|
||||
args.push("bestaudio[acodec=" + this.video.selectedAudioEncoding + "]/bestaudio");
|
||||
}
|
||||
if(audioOutputFormat !== "none") {
|
||||
args.push('--audio-format', audioOutputFormat);
|
||||
@@ -43,16 +43,17 @@ class DownloadQuery extends Query {
|
||||
} else {
|
||||
if (this.video.formats.length !== 0) {
|
||||
let format;
|
||||
const encoding = this.video.selectedEncoding === "none" ? "" : "[vcodec=" + this.video.selectedEncoding + "]"
|
||||
const encoding = this.video.selectedEncoding === "none" ? "" : "[vcodec=" + this.video.selectedEncoding + "]";
|
||||
const audioEncoding = this.video.selectedAudioEncoding === "none" ? "" : "[acodec=" + this.video.selectedAudioEncoding + "]";
|
||||
if(this.video.videoOnly) {
|
||||
format = `bestvideo[height=${this.format.height}][fps=${this.format.fps}]${encoding}/bestvideo[height=${this.format.height}][fps=${this.format.fps}]/bestvideo[height=${this.format.height}]/best[height=${this.format.height}]/bestvideo/best`;
|
||||
if (this.format.fps == null) {
|
||||
format = `bestvideo[height=${this.format.height}]${encoding}/bestvideo[height=${this.format.height}]/best[height=${this.format.height}]/bestvideo/best`
|
||||
}
|
||||
} else {
|
||||
format = `bestvideo[height=${this.format.height}][fps=${this.format.fps}]${encoding}+${this.video.audioQuality}audio/bestvideo[height=${this.format.height}][fps=${this.format.fps}]+${this.video.audioQuality}audio/bestvideo[height=${this.format.height}]+${this.video.audioQuality}audio/best[height=${this.format.height}]/bestvideo+bestaudio/best`;
|
||||
format = `bestvideo[height=${this.format.height}][fps=${this.format.fps}]${encoding}+${this.video.audioQuality}audio${audioEncoding}/bestvideo[height=${this.format.height}][fps=${this.format.fps}]${encoding}+${this.video.audioQuality}audio/bestvideo[height=${this.format.height}][fps=${this.format.fps}]+${this.video.audioQuality}audio/bestvideo[height=${this.format.height}]+${this.video.audioQuality}audio/best[height=${this.format.height}]/bestvideo+bestaudio/best`;
|
||||
if (this.format.fps == null) {
|
||||
format = `bestvideo[height=${this.format.height}]${encoding}+${this.video.audioQuality}audio/bestvideo[height=${this.format.height}]+${this.video.audioQuality}audio/best[height=${this.format.height}]/bestvideo+bestaudio/best`
|
||||
format = `bestvideo[height=${this.format.height}]${encoding}+${this.video.audioQuality}audio${audioEncoding}/bestvideo[height=${this.format.height}]${encoding}+${this.video.audioQuality}audio/bestvideo[height=${this.format.height}]+${this.video.audioQuality}audio/best[height=${this.format.height}]/bestvideo+bestaudio/best`
|
||||
}
|
||||
}
|
||||
args = [
|
||||
|
||||
@@ -12,10 +12,19 @@ class SizeQuery extends Query {
|
||||
}
|
||||
|
||||
async connect() {
|
||||
const encoding = this.video.selectedEncoding === "none" ? "" : "[vcodec=" + this.video.selectedEncoding + "]"
|
||||
const encoding = this.video.selectedEncoding === "none" ? "" : "[vcodec=" + this.video.selectedEncoding + "]";
|
||||
const audioEncoding = this.video.selectedAudioEncoding === "none" ? "" : "[acodec=" + this.video.selectedAudioEncoding + "]";
|
||||
let formatArgument = `bestvideo[height=${this.format.height}][fps=${this.format.fps}]${encoding}+${this.audioQuality}audio/bestvideo[height=${this.format.height}][fps=${this.format.fps}]+${this.audioQuality}audio/bestvideo[height=${this.format.height}]+${this.audioQuality}audio/best[height=${this.format.height}]/bestvideo+bestaudio/best`;
|
||||
if (this.format.fps == null) {
|
||||
formatArgument = `bestvideo[height=${this.format.height}]${encoding}+${this.audioQuality}audio/bestvideo[height=${this.format.height}]+${this.audioQuality}audio/best[height=${this.format.height}]/bestvideo+bestaudio/best`;
|
||||
if(this.videoOnly) {
|
||||
formatArgument = `bestvideo[height=${this.format.height}][fps=${this.format.fps}]${encoding}/bestvideo[height=${this.format.height}][fps=${this.format.fps}]/bestvideo[height=${this.format.height}]/best[height=${this.format.height}]/bestvideo/best`;
|
||||
if (this.format.fps == null) {
|
||||
formatArgument = `bestvideo[height=${this.format.height}]${encoding}/bestvideo[height=${this.format.height}]/best[height=${this.format.height}]/bestvideo/best`
|
||||
}
|
||||
} else {
|
||||
formatArgument = `bestvideo[height=${this.format.height}][fps=${this.format.fps}]${encoding}+${this.video.audioQuality}audio${audioEncoding}/bestvideo[height=${this.format.height}][fps=${this.format.fps}]${encoding}+${this.video.audioQuality}audio/bestvideo[height=${this.format.height}][fps=${this.format.fps}]+${this.video.audioQuality}audio/bestvideo[height=${this.format.height}]+${this.video.audioQuality}audio/best[height=${this.format.height}]/bestvideo+bestaudio/best`;
|
||||
if (this.format.fps == null) {
|
||||
formatArgument = `bestvideo[height=${this.format.height}]${encoding}+${this.video.audioQuality}audio${audioEncoding}/bestvideo[height=${this.format.height}]${encoding}+${this.video.audioQuality}audio/bestvideo[height=${this.format.height}]+${this.video.audioQuality}audio/best[height=${this.format.height}]/bestvideo+bestaudio/best`
|
||||
}
|
||||
}
|
||||
if(this.audioOnly) {
|
||||
formatArgument = `bestvideo+${this.format}audio/bestvideo+bestaudio/best`;
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
<option value="videoOnly">Video only</option>
|
||||
</select>
|
||||
<select class="custom-select download-encoding">
|
||||
<option class="none" value="none" selected>Best codec</option>
|
||||
<option class="none" value="none" selected>Video codec</option>
|
||||
</select>
|
||||
<p class="metadata left"></p>
|
||||
</div>
|
||||
@@ -109,6 +109,9 @@
|
||||
<option class="audio" value="best" selected>Best</option>
|
||||
<option class="audio" value="worst">Worst</option>
|
||||
</select>
|
||||
<select class="custom-select download-audio-encoding">
|
||||
<option class="none" value="none" selected>Audio codec</option>
|
||||
</select>
|
||||
<p class="metadata right"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -311,6 +311,7 @@ async function init() {
|
||||
url: $(card).find('.url').val(),
|
||||
format: $(card).find('.custom-select.download-quality').val(),
|
||||
encoding: $(card).find('.custom-select.download-encoding').val(),
|
||||
audioEncoding: $(card).find('.custom-select.download-audio-encoding').val(),
|
||||
type: $(card).find('.custom-select.download-type').val(),
|
||||
downloadSubs: !$(card).find('.subtitle-btn i').hasClass("bi-card-text-strike")
|
||||
})
|
||||
@@ -319,6 +320,7 @@ async function init() {
|
||||
identifier: card.id,
|
||||
format: $(card).find('.custom-select.download-quality').val(),
|
||||
encoding: $(card).find('.custom-select.download-encoding').val(),
|
||||
audioEncoding: $(card).find('.custom-select.download-audio-encoding').val(),
|
||||
type: $(card).find('.custom-select.download-type').val(),
|
||||
downloadSubs: !$(card).find('.subtitle-btn i').hasClass("bi-card-text-strike")
|
||||
})
|
||||
@@ -469,8 +471,8 @@ function showToast(toastInfo) {
|
||||
|
||||
function updateEncodingDropdown(enabled) {
|
||||
$('.video-cards').children().each(function() {
|
||||
$(this).find('.metadata.left').toggle(!enabled);
|
||||
$(this).find('.custom-select.download-encoding').toggle(enabled);
|
||||
$(this).find('.metadata').toggle(!enabled);
|
||||
$(this).find('.custom-select.download-encoding, .custom-select.download-audio-encoding').toggle(enabled);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -534,9 +536,9 @@ async function addVideo(args) {
|
||||
$(template).find('.progress small').html("Setting up environment")
|
||||
$(template).find('.metadata.left').html('<strong>Duration: </strong>' + ((args.duration == null) ? "Unknown" : args.duration));
|
||||
if(window.settings.enableEncoding) {
|
||||
$(template).find('.metadata.left').hide();
|
||||
$(template).find('.metadata').hide();
|
||||
} else {
|
||||
$(template).find('.custom-select.download-encoding').hide();
|
||||
$(template).find('.custom-select.download-encoding, .custom-select.download-audio-encoding').hide();
|
||||
}
|
||||
|
||||
if(!args.hasFilesizes) {
|
||||
@@ -549,6 +551,7 @@ async function addVideo(args) {
|
||||
|
||||
$(template).find('.custom-select.download-type').on('change', function () {
|
||||
let isAudio = this.selectedOptions[0].value === "audio";
|
||||
disableEncodingDropdowns(this.selectedOptions[0].value, template);
|
||||
for(const elem of $(template).find('option')) {
|
||||
if($(elem).hasClass("video")) {
|
||||
$(elem).toggle(!isAudio)
|
||||
@@ -591,6 +594,7 @@ async function addVideo(args) {
|
||||
identifier: args.identifier,
|
||||
format: $(template).find('.custom-select.download-quality').val(),
|
||||
encoding: $(template).find('.custom-select.download-encoding').val(),
|
||||
audioEncoding: $(template).find('.custom-select.download-audio-encoding').val(),
|
||||
type: $(template).find('.custom-select.download-type').val(),
|
||||
downloadType: "single"
|
||||
}
|
||||
@@ -685,7 +689,7 @@ async function setUnifiedPlaylist(args) {
|
||||
$(card).find('.metadata.right').html('<strong>Playlist size: </strong>' + args.length);
|
||||
$(card).find('.metadata.left').html('<strong>Uploader: </strong>' + (args.uploader == null ? "Unknown" : args.uploader));
|
||||
if(window.settings.enableEncoding) {
|
||||
$(card).find('.metadata.left').hide();
|
||||
$(card).find('.metadata').hide();
|
||||
} else {
|
||||
$(card).find('.custom-select.download-encoding').hide();
|
||||
}
|
||||
@@ -707,6 +711,7 @@ async function setUnifiedPlaylist(args) {
|
||||
});
|
||||
|
||||
$(card).find('.custom-select.download-type').on('change', function () {
|
||||
disableEncodingDropdowns(this.selectedOptions[0].value, card);
|
||||
let isAudio = this.selectedOptions[0].value === "audio";
|
||||
for(const elem of $(card).find('option')) {
|
||||
if($(elem).hasClass("video")) {
|
||||
@@ -725,6 +730,7 @@ async function setUnifiedPlaylist(args) {
|
||||
format: $(card).find('.custom-select.download-quality').val(),
|
||||
type: $(card).find('.custom-select.download-type').val(),
|
||||
encoding: $(card).find('.custom-select.download-encoding').val(),
|
||||
audioEncoding: $(card).find('.custom-select.download-audio-encoding').val(),
|
||||
downloadType: "unified"
|
||||
}
|
||||
window.main.invoke("videoAction", downloadArgs);
|
||||
@@ -756,8 +762,7 @@ function setCodecs(card, audioCodecs, formats) {
|
||||
//Add the audio encoding
|
||||
for(const audioCodec of audioCodecs) {
|
||||
let codecOption = new Option(audioCodec, audioCodec);
|
||||
$(card).find('.custom-select.download-encoding').append(codecOption);
|
||||
$(codecOption).addClass("audio");
|
||||
$(card).find('.custom-select.download-audio-encoding').append(codecOption);
|
||||
}
|
||||
|
||||
for(const format of formats) {
|
||||
@@ -778,9 +783,7 @@ function setCodecs(card, audioCodecs, formats) {
|
||||
function updateCodecs(card, newValue) {
|
||||
const encodingValue = $(card).find('.custom-select.download-encoding :selected').val();
|
||||
for(const elem of $(card).find('.custom-select.download-encoding option')) {
|
||||
if($(elem).hasClass("audio") && (newValue === "best" || newValue === "worst")) {
|
||||
$(elem).show();
|
||||
} else if($(elem).hasClass(newValue)) {
|
||||
if($(elem).hasClass(newValue)) {
|
||||
$(elem).show();
|
||||
} else if(!$(elem).hasClass("none")) {
|
||||
$(elem).hide();
|
||||
@@ -890,6 +893,7 @@ function updateSize(identifier, clicked) {
|
||||
identifier: identifier,
|
||||
formatLabel: formatLabel,
|
||||
encoding: $(card).find('.custom-select.download-encoding').val(),
|
||||
audioEncoding: $(card).find('.custom-select.download-audio-encoding').val(),
|
||||
audioOnly: $(card).find('.custom-select.download-type').val() === "audio",
|
||||
videoOnly: $(card).find('.custom-select.download-type').val() === "videoOnly",
|
||||
clicked: clicked
|
||||
@@ -943,6 +947,7 @@ async function updateVideoSettings(identifier) {
|
||||
$('#download-quality').val("best");
|
||||
$(card).find('.custom-select.download-quality').val($(card).find(`.custom-select.download-quality option.${classValue}:first`).val());
|
||||
}
|
||||
disableEncodingDropdowns(typeValue, card);
|
||||
for(const elem of $(card).find('option')) {
|
||||
if($(elem).hasClass("video")) {
|
||||
$(elem).toggle(!isAudio)
|
||||
@@ -960,6 +965,13 @@ async function updateVideoSettings(identifier) {
|
||||
}
|
||||
}
|
||||
|
||||
function disableEncodingDropdowns(typeValue, card) {
|
||||
let isAudio = typeValue === "audio";
|
||||
let isVideoOnly = typeValue === "videoOnly";
|
||||
$(card).find(".custom-select.download-encoding").prop("disabled", isAudio && !isVideoOnly);
|
||||
$(card).find(".custom-select.download-audio-encoding").prop("disabled", !isAudio && isVideoOnly);
|
||||
}
|
||||
|
||||
function updateAllVideoSettings() {
|
||||
let isAudio = $('#download-type').val() === "audio";
|
||||
for(const elem of $('#download-quality option')) {
|
||||
|
||||
Reference in New Issue
Block a user