mirror of
https://github.com/jely2002/youtube-dl-gui.git
synced 2021-11-01 22:46:21 +03:00
feat: add option to automatically save metadata as JSON (#164)
This commit is contained in:
@@ -160,6 +160,7 @@ class QueryManager {
|
||||
downloadVideo.query.connect().then(() => {
|
||||
//Backup done call, sometimes it does not trigger automatically from within the downloadQuery.
|
||||
if(downloadVideo.error) return;
|
||||
if(this.environment.settings.downloadJsonMetadata) this.saveInfo(downloadVideo.identifier, false);
|
||||
downloadVideo.downloaded = true;
|
||||
downloadVideo.query.progressBar.done(downloadVideo.audioOnly);
|
||||
this.updateGlobalButtons();
|
||||
@@ -467,17 +468,22 @@ class QueryManager {
|
||||
this.window.webContents.send("videoAction", args);
|
||||
}
|
||||
|
||||
async saveInfo(identifier) {
|
||||
let video = this.getVideo(identifier);
|
||||
let result = await dialog.showSaveDialog(this.window, {
|
||||
defaultPath: path.join(this.environment.settings.downloadPath, "metadata_" + video.url.slice(-11)),
|
||||
buttonLabel: "Save metadata",
|
||||
filters: [
|
||||
{ name: "JSON", extensions: ["json"] },
|
||||
{ name: "All Files", extensions: ["*"] },
|
||||
],
|
||||
properties: ["createDirectory"]
|
||||
});
|
||||
async saveInfo(infoVideo, askPath=true) {
|
||||
let video = infoVideo;
|
||||
if(video.url == null) video = this.getVideo(infoVideo);
|
||||
if (video.url == null) return;
|
||||
let result = { filePath: path.join(this.environment.settings.downloadPath, "metadata_" + video.url.slice(-11)) + ".json", };
|
||||
if (askPath) {
|
||||
result = await dialog.showSaveDialog(this.window, {
|
||||
defaultPath: path.join(this.environment.settings.downloadPath, "metadata_" + video.url.slice(-11)),
|
||||
buttonLabel: "Save metadata",
|
||||
filters: [
|
||||
{name: "JSON", extensions: ["json"]},
|
||||
{name: "All Files", extensions: ["*"]},
|
||||
],
|
||||
properties: ["createDirectory"]
|
||||
});
|
||||
}
|
||||
if(!result.canceled) {
|
||||
fs.writeFileSync(result.filePath, JSON.stringify(video.serialize(), null, 3));
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ class DownloadQueryList {
|
||||
}
|
||||
this.progressBar.updatePlaylist(this.done - this.cancelled, this.length - this.cancelled);
|
||||
if(!video.error) {
|
||||
if(this.environment.settings.downloadJsonMetadata) this.manager.saveInfo(video, false);
|
||||
video.downloaded = true;
|
||||
video.query.progressBar.done(video.audioOnly);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ class Settings {
|
||||
proxy, rateLimit, autoFillClipboard, noPlaylist, globalShortcut, userAgent,
|
||||
validateCertificate, enableEncoding, taskList, nameFormat, nameFormatMode,
|
||||
sizeMode, splitMode, maxConcurrent, updateBinary, downloadType, updateApplication, cookiePath,
|
||||
statSend, downloadMetadata, downloadThumbnail, keepUnmerged, calculateTotalSize, theme
|
||||
statSend, downloadMetadata, downloadJsonMetadata, downloadThumbnail, keepUnmerged,
|
||||
calculateTotalSize, theme
|
||||
) {
|
||||
this.paths = paths;
|
||||
this.env = env
|
||||
@@ -27,6 +28,7 @@ class Settings {
|
||||
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.downloadJsonMetadata = downloadJsonMetadata == null ? false : downloadJsonMetadata;
|
||||
this.downloadThumbnail = downloadThumbnail == null ? false : downloadThumbnail;
|
||||
this.keepUnmerged = keepUnmerged == null ? false : keepUnmerged;
|
||||
this.calculateTotalSize = calculateTotalSize == null ? true : calculateTotalSize;
|
||||
@@ -72,6 +74,7 @@ class Settings {
|
||||
data.cookiePath,
|
||||
data.statSend,
|
||||
data.downloadMetadata,
|
||||
data.downloadJsonMetadata,
|
||||
data.downloadThumbnail,
|
||||
data.keepUnmerged,
|
||||
data.calculateTotalSize,
|
||||
@@ -101,6 +104,7 @@ class Settings {
|
||||
this.nameFormat = settings.nameFormat;
|
||||
this.nameFormatMode = settings.nameFormatMode;
|
||||
this.downloadMetadata = settings.downloadMetadata;
|
||||
this.downloadJsonMetadata = settings.downloadJsonMetadata;
|
||||
this.downloadThumbnail = settings.downloadThumbnail;
|
||||
this.keepUnmerged = settings.keepUnmerged;
|
||||
this.calculateTotalSize = settings.calculateTotalSize;
|
||||
@@ -147,6 +151,7 @@ class Settings {
|
||||
cookiePath: this.cookiePath,
|
||||
statSend: this.statSend,
|
||||
downloadMetadata: this.downloadMetadata,
|
||||
downloadJsonMetadata: this.downloadJsonMetadata,
|
||||
downloadThumbnail: this.downloadThumbnail,
|
||||
keepUnmerged: this.keepUnmerged,
|
||||
calculateTotalSize: this.calculateTotalSize,
|
||||
|
||||
@@ -373,6 +373,10 @@
|
||||
<input class="check-input" type="checkbox" value="" id="downloadMetadata">
|
||||
<label class="check-label" for="downloadMetadata">Save metadata</label>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<input class="check-input" type="checkbox" value="" id="downloadJsonMetadata">
|
||||
<label class="check-label" for="downloadJsonMetadata">Save JSON metadata</label>
|
||||
</div>
|
||||
<div class="mb-1">
|
||||
<input class="check-input" type="checkbox" value="" id="downloadThumbnail">
|
||||
<label class="check-label" for="downloadThumbnail">Save thumbnail as file</label>
|
||||
|
||||
@@ -992,6 +992,7 @@ async function getSettings() {
|
||||
$('#outputFormat').val(settings.outputFormat);
|
||||
$('#audioOutputFormat').val(settings.audioOutputFormat);
|
||||
$('#downloadMetadata').prop('checked', settings.downloadMetadata);
|
||||
$('#downloadJsonMetadata').prop('checked', settings.downloadJsonMetadata);
|
||||
$('#downloadThumbnail').prop('checked', settings.downloadThumbnail);
|
||||
$('#keepUnmerged').prop('checked', settings.keepUnmerged);
|
||||
$('#calculateTotalSize').prop('checked', settings.calculateTotalSize);
|
||||
@@ -1021,6 +1022,7 @@ function sendSettings() {
|
||||
nameFormatMode: $('#nameFormat').val(),
|
||||
nameFormat: $('#nameFormatCustom').val(),
|
||||
downloadMetadata: $('#downloadMetadata').prop('checked'),
|
||||
downloadJsonMetadata: $('#downloadJsonMetadata').prop('checked'),
|
||||
downloadThumbnail: $('#downloadThumbnail').prop('checked'),
|
||||
keepUnmerged: $('#keepUnmerged').prop('checked'),
|
||||
calculateTotalSize: $('#calculateTotalSize').prop('checked'),
|
||||
|
||||
@@ -2,8 +2,8 @@ const fs = require('fs').promises;
|
||||
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", "none", "test/path", "", "", true, false, true, "spoof", false, false, true, "%(title).200s-(%(height)sp%(fps).0d).%(ext)s", "%(title).200s-(%(height)sp%(fps).0d).%(ext)s", "click", "49", 8, true, "video", true, "C:\\Users\\user\\cookies.txt", false, true, false, false, true, "dark");
|
||||
const defaultSettings = "{\"outputFormat\":\"none\",\"audioOutputFormat\":\"none\",\"downloadPath\":\"test/path\",\"proxy\":\"\",\"rateLimit\":\"\",\"autoFillClipboard\":true,\"noPlaylist\":false,\"globalShortcut\":true,\"userAgent\":\"spoof\",\"validateCertificate\":false,\"enableEncoding\":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,\"downloadType\":\"video\",\"updateApplication\":true,\"statSend\":false,\"downloadMetadata\":true,\"downloadThumbnail\":false,\"keepUnmerged\":false,\"calculateTotalSize\":true,\"theme\":\"dark\",\"version\":\"2.0.0-test1\"}"
|
||||
const defaultSettingsInstance = new Settings({settings: "tests/test-settings.json"}, env, "none", "none", "test/path", "", "", true, false, true, "spoof", false, false, true, "%(title).200s-(%(height)sp%(fps).0d).%(ext)s", "%(title).200s-(%(height)sp%(fps).0d).%(ext)s", "click", "49", 8, true, "video", true, "C:\\Users\\user\\cookies.txt", false, true, false, false, false, true, "dark");
|
||||
const defaultSettings = "{\"outputFormat\":\"none\",\"audioOutputFormat\":\"none\",\"downloadPath\":\"test/path\",\"proxy\":\"\",\"rateLimit\":\"\",\"autoFillClipboard\":true,\"noPlaylist\":false,\"globalShortcut\":true,\"userAgent\":\"spoof\",\"validateCertificate\":false,\"enableEncoding\":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,\"downloadType\":\"video\",\"updateApplication\":true,\"statSend\":false,\"downloadMetadata\":true,\"downloadJsonMetadata\":false,\"downloadThumbnail\":false,\"keepUnmerged\":false,\"calculateTotalSize\":true,\"theme\":\"dark\",\"version\":\"2.0.0-test1\"}"
|
||||
|
||||
describe('Load settings from file', () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"outputFormat":"none","audioOutputFormat":"none","downloadPath": "test/path","proxy": "","rateLimit": "","autoFillClipboard":true,"noPlaylist": false,"globalShortcut":true,"userAgent":"spoof","validateCertificate": false,"enableEncoding": 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,"downloadType":"video","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": "","rateLimit": "","autoFillClipboard":true,"noPlaylist": false,"globalShortcut":true,"userAgent":"spoof","validateCertificate": false,"enableEncoding": 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,"downloadType":"video","updateApplication":true,"cookiePath":"C:\\Users\\user\\cookies.txt","statSend":false,"downloadMetadata":true,"downloadJsonMetadata":false,"downloadThumbnail":false,"keepUnmerged":false,"calculateTotalSize":true,"theme": "dark","version":"2.0.0-test1"}
|
||||
|
||||
Reference in New Issue
Block a user