diff --git a/docs/API.md b/docs/API.md index dac2e573..9801a553 100644 --- a/docs/API.md +++ b/docs/API.md @@ -21,6 +21,7 @@ Response Body Type: ``application/json`` | isAudioOnly | boolean | ``true / false`` | ``false`` | | | isNoTTWatermark | boolean | ``true / false`` | ``false`` | Changes whether downloaded TikTok & Douyin videos have watermarks. | | 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. | ### Response Body Variables | key | type | variables | diff --git a/package.json b/package.json index 70b996ff..7df551ea 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cobalt", "description": "save what you love", - "version": "4.5", + "version": "4.6.0", "author": "wukko", "exports": "./src/cobalt.js", "type": "module", diff --git a/src/cobalt.js b/src/cobalt.js index 5a0861e0..bce2398b 100644 --- a/src/cobalt.js +++ b/src/cobalt.js @@ -10,7 +10,7 @@ import { appName, genericUserAgent, version, internetExplorerRedirect } from "./ import { getJSON } from "./modules/api.js"; import renderPage from "./modules/pageRender/page.js"; import { apiJSON, checkJSONPost, languageCode } from "./modules/sub/utils.js"; -import { Bright, Cyan } from "./modules/sub/consoleText.js"; +import { Bright, Cyan, Green, Red } from "./modules/sub/consoleText.js"; import stream from "./modules/stream/stream.js"; import loc from "./localization/manager.js"; import { buildFront } from "./modules/build.js"; @@ -190,8 +190,8 @@ if (fs.existsSync('./.env') && process.env.selfURL && process.env.streamSalt && res.redirect('/') }); app.listen(process.env.port, () => { - console.log(`\n${Bright(`${appName} (${version})`)}\n\nURL: ${Cyan(`${process.env.selfURL}`)}\nPort: ${process.env.port}\nCurrent commit: ${Bright(`${commitHash}`)}\nStart time: ${Bright(Math.floor(new Date().getTime()))}\n`) + console.log(`\n${Cyan(appName)} ${Bright(`v.${version}-${commitHash}`)}\n\nURL: ${Cyan(`${process.env.selfURL}`)}\nPort: ${process.env.port}\nStart time: ${Bright(Math.floor(new Date().getTime()))}\n`) }); } else { - console.log(`you can't run the server without generating a .env file. please run the setup script first: npm run setup`) + console.log(Red(`cobalt hasn't been configured yet or configuration is invalid.\n`) + Bright(`please run the setup script to fix this: `) + Green(`npm run setup`)) } diff --git a/src/config.json b/src/config.json index 98bdd3f6..d42baf27 100644 --- a/src/config.json +++ b/src/config.json @@ -41,6 +41,9 @@ "10-31": "🎃", "11-01": "🕯️", "11-02": "🕯️", + "12-20": "🎄", + "12-21": "🎄", + "12-22": "🎄", "12-23": "🎄", "12-24": "🎄", "12-25": "🎄", diff --git a/src/front/cobalt.js b/src/front/cobalt.js index b8b5ddfd..0c57be82 100644 --- a/src/front/cobalt.js +++ b/src/front/cobalt.js @@ -1,7 +1,7 @@ let ua = navigator.userAgent.toLowerCase(); let isIOS = ua.match("iphone os"); let isMobile = ua.match("android") || ua.match("iphone os"); -let version = 19; +let version = 20; let regex = new RegExp(/https:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/); let notification = `
` @@ -13,7 +13,7 @@ let switchers = { "vQuality": ["hig", "max", "mid", "low"], "aFormat": ["mp3", "best", "ogg", "wav", "opus"] } -let checkboxes = ["disableTikTokWatermark", "fullTikTokAudio"]; +let checkboxes = ["disableTikTokWatermark", "fullTikTokAudio", "muteAudio"]; let exceptions = { // used for mobile devices "vQuality": "mid" } @@ -339,6 +339,7 @@ async function download(url) { if (sGet("fullTikTokAudio") === "true") req["isTTFullAudio"] = true; // audio tiktok full } else { req["vQuality"] = sGet("vQuality").slice(0, 4); + if (sGet("muteAudio") === "true") req["isAudioMuted"] = true; if (url.includes("youtube.com/") || url.includes("/youtu.be/")) req["vFormat"] = sGet("vFormat").slice(0, 4); if ((url.includes("tiktok.com/") || url.includes("douyin.com/")) && sGet("disableTikTokWatermark") === "true") req["isNoTTWatermark"] = true; } diff --git a/src/front/updateBanners/shutup.png b/src/front/updateBanners/shutup.png new file mode 100644 index 00000000..cbc80ae8 Binary files /dev/null and b/src/front/updateBanners/shutup.png differ diff --git a/src/localization/languages/en.json b/src/localization/languages/en.json index 745a89e0..c364fc46 100644 --- a/src/localization/languages/en.json +++ b/src/localization/languages/en.json @@ -1,7 +1,7 @@ { "name": "english", "substrings": { - "ContactLink": "contact the maintainer" + "ContactLink": "file an issue on github" }, "strings": { "LinkInput": "paste the link here", @@ -38,7 +38,6 @@ "SettingsAppearanceSubtitle": "appearance", "SettingsThemeSubtitle": "theme", "SettingsFormatSubtitle": "download format", - "SettingsDownloadsSubtitle": "downloads", "SettingsQualitySubtitle": "quality", "SettingsThemeAuto": "auto", "SettingsThemeLight": "light", @@ -108,6 +107,9 @@ "DonateExplanation": "{appName} does not (and will never) serve ads or sell your data, therefore it's completely free to use. but hey! turns out keeping up a web service used by hundreds of thousands of people is somewhat costly.\n\nif you ever found {appName} useful and want to keep it online, or simply want to thank the developer, consider chipping in! each and every cent helps and is VERY appreciated.", "DonateVia": "donate via", "DonateHireMe": "or, as an alternative, you can hire me.", - "DiscordServer": "join the live conversation about {appName} on the official discord server" + "SettingsVideoMute": "mute audio", + "SettingsVideoMuteExplanation": "disables audio in downloaded video when possible. you'll get the source video file if video and audio channels are served in two files by the origin service. ignored when audio mode is on or service only supports audio.", + "SettingsVideoGeneral": "general", + "ErrorSoundCloudNoClientId": "couldn't find client_id that is required to fetch audio data from soundcloud. try again, and if issue persists, {ContactLink}." } } diff --git a/src/localization/languages/ru.json b/src/localization/languages/ru.json index d40f770c..8c76ae2f 100644 --- a/src/localization/languages/ru.json +++ b/src/localization/languages/ru.json @@ -1,7 +1,7 @@ { "name": "русский", "substrings": { - "ContactLink": "напиши об этом мейнтейнеру" + "ContactLink": "напиши об этом на github" }, "strings": { "LinkInput": "вставь ссылку сюда", @@ -25,7 +25,7 @@ "ErrorUnsupported": "с твоей ссылкой что-то не так, или же этот сервис ещё не поддерживается. может быть, ты вставил не ту ссылку?", "ErrorBrokenLink": "{s} поддерживается, но с твоей ссылкой что-то не так. может быть, ты её не полностью скопировал?", "ErrorNoLink": "я не гадалка и не могу угадывать, что ты хочешь скачать. попробуй в следующий раз вставить ссылку.", - "ErrorPageRenderFail": "что-то пошло не так, поэтому у меня не получилось срендерить страницу. если это повторится ещё раз, пожалуйста, {ContactLink}. также приложи хэш текущего коммита ({s}) с действиями для повторения этой ошибки. можно на русском языке. спасибо :)", + "ErrorPageRenderFail": "что-то пошло не так и у меня не получилось срендерить страницу. если это повторится ещё раз, пожалуйста, {ContactLink}. также приложи хэш текущего коммита ({s}) с действиями для повторения этой ошибки. можно на русском языке. спасибо :)", "ErrorRateLimit": "ты делаешь слишком много запросов. успокойся и попробуй ещё раз через несколько минут.", "ErrorCouldntFetch": "мне не удалось получить инфу о твоей ссылке. проверь её и попробуй ещё раз.", "ErrorLengthLimit": "твоё видео длиннее чем {s} минут(ы). это превышает текущий лимит. скачай что-нибудь покороче, а не экранизацию \"войны и мира\".", @@ -38,7 +38,6 @@ "SettingsAppearanceSubtitle": "внешний вид", "SettingsThemeSubtitle": "тема", "SettingsFormatSubtitle": "формат загрузок", - "SettingsDownloadsSubtitle": "загрузки", "SettingsQualitySubtitle": "качество", "SettingsThemeAuto": "авто", "SettingsThemeLight": "светлая", @@ -54,8 +53,8 @@ "AccessibilityEnableDownloadPopup": "спрашивать, что делать с загрузками", "SettingsFormatDescription": "выбирай webm, если хочешь максимальное качество. у webm видео битрейт обычно выше, но устройства на ios не могут проигрывать их без сторонних приложений.", "SettingsQualityDescription": "если выбранное качество недоступно, то выбирается ближайшее к нему.\nесли ты хочешь опубликовать видео с youtube где-то в соц. сетях, то выбирай комбинацию из mp4 и 720p. у таких видео кодек обычно не av1, поэтому они должны работать практически везде.", - "LinkGitHubIssues": ">> сообщай о проблемах и смотри исходный код на гитхабе", - "LinkGitHubChanges": ">> смотри предыдущие изменения на гитхабе", + "LinkGitHubIssues": ">> сообщай о проблемах и смотри исходный код на github", + "LinkGitHubChanges": ">> смотри предыдущие изменения на github", "NoScriptMessage": "{appName} использует javascript для обработки ссылок и интерактивного интерфейса. ты должен разрешить использование javascript, чтобы пользоваться сайтом. тут нет никаких трекеров или рекламы, обещаю.", "DownloadPopupDescriptionIOS": "так как у тебя устройство на ios, тебе нужно зажать кнопку \"скачать\", затем скрыть превью видео и выбрать \"загрузить файл по ссылке\" в появившемся окне.", "DownloadPopupDescription": "кнопка скачивания открывает новое окно с файлом. ты можешь отключить выбор метода сохранения файла в настройках.", @@ -108,6 +107,9 @@ "DonateExplanation": "{appName} не пихает рекламу тебе в лицо и не продаёт твои личные данные, а значит работает совершенно бесплатно. но оказывается, что хостинг сервиса, которым пользуются сотни тысяч людей, обходится довольно дорого.\n\nесли ты хочешь, чтобы твой любимый загрузчик оставался онлайн, а разработчик не помер с голоду вместе с двумя котами, то подумай над тем, чтобы задонатить. каждый рубль поможет мне, моим котам, и {appName}!", "DonateVia": "открыть", "DonateHireMe": "или же ты можешь пригласить меня на работу.", - "DiscordServer": "присоединяйся к живой беседе о {appName} прямо на его официальном discord сервере" + "SettingsVideoMute": "отключить аудио", + "SettingsVideoMuteExplanation": "убирает аудио при загрузке видео, когда это возможно. ты получишь исходное видео напрямую от сервиса, если видео и аудио каналы разбиты по файлам. игнорируется если включен режим аудио или сервис поддерживает только аудио загрузки.", + "SettingsVideoGeneral": "основные", + "ErrorSoundCloudNoClientId": "мне не удалось достать client_id, который необходим для получения аудио из soundcloud. попробуй ещё раз, но если так и не получится, {ContactLink}." } } diff --git a/src/modules/changelog/changelog.json b/src/modules/changelog/changelog.json index 43f86c7a..01c21a2d 100644 --- a/src/modules/changelog/changelog.json +++ b/src/modules/changelog/changelog.json @@ -1,11 +1,16 @@ { "current": { + "version": "4.6", + "title": "mute videos and proper soundcloud support", + "banner": "shutup.png", + "content": "i've been longing to implement both of these things, and here they finally are.\n\nservice-related improvements:\n
• you now can download videos with no audio! simply enable the \"mute audio\" option in settings > audio.\n• soundcloud module has been updated, and downloads should no longer break after some time.
\nvisual improvements:\n
• moved some things around in settings popup, and added separators where separation is needed.\n• updated some texts in english and russian.\n• version and commit hash have been joined together, now they're a single unit.
\ninternal improvements:\n
• updated api documentation to include isAudioMuted.\n• created render elements for separator and explanation due to high duplication of them in the page.\n• fixed some code quirks.
\nhere's how soundcloud downloads got fixed:\n\npreviously, client_id was (stupidly) hardcoded. that means cobalt wasn't able to fetch song data if soundcloud web app got updated.\nnow, cobalt tries to find the up-to-date client_id, caches it in memory, and checks if web app version has changed to update the id accordingly. you can see this change for yourself on github." + }, + "history": [{ "version": "4.5", "title": "better, faster, stronger, stable", "banner": "meowthstrong.webp", "content": "your favorite social media downloader just got even better! this update includes a ton of imporvements and fixes.\n\nin fact, there are so many changes, i had to split them in sections.\n\nservice-related improvements:\n
• vimeo module has been revamped, all sorts of videos should now be supported.\n• vimeo audio downloads! you now can download audios from more recent videos.\n• {appName} now supports all sorts of tumblr links. (even those scary ones from the mobile app)\n• vk clips support has been fixed. they rolled back the separation of videos and clips, so i had to do the same.\n• youtube videos with community warnings should now be possible to download.
\nuser interface improvements:\n
• list of supported services is now MUCH easier to read.\n• banners in changelog history should no longer overlap each other.\n• bullet points! they have a bit of extra padding, so it makes them stand out of the rest of text.
\ninternal improvements:\n
• cobalt will now match the link to regex when using ?u= query for autopasting it into input area.\n• better rate limiting: limiting now is done per minute, not per 20 minutes. this ensures less waiting and less attack area for request spammers.\n• moved to my own fork of ytdl-core, cause main project seems to have been abandoned. go check it out on github or npm!\n• ALL user inputs are now properly sanitized on the server. that includes variables for POST api method, too.\n• \"got\" package has been (mostly) replaced by native fetch api. this should greately reduce ram usage.\n• all unnecessary duplications of module imports have been gotten rid of. no more error passing strings from inside of service modules. you don't make mistakes only if you don't do anything, right?\n• other code optimizations. there's less clutter overall.
\nhuge update, right? seems like everything's fixed now?\n\nnope, one issue still persists: sometimes youtube server drops packets for an audio file while cobalt's rendering the video for you. this results in abrupt cuts of audio. if you want to help solving this issue, please feel free to do it on github!\n\nthank you for reading this, and thank you for sticking with cobalt and me." - }, - "history": [{ + }, { "version": "4.4", "title": "over 1 million monthly requests. thank you.", "banner": "onemillionr.webp", diff --git a/src/modules/pageRender/elements.js b/src/modules/pageRender/elements.js index 25bebb92..fd1b6c50 100644 --- a/src/modules/pageRender/elements.js +++ b/src/modules/pageRender/elements.js @@ -39,7 +39,15 @@ export function checkbox(action, text, aria, paddingType) { ${text} ` } - +export function sep(paddingType) { + let paddingClass = `` + switch(paddingType) { + case 0: + paddingClass += ` top-margin`; + break; + } + return `
` +} export function popup(obj) { let classes = obj.classes ? obj.classes : [] let body = obj.body; @@ -143,7 +151,9 @@ export function footerButtons(obj) { return ` ` } - +export function explanation(text) { + return `
${text}
` +} export function celebrationsEmoji() { let n = new Date().toISOString().split('T')[0].split('-'); let dm = `${n[1]}-${n[2]}`; diff --git a/src/modules/pageRender/page.js b/src/modules/pageRender/page.js index 2c5c1883..938f3b0a 100644 --- a/src/modules/pageRender/page.js +++ b/src/modules/pageRender/page.js @@ -1,4 +1,4 @@ -import { backdropLink, celebrationsEmoji, checkbox, footerButtons, multiPagePopup, popup, popupWithBottomButtons, settingsCategory, switcher } from "./elements.js"; +import { backdropLink, celebrationsEmoji, checkbox, explanation, footerButtons, multiPagePopup, popup, popupWithBottomButtons, sep, settingsCategory, switcher } from "./elements.js"; import { services as s, appName, authorInfo, version, quality, repo, donations, supportedAudio } from "../config.js"; import { getCommitInfo } from "../sub/currentCommit.js"; import loc from "../../localization/manager.js"; @@ -115,7 +115,7 @@ export default function(obj) { }, { text: changelogManager("content") }, { - text: `
${obj.hash}: ${com[0]}`, + text: `${sep()}${obj.hash}: ${com[0]}`, classes: ["changelog-subtitle"], nopadding: true }, { @@ -153,13 +153,13 @@ export default function(obj) { text: loc(obj.lang, 'DonateLinksDescription'), classes: ["explanation"] }, { - text: `
`, + text: sep(), raw: true }, { text: donate.replace(/REPLACEME/g, loc(obj.lang, 'ClickToCopy')), classes: ["desc-padding"] }, { - text: `
`, + text: sep(), raw: true }, { text: loc(obj.lang, 'DonateHireMe', authorInfo.link), @@ -173,7 +173,7 @@ export default function(obj) { closeAria: loc(obj.lang, 'AccessibilityClosePopup'), header: { aboveTitle: { - text: `v.${version} ~ ${obj.hash}`, + text: `v.${version}-${obj.hash}`, url: `${repo}/commit/${obj.hash}` }, title: `${emoji("⚙️", 30)} ${loc(obj.lang, 'TitlePopupSettings')}` @@ -183,7 +183,7 @@ export default function(obj) { title: `${emoji("🎬")} ${loc(obj.lang, 'SettingsVideoTab')}`, content: settingsCategory({ name: "downloads", - title: loc(obj.lang, 'SettingsDownloadsSubtitle'), + title: loc(obj.lang, 'SettingsVideoGeneral'), body: switcher({ name: "vQuality", subtitle: loc(obj.lang, 'SettingsQualitySubtitle'), @@ -202,8 +202,7 @@ export default function(obj) { "text": `${loc(obj.lang, 'SettingsQualitySwitchLow')}
(${quality.low}p)` }] }) - }) + `${!isIOS ? checkbox("downloadPopup", loc(obj.lang, 'SettingsEnableDownloadPopup'), loc(obj.lang, 'AccessibilityEnableDownloadPopup'), 1) : ''}` - + settingsCategory({ + }) + settingsCategory({ name: "youtube", body: switcher({ name: "vFormat", @@ -234,7 +233,7 @@ export default function(obj) { subtitle: loc(obj.lang, 'SettingsFormatSubtitle'), explanation: loc(obj.lang, 'SettingsAudioFormatDescription'), items: audioFormats - }) + }) + sep(0) + checkbox("muteAudio", loc(obj.lang, 'SettingsVideoMute'), loc(obj.lang, 'SettingsVideoMute'), 3) + explanation(loc(obj.lang, 'SettingsVideoMuteExplanation')) }) + settingsCategory({ name: "tiktok", title: "tiktok & douyin", @@ -263,7 +262,7 @@ export default function(obj) { }) + settingsCategory({ name: "miscellaneous", title: loc(obj.lang, 'Miscellaneous'), - body: checkbox("disableChangelog", loc(obj.lang, 'SettingsDisableNotifications')) + body: checkbox("disableChangelog", loc(obj.lang, 'SettingsDisableNotifications')) + `${!isIOS ? checkbox("downloadPopup", loc(obj.lang, 'SettingsEnableDownloadPopup'), loc(obj.lang, 'AccessibilityEnableDownloadPopup'), 1) : ''}` }) }], })} diff --git a/src/modules/processing/match.js b/src/modules/processing/match.js index a7cc5868..b840df1c 100644 --- a/src/modules/processing/match.js +++ b/src/modules/processing/match.js @@ -107,7 +107,7 @@ export default async function (host, patternMatch, url, lang, obj) { default: return apiJSON(0, { t: errorUnsupported(lang) }); } - return !r.error ? matchActionDecider(r, host, obj.ip, obj.aFormat, obj.isAudioOnly, lang) : apiJSON(0, { + return !r.error ? matchActionDecider(r, host, obj.ip, obj.aFormat, obj.isAudioOnly, lang, obj.isAudioMuted) : apiJSON(0, { t: Array.isArray(r.error) ? loc(lang, r.error[0], r.error[1]) : loc(lang, r.error) }); } catch (e) { diff --git a/src/modules/processing/matchActionDecider.js b/src/modules/processing/matchActionDecider.js index 7f03b8c2..2de3ed2c 100644 --- a/src/modules/processing/matchActionDecider.js +++ b/src/modules/processing/matchActionDecider.js @@ -2,8 +2,8 @@ import { audioIgnore, services, supportedAudio } from "../config.js" import { apiJSON } from "../sub/utils.js" import loc from "../../localization/manager.js"; -export default function(r, host, ip, audioFormat, isAudioOnly, lang) { - if (!isAudioOnly && !r.picker) { +export default function(r, host, ip, audioFormat, isAudioOnly, lang, isAudioMuted) { + if (!isAudioOnly && !r.picker && !isAudioMuted) { switch (host) { case "twitter": return apiJSON(1, { u: r.urls }); @@ -42,7 +42,7 @@ export default function(r, host, ip, audioFormat, isAudioOnly, lang) { case "tumblr": return apiJSON(1, { u: r.urls }); case "vimeo": - if (r.filename) { + if (Array.isArray(r.urls)) { return apiJSON(2, { type: "render", u: r.urls, service: host, ip: ip, filename: r.filename @@ -51,6 +51,16 @@ export default function(r, host, ip, audioFormat, isAudioOnly, lang) { return apiJSON(1, { u: r.urls }); } } + } else if (isAudioMuted) { + let isSplit = Array.isArray(r.urls); + return apiJSON(2, { + type: isSplit ? "bridge" : "mute", + u: isSplit ? r.urls[0] : r.urls, + service: host, + ip: ip, + filename: r.filename, + mute: true, + }); } else if (r.picker) { switch (host) { case "douyin": diff --git a/src/modules/processing/servicesConfig.json b/src/modules/processing/servicesConfig.json index c0cd70a2..5535025d 100644 --- a/src/modules/processing/servicesConfig.json +++ b/src/modules/processing/servicesConfig.json @@ -86,7 +86,6 @@ "soundcloud": { "patterns": [":author/:song", ":shortLink"], "bestAudio": "none", - "clientid": "YeTcsotswIIc4sse5WZsXszVxMtP6eLc", "enabled": true } } diff --git a/src/modules/services/bilibili.js b/src/modules/services/bilibili.js index d8311326..367e538f 100644 --- a/src/modules/services/bilibili.js +++ b/src/modules/services/bilibili.js @@ -4,7 +4,7 @@ export default async function(obj) { try { let html = await fetch(`https://bilibili.com/video/${obj.id}`, { headers: {"user-agent": genericUserAgent} - }).then(async (r) => {return await r.text()}).catch(() => {return false}); + }).then(async (r) => {return r.text()}).catch(() => {return false}); if (!html) return { error: 'ErrorCouldntFetch' }; if (html.includes('')[0]) if (json["media"]["transcodings"]) { - let fileUrl = `${json.media.transcodings[0]["url"].replace("/hls", "/progressive")}?client_id=${services["soundcloud"]["clientid"]}&track_authorization=${json.track_authorization}`; - if (fileUrl.substring(0, 54) === "https://api-v2.soundcloud.com/media/soundcloud:tracks:") { - if (json.duration < maxAudioDuration) { - let file = await fetch(fileUrl).then(async (r) => {return (await r.json()).url}).catch(() => {return false}); - if (!file) return { error: 'ErrorCouldntFetch' }; - return { - urls: file, - audioFilename: `soundcloud_${json.id}`, - fileMetadata: { - title: json.title, - artist: json.user.username, + let clientId = await findClientID(); + if (clientId) { + let fileUrl = `${json.media.transcodings[0]["url"].replace("/hls", "/progressive")}?client_id=${clientId}&track_authorization=${json.track_authorization}`; + if (fileUrl.substring(0, 54) === "https://api-v2.soundcloud.com/media/soundcloud:tracks:") { + if (json.duration < maxAudioDuration) { + let file = await fetch(fileUrl).then(async (r) => {return (await r.json()).url}).catch(() => {return false}); + if (!file) return { error: 'ErrorCouldntFetch' }; + return { + urls: file, + audioFilename: `soundcloud_${json.id}`, + fileMetadata: { + title: json.title, + artist: json.user.username, + } } - } - } else return { error: ['ErrorLengthAudioConvert', maxAudioDuration / 60000] } - } + } else return { error: ['ErrorLengthAudioConvert', maxAudioDuration / 60000] } + } + } else return { error: 'ErrorSoundCloudNoClientId' } } else return { error: 'ErrorEmptyDownload' } } else return { error: ['ErrorBrokenLink', 'soundcloud'] } } catch (e) { diff --git a/src/modules/services/tiktok.js b/src/modules/services/tiktok.js index d38b8c5c..72e548b4 100644 --- a/src/modules/services/tiktok.js +++ b/src/modules/services/tiktok.js @@ -32,7 +32,7 @@ export default async function(obj) { let html = await fetch(`${config[obj.host]["short"]}${obj.id}`, { redirect: "manual", headers: { "user-agent": userAgent } - }).then(async (r) => {return await r.text()}).catch(() => {return false}); + }).then(async (r) => {return r.text()}).catch(() => {return false}); if (!html) return { error: 'ErrorCouldntFetch' }; if (html.slice(0, 17) === ' {return await r.json()}).catch(() => {return false}); + }).then(async (r) => {return r.json()}).catch(() => {return false}); detail = selector(detail, obj.host, obj.postId); diff --git a/src/modules/services/tumblr.js b/src/modules/services/tumblr.js index 23306cae..29592897 100644 --- a/src/modules/services/tumblr.js +++ b/src/modules/services/tumblr.js @@ -5,7 +5,7 @@ export default async function(obj) { let user = obj.user ? obj.user : obj.url.split('.')[0].replace('https://', ''); let html = await fetch(`https://${user}.tumblr.com/post/${obj.id}`, { headers: {"user-agent": genericUserAgent} - }).then(async (r) => {return await r.text()}).catch(() => {return false}); + }).then(async (r) => {return r.text()}).catch(() => {return false}); if (!html) return { error: 'ErrorCouldntFetch' }; if (html.includes('property="og:video" content="https://va.media.tumblr.com/')) { return { urls: `https://va.media.tumblr.com/${html.split('property="og:video" content="https://va.media.tumblr.com/')[1].split('"/>')[0]}`, audioFilename: `tumblr_${obj.id}_audio` } diff --git a/src/modules/services/twitter.js b/src/modules/services/twitter.js index 923c8825..4298378e 100644 --- a/src/modules/services/twitter.js +++ b/src/modules/services/twitter.js @@ -15,13 +15,13 @@ export default async function(obj) { let req_act = await fetch(`${apiURL}/guest/activate.json`, { method: "POST", headers: _headers - }).then(async (r) => { return r.status == 200 ? await r.json() : false;}).catch(() => {return false}); + }).then(async (r) => { return r.status == 200 ? r.json() : false;}).catch(() => {return false}); if (!req_act) return { error: 'ErrorCouldntFetch' }; _headers["x-guest-token"] = req_act["guest_token"]; let showURL = `${apiURL}/statuses/show/${obj.id}.json?tweet_mode=extended&include_user_entities=0&trim_user=1&include_entities=0&cards_platform=Web-12&include_cards=1` if (!obj.spaceId) { - let req_status = await fetch(showURL, { headers: _headers }).then(async (r) => { return r.status == 200 ? await r.json() : false;}).catch((e) => { return false}); + let req_status = await fetch(showURL, { headers: _headers }).then(async (r) => { return r.status == 200 ? r.json() : false;}).catch((e) => { return false}); if (!req_status) { _headers.authorization = "Bearer AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw"; delete _headers["x-guest-token"] @@ -29,11 +29,11 @@ export default async function(obj) { req_act = await fetch(`${apiURL}/guest/activate.json`, { method: "POST", headers: _headers - }).then(async (r) => { return r.status == 200 ? await r.json() : false;}).catch(() => {return false}); + }).then(async (r) => { return r.status == 200 ? r.json() : false;}).catch(() => {return false}); if (!req_act) return { error: 'ErrorCouldntFetch' }; _headers["x-guest-token"] = req_act["guest_token"]; - req_status = await fetch(showURL, { headers: _headers }).then(async (r) => { return r.status == 200 ? await r.json() : false;}).catch(() => {return false}); + req_status = await fetch(showURL, { headers: _headers }).then(async (r) => { return r.status == 200 ? r.json() : false;}).catch(() => {return false}); } if (!req_status) return { error: 'ErrorCouldntFetch' } if (req_status["extended_entities"] && req_status["extended_entities"]["media"]) { @@ -47,7 +47,7 @@ export default async function(obj) { return { error: 'ErrorNoVideosInTweet' } } if (single) { - return { urls: single, audioFilename: `twitter_${obj.id}_audio` } + return { urls: single, filename: `twitter_${obj.id}.mp4`, audioFilename: `twitter_${obj.id}_audio` } } else if (multiple) { return { picker: multiple } } else { @@ -64,12 +64,12 @@ export default async function(obj) { } let AudioSpaceById = await fetch(`https://twitter.com/i/api/graphql/wJ5g4zf7v8qPHSQbaozYuw/AudioSpaceById?variables=${new URLSearchParams(JSON.stringify(query.variables)).toString().slice(0, -1)}&features=${new URLSearchParams(JSON.stringify(query.features)).toString().slice(0, -1)}`, { headers: _headers }).then(async (r) => { - return r.status == 200 ? await r.json() : false; + return r.status == 200 ? r.json() : false; }).catch((e) => {return false}); if (AudioSpaceById) { if (AudioSpaceById.data.audioSpace.metadata.is_space_available_for_replay === true) { - let streamStatus = await fetch(`https://twitter.com/i/api/1.1/live_video_stream/status/${AudioSpaceById.data.audioSpace.metadata.media_key}`, { headers: _headers }).then(async (r) => {return r.status == 200 ? await r.json() : false;}).catch(() => {return false;}); + let streamStatus = await fetch(`https://twitter.com/i/api/1.1/live_video_stream/status/${AudioSpaceById.data.audioSpace.metadata.media_key}`, { headers: _headers }).then(async (r) => {return r.status == 200 ? r.json() : false;}).catch(() => {return false;}); if (!streamStatus) return { error: 'ErrorCouldntFetch' }; let participants = AudioSpaceById.data.audioSpace.participants.speakers diff --git a/src/modules/services/vimeo.js b/src/modules/services/vimeo.js index 0c2b06c8..b1ca763f 100644 --- a/src/modules/services/vimeo.js +++ b/src/modules/services/vimeo.js @@ -2,7 +2,7 @@ import { quality, services } from "../config.js"; export default async function(obj) { try { - let api = await fetch(`https://player.vimeo.com/video/${obj.id}/config`).then(async (r) => {return await r.json()}).catch(() => {return false}); + let api = await fetch(`https://player.vimeo.com/video/${obj.id}/config`).then(async (r) => {return r.json()}).catch(() => {return false}); if (!api) return { error: 'ErrorCouldntFetch' }; let downloadType = ""; @@ -29,10 +29,10 @@ export default async function(obj) { } catch (e) { best = all[0] } - return { urls: best["url"] }; + return { urls: best["url"], filename: `tumblr_${obj.id}.mp4` }; case "dash": let masterJSONURL = api["request"]["files"]["dash"]["cdns"]["akfire_interconnect_quic"]["url"]; - let masterJSON = await fetch(masterJSONURL).then(async (r) => {return await r.json()}).catch(() => {return false}); + let masterJSON = await fetch(masterJSONURL).then(async (r) => {return r.json()}).catch(() => {return false}); if (!masterJSON) return { error: 'ErrorCouldntFetch' }; if (masterJSON.video) { let type = ""; diff --git a/src/modules/services/vk.js b/src/modules/services/vk.js index 3d77ffde..eb66361f 100644 --- a/src/modules/services/vk.js +++ b/src/modules/services/vk.js @@ -7,7 +7,7 @@ export default async function(obj) { let html; html = await fetch(`https://vk.com/video-${obj.userId}_${obj.videoId}`, { headers: {"user-agent": genericUserAgent} - }).then(async (r) => {return await r.text()}).catch(() => {return false}); + }).then(async (r) => {return r.text()}).catch(() => {return false}); if (!html) return { error: 'ErrorCouldntFetch' }; if (html.includes(`{"lang":`)) { let js = JSON.parse('{"lang":' + html.split(`{"lang":`)[1].split(']);')[0]); diff --git a/src/modules/stream/manage.js b/src/modules/stream/manage.js index 5093bb54..6c06b3a9 100644 --- a/src/modules/stream/manage.js +++ b/src/modules/stream/manage.js @@ -22,8 +22,9 @@ export function createStream(obj) { exp: exp, isAudioOnly: !!obj.isAudioOnly, audioFormat: obj.audioFormat, - time: obj.time, - copy: obj.copy, + time: obj.time ? obj.time : false, + copy: obj.copy ? true : false, + mute: obj.mute ? true : false, metadata: obj.fileMetadata ? obj.fileMetadata : false }); return `${process.env.selfURL}api/stream?t=${streamUUID}&e=${exp}&h=${ghmac}`; diff --git a/src/modules/stream/stream.js b/src/modules/stream/stream.js index 796bc4c8..eb843086 100644 --- a/src/modules/stream/stream.js +++ b/src/modules/stream/stream.js @@ -1,6 +1,6 @@ import { apiJSON } from "../sub/utils.js"; import { verifyStream } from "./manage.js"; -import { streamAudioOnly, streamDefault, streamLiveRender } from "./types.js"; +import { streamAudioOnly, streamDefault, streamLiveRender, streamVideoOnly } from "./types.js"; export default function(res, ip, id, hmac, exp) { try { @@ -13,6 +13,9 @@ export default function(res, ip, id, hmac, exp) { case "render": streamLiveRender(streamInfo, res); break; + case "mute": + streamVideoOnly(streamInfo, res); + break; default: streamDefault(streamInfo, res); break; diff --git a/src/modules/stream/types.js b/src/modules/stream/types.js index b2d386f1..d32f5e8c 100644 --- a/src/modules/stream/types.js +++ b/src/modules/stream/types.js @@ -6,7 +6,9 @@ import { metadataManager, msToTime } from "../sub/utils.js"; export function streamDefault(streamInfo, res) { try { - res.setHeader('Content-disposition', `attachment; filename="${streamInfo.isAudioOnly ? `${streamInfo.filename}.${streamInfo.audioFormat}` : streamInfo.filename}"`); + let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1] + let regFilename = !streamInfo.mute ? streamInfo.filename : `${streamInfo.filename.split('.')[0]}_mute.${format}` + res.setHeader('Content-disposition', `attachment; filename="${streamInfo.isAudioOnly ? `${streamInfo.filename}.${streamInfo.audioFormat}` : regFilename}"`); const stream = got.get(streamInfo.urls, { headers: { "user-agent": genericUserAgent @@ -96,3 +98,31 @@ export function streamAudioOnly(streamInfo, res) { res.end(); } } +export function streamVideoOnly(streamInfo, res) { + try { + let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], args = [ + '-loglevel', '-8', + '-i', streamInfo.urls, + '-c', 'copy', '-an' + ] + if (format == "mp4") args.push('-movflags', 'faststart+frag_keyframe+empty_moov') + args.push('-f', format, 'pipe:3'); + const ffmpegProcess = spawn(ffmpeg, args, { + windowsHide: true, + stdio: [ + 'inherit', 'inherit', 'inherit', + 'pipe' + ], + }); + res.setHeader('Connection', 'keep-alive'); + res.setHeader('Content-Disposition', `attachment; filename="${streamInfo.filename.split('.')[0]}_mute.${format}"`); + ffmpegProcess.stdio[3].pipe(res); + + ffmpegProcess.on('error', (err) => { + ffmpegProcess.kill(); + res.end(); + }); + } catch (e) { + res.end(); + } +} diff --git a/src/modules/sub/utils.js b/src/modules/sub/utils.js index 548e597c..adf85baf 100644 --- a/src/modules/sub/utils.js +++ b/src/modules/sub/utils.js @@ -6,7 +6,7 @@ let apiVar = { vQuality: ["max", "hig", "mid", "low", "los"], aFormat: ["best", "mp3", "ogg", "wav", "opus"] }, - booleanOnly: ["isAudioOnly", "isNoTTWatermark", "isTTFullAudio"] + booleanOnly: ["isAudioOnly", "isNoTTWatermark", "isTTFullAudio", "isAudioMuted"] } export function apiJSON(type, obj) { @@ -95,7 +95,8 @@ export function checkJSONPost(obj) { aFormat: "mp3", isAudioOnly: false, isNoTTWatermark: false, - isTTFullAudio: false + isTTFullAudio: false, + isAudioMuted: false, } try { let objKeys = Object.keys(obj); @@ -106,7 +107,7 @@ export function checkJSONPost(obj) { if (apiVar.booleanOnly.includes(objKeys[i])) { def[objKeys[i]] = obj[objKeys[i]] ? true : false; } else { - if (apiVar.allowed[objKeys[i]].includes(obj[objKeys[i]])) def[objKeys[i]] = String(obj[objKeys[i]]) + if (apiVar.allowed[objKeys[i]] && apiVar.allowed[objKeys[i]].includes(obj[objKeys[i]])) def[objKeys[i]] = String(obj[objKeys[i]]) } } }