From 93aa1f4db47a4f77a15baeb5d34ea5d4c946ba76 Mon Sep 17 00:00:00 2001 From: dumbmoron <136796770+dumbmoron@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:31:39 +0000 Subject: [PATCH] add option to disable file metadata closes #142 --- docs/API.md | 1 + src/front/cobalt.js | 4 +++- src/localization/languages/en.json | 1 + src/localization/languages/ru.json | 1 + src/modules/pageRender/page.js | 4 ++++ src/modules/processing/match.js | 4 ++-- src/modules/processing/matchActionDecider.js | 6 +++--- src/modules/sub/utils.js | 5 +++-- 8 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/API.md b/docs/API.md index 7c2a5b34..69c5fb3f 100644 --- a/docs/API.md +++ b/docs/API.md @@ -26,6 +26,7 @@ Response Body Type: ``application/json`` | isTTFullAudio | boolean | ``true / false`` | ``false`` | Enables download of original sound used in a TikTok video. | | isAudioMuted | boolean | ``true / false`` | ``false`` | Disables audio track in video downloads. | | dubLang | boolean | ``true / false`` | ``false`` | Backend uses Accept-Language for YouTube video audio tracks when ``true``. | +| disableMetadata | boolean | ``true / false`` | ``false`` | Does not add metadata to the downloaded audio/video | ### Response Body Variables | key | type | variables | diff --git a/src/front/cobalt.js b/src/front/cobalt.js index ca309511..754ed349 100644 --- a/src/front/cobalt.js +++ b/src/front/cobalt.js @@ -18,7 +18,7 @@ const switchers = { "vimeoDash": ["false", "true"], "audioMode": ["false", "true"] }; -const checkboxes = ["disableTikTokWatermark", "fullTikTokAudio", "muteAudio", "reduceTransparency", "disableAnimations"]; +const checkboxes = ["disableTikTokWatermark", "fullTikTokAudio", "muteAudio", "reduceTransparency", "disableAnimations", "disableMetadata"]; const exceptions = { // used for mobile devices "vQuality": "720" }; @@ -377,6 +377,8 @@ async function download(url) { if ((url.includes("tiktok.com/") || url.includes("douyin.com/")) && sGet("disableTikTokWatermark") === "true") req.isNoTTWatermark = true; } + if (sGet("disableMetadata") === "true") req.disableMetadata = true; + let j = await fetch(`${apiURL}/api/json`, { method: "POST", body: JSON.stringify(req), diff --git a/src/localization/languages/en.json b/src/localization/languages/en.json index b087f998..ceb63ac9 100644 --- a/src/localization/languages/en.json +++ b/src/localization/languages/en.json @@ -43,6 +43,7 @@ "SettingsKeepDownloadButton": "keep >> visible", "AccessibilityKeepDownloadButton": "keep the download button always visible", "SettingsEnableDownloadPopup": "ask how to save", + "SettingsDisableMetadata": "disable file metadata", "AccessibilityEnableDownloadPopup": "ask what to do with downloads", "SettingsQualityDescription": "if selected quality isn't available, closest one is used instead.", "LinkGitHubChanges": ">> see previous commits and contribute on github", diff --git a/src/localization/languages/ru.json b/src/localization/languages/ru.json index d65353bc..6cb51085 100644 --- a/src/localization/languages/ru.json +++ b/src/localization/languages/ru.json @@ -43,6 +43,7 @@ "SettingsKeepDownloadButton": "всегда показывать >>", "AccessibilityKeepDownloadButton": "всегда показывать кнопку скачивания на экране", "SettingsEnableDownloadPopup": "выбор метода скачивания", + "SettingsDisableMetadata": "disable file metadata", "AccessibilityEnableDownloadPopup": "спрашивать, что делать с загрузками", "SettingsQualityDescription": "если выбранное качество недоступно, то выбирается ближайшее к нему.", "LinkGitHubChanges": ">> смотри предыдущие изменения на github", diff --git a/src/modules/pageRender/page.js b/src/modules/pageRender/page.js index 1c8a5738..6baea34e 100644 --- a/src/modules/pageRender/page.js +++ b/src/modules/pageRender/page.js @@ -447,6 +447,10 @@ export default function(obj) { name: t("SettingsEnableDownloadPopup"), padding: "no-margin", aria: t("AccessibilityEnableDownloadPopup") + }, { + action: "disableMetadata", + name: t("SettingsDisableMetadata"), + padding: "no-margin" }]) }) }], diff --git a/src/modules/processing/match.js b/src/modules/processing/match.js index 0552f2da..51333829 100644 --- a/src/modules/processing/match.js +++ b/src/modules/processing/match.js @@ -22,7 +22,7 @@ import streamable from "./services/streamable.js"; export default async function (host, patternMatch, url, lang, obj) { try { - let r, isAudioOnly = !!obj.isAudioOnly; + let r, isAudioOnly = !!obj.isAudioOnly, disableMetadata = !!obj.disableMetadata; if (!testers[host]) return apiJSON(0, { t: errorUnsupported(lang) }); if (!(testers[host](patternMatch))) return apiJSON(0, { t: brokenLink(lang, host) }); @@ -131,7 +131,7 @@ export default async function (host, patternMatch, url, lang, obj) { if (r.error) return apiJSON(0, { t: Array.isArray(r.error) ? loc(lang, r.error[0], r.error[1]) : loc(lang, r.error) }); - return matchActionDecider(r, host, obj.aFormat, isAudioOnly, lang, isAudioMuted); + return matchActionDecider(r, host, obj.aFormat, isAudioOnly, lang, isAudioMuted, disableMetadata); } catch (e) { return apiJSON(0, { t: genericError(lang, host) }) } diff --git a/src/modules/processing/matchActionDecider.js b/src/modules/processing/matchActionDecider.js index c2db9176..258fd81b 100644 --- a/src/modules/processing/matchActionDecider.js +++ b/src/modules/processing/matchActionDecider.js @@ -2,17 +2,17 @@ import { audioIgnore, services, supportedAudio } from "../config.js"; import { apiJSON } from "../sub/utils.js"; import loc from "../../localization/manager.js"; -export default function(r, host, audioFormat, isAudioOnly, lang, isAudioMuted) { +export default function(r, host, audioFormat, isAudioOnly, lang, isAudioMuted, disableMetadata) { let action, responseType = 2, defaultParams = { u: r.urls, service: host, filename: r.filename, - fileMetadata: r.fileMetadata ? r.fileMetadata : false + fileMetadata: !disableMetadata ? r.fileMetadata : false }, params = {} - + if (r.isPhoto) action = "photo"; else if (r.picker) action = "picker" else if (isAudioMuted) action = "muteVideo"; diff --git a/src/modules/sub/utils.js b/src/modules/sub/utils.js index e237e6a6..0a905110 100644 --- a/src/modules/sub/utils.js +++ b/src/modules/sub/utils.js @@ -6,7 +6,7 @@ const apiVar = { vQuality: ["max", "4320", "2160", "1440", "1080", "720", "480", "360", "240", "144"], aFormat: ["best", "mp3", "ogg", "wav", "opus"] }, - booleanOnly: ["isAudioOnly", "isNoTTWatermark", "isTTFullAudio", "isAudioMuted", "dubLang", "vimeoDash"] + booleanOnly: ["isAudioOnly", "isNoTTWatermark", "isTTFullAudio", "isAudioMuted", "dubLang", "vimeoDash", "disableMetadata"] } const forbiddenChars = ['}', '{', '(', ')', '\\', '%', '>', '<', '^', '*', '!', '~', ';', ':', ',', '`', '[', ']', '#', '$', '"', "'", "@", '==']; const forbiddenCharsString = ['}', '{', '%', '>', '<', '^', ';', '`', '$', '"', "@", '=']; @@ -101,13 +101,14 @@ export function checkJSONPost(obj) { isNoTTWatermark: false, isTTFullAudio: false, isAudioMuted: false, + disableMetadata: false, dubLang: false, vimeoDash: false } try { let objKeys = Object.keys(obj); - if (!(objKeys.length <= 9 && obj.url)) return false; let defKeys = Object.keys(def); + if (objKeys.length > defKeys.length + 1 || !obj.url) return false; for (let i in objKeys) { if (String(objKeys[i]) !== "url" && defKeys.includes(objKeys[i])) {