Merge pull request #138 from NebelNidas/auto-audio

Add `auto` file format option for audio-only downloads
This commit is contained in:
Jelle Glebbeek
2021-07-17 17:54:00 +02:00
committed by GitHub
7 changed files with 36 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
const Query = require("../types/Query")
const path = require("path")
const fs = require("fs");
const Utils = require("../Utils")
class DownloadQuery extends Query {
@@ -24,13 +25,15 @@ class DownloadQuery extends Query {
const audioOutputFormat = this.environment.settings.audioOutputFormat;
args = [
'--extract-audio', '--audio-quality', numeralAudioQuality,
'--audio-format', audioOutputFormat,
'--ffmpeg-location', this.environment.paths.ffmpeg,
'--no-mtime',
'-o', output,
'--output-na-placeholder', ""
];
if(audioOutputFormat === "m4a" || audioOutputFormat === "mp3") {
if(audioOutputFormat !== "none") {
args.push('--audio-format', audioOutputFormat);
}
if(audioOutputFormat === "m4a" || audioOutputFormat === "mp3" || audioOutputFormat === "none") {
args.push("--embed-thumbnail");
}
} else {
@@ -118,7 +121,26 @@ class DownloadQuery extends Query {
this.environment.errorHandler.checkError(exception, this.video.identifier);
return exception;
}
if(this.environment.settings.audioOutputFormat === "none") {
await this.removeThumbnail();
}
return result;
}
async removeThumbnail() {
const filename = this.video.filename;
if(filename != null) {
const filenameExt = path.basename(filename, path.extname(filename)) + ".jpg";
const filenameAbs = path.join(this.video.downloadedPath, filenameExt);
try {
await fs.promises.unlink(filenameAbs);
} catch(e) {
console.error("Unable to remove failed image embed.");
console.error(filenameExt);
console.error(filenameAbs);
}
}
}
}
module.exports = DownloadQuery;

View File

@@ -28,6 +28,7 @@ class ErrorHandler {
for(const trigger of errorDef.trigger) {
if(stderr.includes(trigger)) {
if(errorDef.code === "ffmpeg not found" && process.argv[2] === '--dev') return false; //Do not raise a 'ffmpeg not found' error when in dev mode
if(errorDef.code === "Thumbnail embedding not supported") return false; //Do not raise an error when thumbnails can't be embedded due to unsupported container
foundError = true;
errorDef.trigger = trigger;
this.raiseError(errorDef, identifier);
@@ -36,6 +37,7 @@ class ErrorHandler {
}
} else if(stderr.includes(errorDef.trigger)) {
if(errorDef.code === "ffmpeg not found" && process.argv[2] === '--dev') return false; //Do not raise a 'ffmpeg not found' error when in dev mode
if(errorDef.code === "Thumbnail embedding not supported") return false; //Do not raise an error when thumbnails can't be embedded due to unsupported container
foundError = true;
this.raiseError(errorDef, identifier);
break;

View File

@@ -257,5 +257,10 @@
"code": "Livestream not started yet",
"description": "Wait for the livestream to start.",
"trigger": "This live event will begin in a few moments."
},
{
"code": "Thumbnail embedding not supported",
"description": "Only mp3 and m4a/mp4 are supported for thumbnail embedding for now.",
"trigger": "ERROR: Only mp3 and m4a/mp4 are supported for thumbnail embedding for now."
}
]

View File

@@ -6,7 +6,7 @@ class Settings {
this.paths = paths;
this.env = env
this.outputFormat = outputFormat == null ? "none" : outputFormat;
this.audioOutputFormat = audioOutputFormat == null ? "mp3" : audioOutputFormat;
this.audioOutputFormat = audioOutputFormat == null ? "none" : audioOutputFormat;
this.downloadPath = downloadPath == null ? env.app.getPath("downloads") : downloadPath;
this.proxy = proxy == null ? "" : proxy;
this.autoFillClipboard = autoFillClipboard == null ? true : autoFillClipboard;

View File

@@ -298,7 +298,8 @@
<div class="mb-3">
<label for="audioOutputFormat" class="form-label">Force audio-only downloads to use output format:</label>
<select class="custom-select d-block rounded w-auto mb-2" id="audioOutputFormat">
<option value="mp3" selected>MP3</option>
<option value="none" selected>Auto</option>
<option value="mp3">MP3</option>
<option value="m4a">M4A</option>
<option value="opus">Opus</option>
<option value="vorbis">Vorbis</option>

View File

@@ -3,7 +3,7 @@ const os = require("os");
const Settings = require('../modules/persistence/Settings');
const env = {version: "2.0.0-test1", app: {getPath: jest.fn().mockReturnValue("test/path")}};
const defaultSettingsInstance = new Settings({settings: "tests/test-settings.json"}, env, "none", "mp3", "test/path", "", true, true, false, true, "%(title).200s-(%(height)sp%(fps).0d).%(ext)s", "%(title).200s-(%(height)sp%(fps).0d).%(ext)s", "click", "49", 8, true, true, "C:\\Users\\user\\cookies.txt", false, true, false, false, true, "dark");
const defaultSettings = "{\"outputFormat\":\"none\",\"audioOutputFormat\":\"mp3\",\"downloadPath\":\"test/path\",\"proxy\":\"\",\"autoFillClipboard\":true,\"spoofUserAgent\":true,\"validateCertificate\":false,\"taskList\":true,\"nameFormat\":\"%(title).200s-(%(height)sp%(fps).0d).%(ext)s\",\"nameFormatMode\":\"%(title).200s-(%(height)sp%(fps).0d).%(ext)s\",\"sizeMode\":\"click\",\"splitMode\":\"49\",\"maxConcurrent\":8,\"defaultConcurrent\":8,\"updateBinary\":true,\"updateApplication\":true,\"statSend\":false,\"downloadMetadata\":true,\"downloadThumbnail\":false,\"keepUnmerged\":false,\"calculateTotalSize\":true,\"theme\":\"dark\",\"version\":\"2.0.0-test1\"}"
const defaultSettings = "{\"outputFormat\":\"none\",\"audioOutputFormat\":\"none\",\"downloadPath\":\"test/path\",\"proxy\":\"\",\"autoFillClipboard\":true,\"spoofUserAgent\":true,\"validateCertificate\":false,\"taskList\":true,\"nameFormat\":\"%(title).200s-(%(height)sp%(fps).0d).%(ext)s\",\"nameFormatMode\":\"%(title).200s-(%(height)sp%(fps).0d).%(ext)s\",\"sizeMode\":\"click\",\"splitMode\":\"49\",\"maxConcurrent\":8,\"defaultConcurrent\":8,\"updateBinary\":true,\"updateApplication\":true,\"statSend\":false,\"downloadMetadata\":true,\"downloadThumbnail\":false,\"keepUnmerged\":false,\"calculateTotalSize\":true,\"theme\":\"dark\",\"version\":\"2.0.0-test1\"}"
describe('Load settings from file', () => {
beforeEach(() => {

View File

@@ -1 +1 @@
{"outputFormat":"none","audioOutputFormat":"mp3","downloadPath": "test/path","proxy": "","autoFillClipboard":true,"spoofUserAgent":true,"validateCertificate": false,"taskList":true,"nameFormat":"%(title).200s-(%(height)sp%(fps).0d).%(ext)s","nameFormatMode":"%(title).200s-(%(height)sp%(fps).0d).%(ext)s","sizeMode":"click","splitMode":"49","maxConcurrent":8,"defaultConcurrent":8,"updateBinary":true,"updateApplication":true,"cookiePath":"C:\\Users\\user\\cookies.txt","statSend":false,"downloadMetadata":true,"downloadThumbnail":false,"keepUnmerged":false,"calculateTotalSize":true,"theme": "dark","version":"2.0.0-test1"}
{"outputFormat":"none","audioOutputFormat":"none","downloadPath": "test/path","proxy": "","autoFillClipboard":true,"spoofUserAgent":true,"validateCertificate": false,"taskList":true,"nameFormat":"%(title).200s-(%(height)sp%(fps).0d).%(ext)s","nameFormatMode":"%(title).200s-(%(height)sp%(fps).0d).%(ext)s","sizeMode":"click","splitMode":"49","maxConcurrent":8,"defaultConcurrent":8,"updateBinary":true,"updateApplication":true,"cookiePath":"C:\\Users\\user\\cookies.txt","statSend":false,"downloadMetadata":true,"downloadThumbnail":false,"keepUnmerged":false,"calculateTotalSize":true,"theme": "dark","version":"2.0.0-test1"}