fixes #63, #67, #68, and #71, among other issues
This commit is contained in:
wukko 2023-01-14 00:34:48 +06:00
parent 1a1a4534b7
commit 3b5bf51ba7
19 changed files with 218 additions and 191 deletions

View file

@ -45,12 +45,12 @@ Item type: ``object``
Content live render streaming endpoint.<br>
### Request Query Variables
| key | variables | description |
|:----|:-----------------|:------------------------------------------------------------------------------------------------------------------------------|
| p | ``1`` | Used for checking the rate limit. |
| t | Stream UUID | Unique stream identificator by which cobalt finds stored stream info data. |
| h | HMAC | Hashed combination of: (hashed) ip address, stream uuid, expiry timestamp, and service name. Used for verification of stream. |
| e | Expiry timestamp | |
| key | variables | description |
|:----|:-----------------|:-------------------------------------------------------------------------------------------------------------------------------|
| p | ``1`` | Used for checking the rate limit. |
| t | Stream token | Unique stream identificator which is used for retrieving cached stream info data. |
| h | HMAC | Hashed combination of: (hashed) ip address, stream token, expiry timestamp, and service name. Used for verification of stream. |
| e | Expiry timestamp | |
## GET: ``/api/onDemand``
On-demand website element loading. Currently used only for older changelogs.<br>

View file

@ -1,7 +1,7 @@
{
"name": "cobalt",
"description": "save what you love",
"version": "4.6.1",
"version": "4.7",
"author": "wukko",
"exports": "./src/cobalt.js",
"type": "module",

View file

@ -15,7 +15,7 @@ import stream from "./modules/stream/stream.js";
import loc from "./localization/manager.js";
import { buildFront } from "./modules/build.js";
import { changelogHistory } from "./modules/pageRender/onDemand.js";
import { encrypt } from "./modules/sub/crypto.js";
import { sha256 } from "./modules/sub/crypto.js";
const commitHash = shortCommit();
const app = express();
@ -71,7 +71,7 @@ if (fs.existsSync('./.env') && process.env.selfURL && process.env.streamSalt &&
}));
app.post('/api/:type', cors({ origin: process.env.selfURL, optionsSuccessStatus: 200 }), async (req, res) => {
try {
let ip = encrypt(req.header('x-forwarded-for') ? req.header('x-forwarded-for') : req.ip.replace('::ffff:', ''), process.env.streamSalt);
let ip = sha256(req.header('x-forwarded-for') ? req.header('x-forwarded-for') : req.ip.replace('::ffff:', ''), process.env.streamSalt);
switch (req.params.type) {
case 'json':
try {
@ -103,7 +103,7 @@ if (fs.existsSync('./.env') && process.env.selfURL && process.env.streamSalt &&
});
app.get('/api/:type', cors({ origin: process.env.selfURL, optionsSuccessStatus: 200 }), (req, res) => {
try {
let ip = encrypt(req.header('x-forwarded-for') ? req.header('x-forwarded-for') : req.ip.replace('::ffff:', ''), process.env.streamSalt);
let ip = sha256(req.header('x-forwarded-for') ? req.header('x-forwarded-for') : req.ip.replace('::ffff:', ''), process.env.streamSalt);
switch (req.params.type) {
case 'json':
res.status(405).json({ 'status': 'error', 'text': 'GET method for this request has been deprecated. see https://github.com/wukko/cobalt/blob/current/docs/API.md for up-to-date API documentation.' });

View file

@ -1,5 +1,5 @@
{
"streamLifespan": 3600000,
"streamLifespan": 120000,
"maxVideoDuration": 7500000,
"maxAudioDuration": 7500000,
"genericUserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
@ -59,7 +59,7 @@
"webm": ["-c:v", "copy", "-c:a", "copy"],
"mp4": ["-c:v", "copy", "-c:a", "copy", "-movflags", "faststart+frag_keyframe+empty_moov"],
"copy": ["-c:a", "copy"],
"audio": ["-ar", "48000", "-ac", "2", "-b:a", "320k"],
"audio": ["-vn", "-ar", "48000", "-ac", "2", "-b:a", "320k"],
"m4a": ["-movflags", "frag_keyframe+empty_moov"]
}
}

View file

@ -72,13 +72,13 @@ a {
:focus-visible {
outline: var(--border-15);
}
[type=checkbox] {
margin-right: 0.8rem;
}
[type="checkbox"] {
-webkit-appearance: none;
margin-right: 0.8rem;
appearance: none;
margin-right: 1rem;
z-index: 0;
border: 0;
height: 15px;
}
[type="checkbox"]::before {
content: "";
@ -91,9 +91,12 @@ a {
position: relative;
}
[type="checkbox"]:checked::before {
box-shadow: inset 0 0 0 0.2rem var(--accent-button-bg);
box-shadow: inset 0 0 0 0.14rem var(--accent-button-bg);
background-color: var(--accent);
}
.checkbox span {
margin-top: 0.21rem;
}
button {
background: none;
border: none;
@ -421,7 +424,7 @@ input[type="checkbox"] {
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
padding: 0.6rem 1rem 0.6rem 0.6rem;
padding: 0.55rem 1rem 0.8rem 0.7rem;
width: auto;
margin: 0 0.5rem 0.5rem 0;
background: var(--accent-button-bg);
@ -454,7 +457,7 @@ input[type="checkbox"] {
color: var(--accent-unhover-2);
}
.switch {
padding: 0.8rem;
padding: 0.7rem;
width: 100%;
text-align: center;
color: var(--accent);
@ -509,6 +512,9 @@ input[type="checkbox"] {
position: relative;
width: 100%;
}
.popup-tabs {
margin-top: 0.5rem;
}
.emoji {
margin-right: 0.4rem;
}
@ -573,9 +579,6 @@ input[type="checkbox"] {
margin-top: 0!important;
margin-bottom: 1rem;
}
.popup-tabs {
padding-top: 0.5rem;
}
/* adapt the page according to screen size */
@media screen and (min-width: 2300px) {
html {
@ -754,7 +757,7 @@ input[type="checkbox"] {
.popup, .popup.scrollable, .popup.small {
border: none;
width: 90%;
height: 90%;
height: 92%;
max-height: 100%;
}
.bottom-link {

View file

@ -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 = 20;
let version = 21;
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 = `<div class="notification-dot"></div>`

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

View file

@ -52,11 +52,11 @@
"SettingsEnableDownloadPopup": "ask for a way to save",
"AccessibilityEnableDownloadPopup": "ask what to do with downloads",
"SettingsFormatDescription": "select webm if you want max quality available. webm videos are usually higher bitrate, but ios devices can't play them natively.",
"SettingsQualityDescription": "if selected quality isn't available, closest one gets picked instead.\nif you want to post a youtube video on social media, then select a combination of mp4 and 720p. those videos are usually not in av1 codec, so they should play just fine basically everywhere.",
"SettingsQualityDescription": "if selected quality isn't available, closest one gets picked instead.\nif you want to post a youtube video on social media, select a combination of mp4 and 720p.",
"LinkGitHubIssues": "&gt;&gt; report issues and check out the source code on github",
"LinkGitHubChanges": "&gt;&gt; see previous commits and contribute on github",
"NoScriptMessage": "{appName} uses javascript for api requests and interactive interface. you have to allow javascript to use this site. i don't have any ads or trackers, pinky promise.",
"DownloadPopupDescriptionIOS": "on ios devices, you have to press and hold the download button, hide the video preview, and then select \"download linked file\" in appeared popup to save the video. this will be required for as long as apple forces safari webview upon all browser developers on ios.",
"DownloadPopupDescriptionIOS": "press and hold the download button, hide the video preview, and then select \"download linked file\" to save.",
"DownloadPopupDescription": "download button opens a new tab with requested file. you can disable this popup in settings.",
"DownloadPopupWayToSave": "pick a way to save",
"ClickToCopy": "press to copy",
@ -72,7 +72,7 @@
"AccessibilityModeToggle": "toggle download mode",
"DonateLinksDescription": "donation links open in a new tab. this is the best way to donate if you want me to receive your donation directly.",
"SettingsAudioFormatBest": "best",
"SettingsAudioFormatDescription": "when best format is selected, you get audio in best quality available, because audio is kept in its original format. if you select anything other than that, you'll get a slightly compressed file.",
"SettingsAudioFormatDescription": "when best format is selected, you get audio in best quality available, because it's not re-encoded. everything else will be re-encoded.",
"Keyphrase": "save what you love",
"SettingsRemoveWatermark": "disable watermark",
"ErrorPopupCloseButton": "got it",
@ -101,14 +101,14 @@
"MediaPickerExplanationPhoneIOS": "press and hold, hide the preview, and then select \"download linked file\" to save.",
"TwitterSpaceWasntRecorded": "this twitter space wasn't recorded, so there's nothing to download. try another one!",
"ErrorCantProcess": "i couldn't process your request :(\nyou can try again, but if issue persists, please {ContactLink}.",
"ChangelogPressToHide": "press to hide",
"ChangelogPressToHide": "press to collapse",
"Donate": "donate",
"DonateSub": "help me keep it up",
"DonateExplanation": "{appName} does not (and will never) serve ads or sell your data, therefore it's <span class=\"text-backdrop\">completely free to use</span>. 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 <a class=\"text-backdrop\" href=\"{s}\" target=\"_blank\">hire me</a>.",
"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.",
"SettingsVideoMuteExplanation": "disables audio in downloaded video when possible. 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}."
}

View file

@ -52,11 +52,11 @@
"SettingsEnableDownloadPopup": "спрашивать, что делать при скачивании",
"AccessibilityEnableDownloadPopup": "спрашивать, что делать с загрузками",
"SettingsFormatDescription": "выбирай webm, если хочешь максимальное качество. у webm видео битрейт обычно выше, но устройства на ios не могут проигрывать их без сторонних приложений.",
"SettingsQualityDescription": "если выбранное качество недоступно, то выбирается ближайшее к нему.\nесли ты хочешь опубликовать видео с youtube где-то в соц. сетях, то выбирай комбинацию из mp4 и 720p. у таких видео кодек обычно не av1, поэтому они должны работать практически везде.",
"SettingsQualityDescription": "если выбранное качество недоступно, то выбирается ближайшее к нему.\nесли ты хочешь опубликовать видео с youtube где-то в соц. сетях, то выбирай комбинацию из mp4 и 720p.",
"LinkGitHubIssues": "&gt;&gt; сообщай о проблемах и смотри исходный код на github",
"LinkGitHubChanges": "&gt;&gt; смотри предыдущие изменения на github",
"NoScriptMessage": "{appName} использует javascript для обработки ссылок и интерактивного интерфейса. ты должен разрешить использование javascript, чтобы пользоваться сайтом. тут нет никаких трекеров или рекламы, обещаю.",
"DownloadPopupDescriptionIOS": "так как у тебя устройство на ios, тебе нужно зажать кнопку \"скачать\", затем скрыть превью видео и выбрать \"загрузить файл по ссылке\" в появившемся окне.",
"DownloadPopupDescriptionIOS": "зажми кнопку \"скачать\", затем скрой превью видео и выбери \"загрузить файл по ссылке\" в появившемся окне.",
"DownloadPopupDescription": "кнопка скачивания открывает новое окно с файлом. ты можешь отключить выбор метода сохранения файла в настройках.",
"DownloadPopupWayToSave": "выбери, как сохранить",
"ClickToCopy": "нажми, чтобы скопировать",
@ -72,7 +72,7 @@
"AccessibilityModeToggle": "переключить режим скачивания",
"DonateLinksDescription": "ссылки на донаты открываются в новой вкладке. это наилучший способ отправить донат, если ты хочешь, чтобы я получил его напрямую.",
"SettingsAudioFormatBest": "лучший",
"SettingsAudioFormatDescription": "когда выбран \"лучший\" формат, ты получишь аудио максимально возможного качества, так как оно останется в оригинальном формате. если же выбрано что-то другое, то аудио будет немного сжато.",
"SettingsAudioFormatDescription": "когда выбран \"лучший\" формат, ты получишь аудио лучшего качества, так как оно не будет сконвертировано. если же выбрано что-то другое, то аудио будет немного сжато.",
"Keyphrase": "сохраняй то, что любишь",
"SettingsRemoveWatermark": "убрать ватермарку",
"ErrorPopupCloseButton": "ясно",
@ -108,7 +108,7 @@
"DonateVia": "открыть",
"DonateHireMe": "или же ты можешь <a class=\"text-backdrop\" href=\"{s}\" target=\"_blank\">пригласить меня на работу</a>.",
"SettingsVideoMute": "отключить аудио",
"SettingsVideoMuteExplanation": "убирает аудио при загрузке видео, когда это возможно. ты получишь исходное видео напрямую от сервиса, если видео и аудио каналы разбиты по файлам. игнорируется если включен режим аудио или сервис поддерживает только аудио загрузки.",
"SettingsVideoMuteExplanation": "убирает аудио при загрузке видео, когда это возможно. игнорируется если включен режим аудио или сервис поддерживает только аудио загрузки.",
"SettingsVideoGeneral": "основные",
"ErrorSoundCloudNoClientId": "мне не удалось достать client_id, который необходим для получения аудио из soundcloud. попробуй ещё раз, но если так и не получится, {ContactLink}."
}

View file

@ -15,7 +15,7 @@ export function loadLoc() {
}
loadLoc();
export function replaceBase(s) {
return s.replace(/\n/g, '<br/>').replace(/{appName}/g, appName).replace(/{repo}/g, repo)// .replace(/{discord}/g, socials.discord)
return s.replace(/\n/g, '<br/>').replace(/{appName}/g, appName).replace(/{repo}/g, repo).replace(/{bS}/g, '<div class=\"bullpadding\">').replace(/{bE}/g, '</div>').replace(/\*;/g, "&bull;");
}
export function replaceAll(lang, str, string, replacement) {
let s = replaceBase(str[string])

View file

@ -1,15 +1,20 @@
{
"current": {
"version": "4.7",
"title": "we're better together! thank you for bug reports.",
"banner": "bettertogether.webp",
"content": "this update includes a bunch of improvements, many of which were made thanks to the community :D\n\nservice-related improvements:\n*; private soundcloud links are now supported (#68);\n*; tiktok usernames with dots in them no longer confuse cobalt (#71);\n*; .ogg files no longer wrongfully include a video channel (#67);\n*; fixed an issue that caused cobalt to freak out when user attempted to download an audio from audio-only service with \"mute video\" option enabled.\n\nui improvements:\n*; all buttons are now of even size and are displayed without any padding issues across all modern browsers and devices;\n*; checkbox is no longer crippled on ios;\n*; many explanation texts have been simplified to get rid of unnecessary bloat (no bullshit, remember?);\n*; moved tiktok section in video settings higher due to higher priority.\n\nstability improvements:\n*; fixed a memory leak that was caused by misconfigured stream information caching (#63).\n\ninternal improvements:\n*; requested streams are now stored in cache for 2 minutes instead of 1000 hours (yes, 1000 hours, i fucked up);\n*; cached data is now reused if user requests same content within 2 minutes;\n*; page render module is now even cleaner than before;\n*; proper support for bullet-points in loc strings.\n\nyou can suggest features or report bugs either on <a class=\"text-backdrop\" href=\"{repo}\" target=\"_blank\">github</a> or <a class=\"text-backdrop\" href=\"https://twitter.com/justusecobalt\" target=\"_blank\">twitter</a>.\nboth work just fine, use whichever you're more comfortable with.\n\nthank you for using cobalt, and thank you for reading this changelog.\n\nyou're amazing, keep it up :)"
},
"history": [{
"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<div class=\"bullpadding\">&bull; you now can download videos with no audio! simply enable the \"mute audio\" option in settings &gt; audio.\n&bull; soundcloud module has been updated, and downloads should no longer break after some time.</div>\nvisual improvements:\n<div class=\"bullpadding\">&bull; moved some things around in settings popup, and added separators where separation is needed.\n&bull; updated some texts in english and russian.\n&bull; version and commit hash have been joined together, now they're a single unit.</div>\ninternal improvements:\n<div class=\"bullpadding\">&bull; updated api documentation to include isAudioMuted.\n&bull; simplified the startup message.\n&bull; created render elements for separator and explanation due to high duplication of them in the page.\n&bull; fully deprecated GET method for API requests.\n&bull; fixed some code quirks.</div>\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": [{
"content": "i've been longing to implement both of these things, and here they finally are.\n\nservice-related improvements:\n{bS}*; you now can download videos with no audio! simply enable the \"mute audio\" option in settings &gt; audio.\n*; soundcloud module has been updated, and downloads should no longer break after some time.{bE}\nvisual improvements:\n{bS}*; 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.{bE}\ninternal improvements:\n{bS}*; updated api documentation to include isAudioMuted.\n*; simplified the startup message.\n*; created render elements for separator and explanation due to high duplication of them in the page.\n*; fully deprecated GET method for API requests.\n*; fixed some code quirks.{bE}\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."
}, {
"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<div class=\"bullpadding\">&bull; vimeo module has been revamped, all sorts of videos should now be supported.\n&bull; vimeo audio downloads! you now can download audios from more recent videos.\n&bull; {appName} now supports all sorts of tumblr links. (even those scary ones from the mobile app)\n&bull; vk clips support has been fixed. they rolled back the separation of videos and clips, so i had to do the same.\n&bull; youtube videos with community warnings should now be possible to download.</div>\nuser interface improvements:\n<div class=\"bullpadding\">&bull; list of supported services is now MUCH easier to read.\n&bull; banners in changelog history should no longer overlap each other.\n&bull; bullet points! they have a bit of extra padding, so it makes them stand out of the rest of text.</div>\ninternal improvements:\n<div class=\"bullpadding\">&bull; cobalt will now match the link to regex when using ?u= query for autopasting it into input area.\n&bull; 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&bull; moved to my own fork of ytdl-core, cause main project seems to have been abandoned. go check it out on <a class=\"text-backdrop\" href=\"https://github.com/wukko/better-ytdl-core\" target=\"_blank\">github</a> or <a class=\"text-backdrop\" href=\"https://www.npmjs.com/package/better-ytdl-core\" target=\"_blank\">npm</a>!\n&bull; ALL user inputs are now properly sanitized on the server. that includes variables for POST api method, too.\n&bull; \"got\" package has been (mostly) replaced by native fetch api. this should greately reduce ram usage.\n&bull; 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&bull; other code optimizations. there's less clutter overall.</div>\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, <a class=\"text-backdrop\" href=\"https://github.com/wukko/cobalt/issues/62\" target=\"_blank\">please feel free to do it on github!</a>\n\nthank you for reading this, and thank you for sticking with cobalt and me."
"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{bS}*; 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.{bE}\nuser interface improvements:\n{bS}*; 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.{bE}\ninternal improvements:\n{bS}*; 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 <a class=\"text-backdrop\" href=\"https://github.com/wukko/better-ytdl-core\" target=\"_blank\">github</a> or <a class=\"text-backdrop\" href=\"https://www.npmjs.com/package/better-ytdl-core\" target=\"_blank\">npm</a>!\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.{bE}\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, <a class=\"text-backdrop\" href=\"https://github.com/wukko/cobalt/issues/62\" target=\"_blank\">please feel free to do it on github!</a>\n\nthank you for reading this, and thank you for sticking with cobalt and me."
}, {
"version": "4.4",
"title": "over 1 million monthly requests. thank you.",

View file

@ -27,11 +27,14 @@ for (let i in donations["crypto"]) {
donate += `<div class="subtitle${extr}">${i} (REPLACEME)</div><div id="don-${i}" class="text-to-copy" onClick="copy('don-${i}')">${donations["crypto"][i]}</div>`
extr = ' top-margin'
}
export default function(obj) {
audioFormats[0]["text"] = loc(obj.lang, 'SettingsAudioFormatBest');
const t = (str, replace) => { return loc(obj.lang, str, replace) };
let ua = obj.useragent.toLowerCase();
let isIOS = ua.match("iphone os");
let isMobile = ua.match("android") || ua.match("iphone os");
audioFormats[0]["text"] = t('SettingsAudioFormatBest');
try {
return `<!DOCTYPE html>
<html lang="en">
@ -43,10 +46,10 @@ export default function(obj) {
<meta property="og:url" content="${process.env.selfURL}" />
<meta property="og:title" content="${appName}" />
<meta property="og:description" content="${loc(obj.lang, 'EmbedBriefDescription')}" />
<meta property="og:description" content="${t('EmbedBriefDescription')}" />
<meta property="og:image" content="${process.env.selfURL}icons/generic.png" />
<meta name="title" content="${appName}" />
<meta name="description" content="${loc(obj.lang, 'AboutSummary')}" />
<meta name="description" content="${t('AboutSummary')}" />
<meta name="theme-color" content="#000000" />
<meta name="twitter:card" content="summary" />
@ -59,51 +62,51 @@ export default function(obj) {
<link rel="stylesheet" href="cobalt.css" />
<link rel="stylesheet" href="fonts/notosansmono.css" />
<noscript><div style="margin: 2rem;">${loc(obj.lang, 'NoScriptMessage')}</div></noscript>
<noscript><div style="margin: 2rem;">${t('NoScriptMessage')}</div></noscript>
</head>
<body id="cobalt-body" data-nosnippet>
${multiPagePopup({
name: "about",
closeAria: loc(obj.lang, 'AccessibilityClosePopup'),
closeAria: t('AccessibilityClosePopup'),
tabs: [{
name: "about",
title: `${emoji("🐲")} ${loc(obj.lang, 'AboutTab')}`,
title: `${emoji("🐲")} ${t('AboutTab')}`,
content: popup({
name: "about",
header: {
aboveTitle: {
text: loc(obj.lang, 'MadeWithLove'),
text: t('MadeWithLove'),
url: authorInfo.link
},
closeAria: loc(obj.lang, 'AccessibilityClosePopup'),
title: loc(obj.lang, 'TitlePopupAbout')
closeAria: t('AccessibilityClosePopup'),
title: t('TitlePopupAbout')
},
body: [{
text: loc(obj.lang, 'AboutSummary')
text: t('AboutSummary')
}, {
text: `${loc(obj.lang, 'AboutSupportedServices')}`,
text: `${t('AboutSupportedServices')}`,
nopadding: true
}, {
text: `<div class="bullpadding">${enabledServices}.</div>`
}, {
text: obj.lang !== "ru" ? loc(obj.lang, 'FollowTwitter') : "",
text: obj.lang !== "ru" ? t('FollowTwitter') : "",
classes: ["desc-padding"]
}, {
text: backdropLink(repo, loc(obj.lang, 'LinkGitHubIssues')),
text: backdropLink(repo, t('LinkGitHubIssues')),
classes: ["bottom-link"]
}]
})
}, {
name: "changelog",
title: `${emoji("🎉")} ${loc(obj.lang, 'ChangelogTab')}`,
title: `${emoji("🎉")} ${t('ChangelogTab')}`,
content: popup({
name: "changelog",
header: {
closeAria: loc(obj.lang, 'AccessibilityClosePopup'),
title: `${emoji("🪄", 30)} ${loc(obj.lang, 'TitlePopupChangelog')}`
closeAria: t('AccessibilityClosePopup'),
title: `${emoji("🪄", 30)} ${t('TitlePopupChangelog')}`
},
body: [{
text: `<div class="category-title">${loc(obj.lang, 'ChangelogLastMajor')}</div>`,
text: `<div class="category-title">${t('ChangelogLastMajor')}</div>`,
raw: true
}, {
text: changelogManager("banner") ? `<div class="changelog-banner"><img class="changelog-img" src="${changelogManager("banner")}" onerror="this.style.display='none'"></img></div>`: '',
@ -121,48 +124,50 @@ export default function(obj) {
}, {
text: com[1]
}, {
text: backdropLink(`${repo}/commits`, loc(obj.lang, 'LinkGitHubChanges')),
text: backdropLink(`${repo}/commits`, t('LinkGitHubChanges')),
classes: ["bottom-link"]
}, {
text: `<div class="category-title">${loc(obj.lang, 'ChangelogOlder')}</div>`,
text: `<div class="category-title">${t('ChangelogOlder')}</div>`,
raw: true
}, {
text: `<div id="changelog-history"><button class="switch bottom-margin" onclick="loadOnDemand('changelog-history', '0')">${loc(obj.lang, "ChangelogPressToExpand")}</button></div>`,
text: `<div id="changelog-history"><button class="switch bottom-margin" onclick="loadOnDemand('changelog-history', '0')">${t("ChangelogPressToExpand")}</button></div>`,
raw: true
}]
})
}, {
name: "donate",
title: `${emoji("💰")} ${loc(obj.lang, 'DonationsTab')}`,
title: `${emoji("💰")} ${t('DonationsTab')}`,
content: popup({
name: "donate",
header: {
closeAria: loc(obj.lang, 'AccessibilityClosePopup'),
title: emoji("💸", 30) + loc(obj.lang, 'TitlePopupDonate'),
subtitle: loc(obj.lang, 'DonateSub')
closeAria: t('AccessibilityClosePopup'),
title: emoji("💸", 30) + t('TitlePopupDonate')
},
body: [{
text: `<div class="category-title">${t('DonateSub')}</div>`,
raw: true
}, {
text: `<div class="changelog-banner"><img class="changelog-img" src="updateBanners/catsleep.webp" onerror="this.style.display='none'"></img></div>`,
raw: true
},{
text: loc(obj.lang, 'DonateExplanation')
}, {
text: donateLinks.replace(/REPLACEME/g, loc(obj.lang, 'DonateVia')),
text: t('DonateExplanation')
}, {
text: donateLinks.replace(/REPLACEME/g, t('DonateVia')),
raw: true
}, {
text: loc(obj.lang, 'DonateLinksDescription'),
text: t('DonateLinksDescription'),
classes: ["explanation"]
}, {
text: sep(),
raw: true
}, {
text: donate.replace(/REPLACEME/g, loc(obj.lang, 'ClickToCopy')),
text: donate.replace(/REPLACEME/g, t('ClickToCopy')),
classes: ["desc-padding"]
}, {
text: sep(),
raw: true
}, {
text: loc(obj.lang, 'DonateHireMe', authorInfo.link),
text: t('DonateHireMe', authorInfo.link),
classes: ["desc-padding"]
}]
})
@ -170,99 +175,100 @@ export default function(obj) {
})}
${multiPagePopup({
name: "settings",
closeAria: loc(obj.lang, 'AccessibilityClosePopup'),
closeAria: t('AccessibilityClosePopup'),
header: {
aboveTitle: {
text: `v.${version}-${obj.hash}`,
url: `${repo}/commit/${obj.hash}`
},
title: `${emoji("⚙️", 30)} ${loc(obj.lang, 'TitlePopupSettings')}`
title: `${emoji("⚙️", 30)} ${t('TitlePopupSettings')}`
},
tabs: [{
name: "video",
title: `${emoji("🎬")} ${loc(obj.lang, 'SettingsVideoTab')}`,
title: `${emoji("🎬")} ${t('SettingsVideoTab')}`,
content: settingsCategory({
name: "downloads",
title: loc(obj.lang, 'SettingsVideoGeneral'),
title: t('SettingsVideoGeneral'),
body: switcher({
name: "vQuality",
subtitle: loc(obj.lang, 'SettingsQualitySubtitle'),
explanation: loc(obj.lang, 'SettingsQualityDescription'),
subtitle: t('SettingsQualitySubtitle'),
explanation: t('SettingsQualityDescription'),
items: [{
"action": "max",
"text": `${loc(obj.lang, 'SettingsQualitySwitchMax')}<br/>(2160p+)`
"text": `${t('SettingsQualitySwitchMax')}<br/>(2160p+)`
}, {
"action": "hig",
"text": `${loc(obj.lang, 'SettingsQualitySwitchHigh')}<br/>(${quality.hig}p)`
"text": `${t('SettingsQualitySwitchHigh')}<br/>(${quality.hig}p)`
}, {
"action": "mid",
"text": `${loc(obj.lang, 'SettingsQualitySwitchMedium')}<br/>(${quality.mid}p)`
"text": `${t('SettingsQualitySwitchMedium')}<br/>(${quality.mid}p)`
}, {
"action": "low",
"text": `${loc(obj.lang, 'SettingsQualitySwitchLow')}<br/>(${quality.low}p)`
"text": `${t('SettingsQualitySwitchLow')}<br/>(${quality.low}p)`
}]
})
}) + settingsCategory({
name: "youtube",
body: switcher({
name: "vFormat",
subtitle: loc(obj.lang, 'SettingsFormatSubtitle'),
explanation: loc(obj.lang, 'SettingsFormatDescription'),
items: [{
"action": "mp4",
"text": "mp4 (av1)"
}, {
"action": "webm",
"text": "webm (vp9)"
}]
})
})
+ settingsCategory({
name: "tiktok",
title: "tiktok & douyin",
body: checkbox("disableTikTokWatermark", loc(obj.lang, 'SettingsRemoveWatermark'))
})
+ settingsCategory({
name: "tiktok",
title: "tiktok & douyin",
body: checkbox("disableTikTokWatermark", t('SettingsRemoveWatermark'))
})
+ settingsCategory({
name: "youtube",
body: switcher({
name: "vFormat",
subtitle: t('SettingsFormatSubtitle'),
explanation: t('SettingsFormatDescription'),
items: [{
"action": "mp4",
"text": "mp4 (av1)"
}, {
"action": "webm",
"text": "webm (vp9)"
}]
})
})
}, {
name: "audio",
title: `${emoji("🎶")} ${loc(obj.lang, 'SettingsAudioTab')}`,
title: `${emoji("🎶")} ${t('SettingsAudioTab')}`,
content: settingsCategory({
name: "general",
title: loc(obj.lang, 'SettingsAudioTab'),
title: t('SettingsAudioTab'),
body: switcher({
name: "aFormat",
subtitle: loc(obj.lang, 'SettingsFormatSubtitle'),
explanation: loc(obj.lang, 'SettingsAudioFormatDescription'),
subtitle: t('SettingsFormatSubtitle'),
explanation: t('SettingsAudioFormatDescription'),
items: audioFormats
}) + sep(0) + checkbox("muteAudio", loc(obj.lang, 'SettingsVideoMute'), loc(obj.lang, 'SettingsVideoMute'), 3) + explanation(loc(obj.lang, 'SettingsVideoMuteExplanation'))
}) + sep(0) + checkbox("muteAudio", t('SettingsVideoMute'), t('SettingsVideoMute'), 3) + explanation(t('SettingsVideoMuteExplanation'))
}) + settingsCategory({
name: "tiktok",
title: "tiktok & douyin",
body: checkbox("fullTikTokAudio", loc(obj.lang, 'SettingsAudioFullTikTok'), loc(obj.lang, 'SettingsAudioFullTikTok'), 3) + `<div class="explanation">${loc(obj.lang, 'SettingsAudioFullTikTokDescription')}</div>`
body: checkbox("fullTikTokAudio", t('SettingsAudioFullTikTok'), t('SettingsAudioFullTikTok'), 3) + `<div class="explanation">${t('SettingsAudioFullTikTokDescription')}</div>`
})
}, {
name: "other",
title: `${emoji("🪅")} ${loc(obj.lang, 'SettingsOtherTab')}`,
title: `${emoji("🪅")} ${t('SettingsOtherTab')}`,
content: settingsCategory({
name: "appearance",
title: loc(obj.lang, 'SettingsAppearanceSubtitle'),
title: t('SettingsAppearanceSubtitle'),
body: switcher({
name: "theme",
subtitle: loc(obj.lang, 'SettingsThemeSubtitle'),
subtitle: t('SettingsThemeSubtitle'),
items: [{
"action": "auto",
"text": loc(obj.lang, 'SettingsThemeAuto')
"text": t('SettingsThemeAuto')
}, {
"action": "dark",
"text": loc(obj.lang, 'SettingsThemeDark')
"text": t('SettingsThemeDark')
}, {
"action": "light",
"text": loc(obj.lang, 'SettingsThemeLight')
"text": t('SettingsThemeLight')
}]
}) + checkbox("alwaysVisibleButton", loc(obj.lang, 'SettingsKeepDownloadButton'), loc(obj.lang, 'AccessibilityKeepDownloadButton'), 2)
}) + checkbox("alwaysVisibleButton", t('SettingsKeepDownloadButton'), t('AccessibilityKeepDownloadButton'), 2)
}) + settingsCategory({
name: "miscellaneous",
title: loc(obj.lang, 'Miscellaneous'),
body: checkbox("disableChangelog", loc(obj.lang, 'SettingsDisableNotifications')) + `${!isIOS ? checkbox("downloadPopup", loc(obj.lang, 'SettingsEnableDownloadPopup'), loc(obj.lang, 'AccessibilityEnableDownloadPopup'), 1) : ''}`
title: t('Miscellaneous'),
body: checkbox("disableChangelog", t('SettingsDisableNotifications')) + `${!isIOS ? checkbox("downloadPopup", t('SettingsEnableDownloadPopup'), t('AccessibilityEnableDownloadPopup'), 1) : ''}`
})
}],
})}
@ -270,25 +276,25 @@ export default function(obj) {
name: "download",
standalone: true,
header: {
closeAria: loc(obj.lang, 'AccessibilityClosePopup'),
subtitle: loc(obj.lang, 'TitlePopupDownload')
closeAria: t('AccessibilityClosePopup'),
subtitle: t('TitlePopupDownload')
},
body: switcher({
name: "download",
subtitle: loc(obj.lang, 'DownloadPopupWayToSave'),
explanation: `${!isIOS ? loc(obj.lang, 'DownloadPopupDescription') : loc(obj.lang, 'DownloadPopupDescriptionIOS')}`,
items: `<a id="pd-download" class="switch full space-right" target="_blank" href="/">${loc(obj.lang, 'Download')}</a>
<div id="pd-copy" class="switch full">${loc(obj.lang, 'CopyURL')}</div>`
subtitle: t('DownloadPopupWayToSave'),
explanation: `${!isIOS ? t('DownloadPopupDescription') : t('DownloadPopupDescriptionIOS')}`,
items: `<a id="pd-download" class="switch full space-right" target="_blank" href="/">${t('Download')}</a>
<div id="pd-copy" class="switch full">${t('CopyURL')}</div>`
})
})}
${popupWithBottomButtons({
name: "picker",
closeAria: loc(obj.lang, 'AccessibilityClosePopup'),
closeAria: t('AccessibilityClosePopup'),
header: {
title: `<div id="picker-title"></div>`,
explanation: `<div id="picker-subtitle"></div>`,
},
buttons: [`<a id="picker-download" class="switch" target="_blank" href="/">${loc(obj.lang, 'ImagePickerDownloadAudio')}</a>`],
buttons: [`<a id="picker-download" class="switch" target="_blank" href="/">${t('ImagePickerDownloadAudio')}</a>`],
content: '<div id="picker-holder"></div>'
})}
${popup({
@ -297,10 +303,10 @@ export default function(obj) {
buttonOnly: true,
emoji: emoji("☹️", 48, 1),
classes: ["small"],
buttonText: loc(obj.lang, 'ErrorPopupCloseButton'),
buttonText: t('ErrorPopupCloseButton'),
header: {
closeAria: loc(obj.lang, 'AccessibilityClosePopup'),
title: loc(obj.lang, 'TitlePopupError')
closeAria: t('AccessibilityClosePopup'),
title: t('TitlePopupError')
},
body: `<div id="desc-error" class="desc-padding subtext"></div>`
})}
@ -309,13 +315,13 @@ export default function(obj) {
<div id="logo-area">${appName}</div>
<div id="download-area" class="mobile-center">
<div id="top">
<input id="url-input-area" class="mono" type="text" autocorrect="off" maxlength="128" autocapitalize="off" placeholder="${loc(obj.lang, 'LinkInput')}" aria-label="${loc(obj.lang, 'AccessibilityInputArea')}" oninput="button()"></input>
<input id="url-input-area" class="mono" type="text" autocorrect="off" maxlength="128" autocapitalize="off" placeholder="${t('LinkInput')}" aria-label="${t('AccessibilityInputArea')}" oninput="button()"></input>
<button id="url-clear" onclick="clearInput()" style="display:none;">x</button>
<input id="download-button" class="mono dontRead" onclick="download(document.getElementById('url-input-area').value)" type="submit" value="" disabled=true aria-label="${loc(obj.lang, 'AccessibilityDownloadButton')}">
<input id="download-button" class="mono dontRead" onclick="download(document.getElementById('url-input-area').value)" type="submit" value="" disabled=true aria-label="${t('AccessibilityDownloadButton')}">
</div>
<div id="bottom">
<button id="pasteFromClipboard" class="switch" onclick="pasteClipboard()" aria-label="${loc(obj.lang, 'PasteFromClipboard')}">${emoji("📋", 22)} ${loc(obj.lang, 'PasteFromClipboard')}</button>
<button id="audioMode" class="switch" onclick="toggle('audioMode')" aria-label="${loc(obj.lang, 'AccessibilityModeToggle')}">${emoji("✨", 22, 1)}</button>
<button id="pasteFromClipboard" class="switch" onclick="pasteClipboard()" aria-label="${t('PasteFromClipboard')}">${emoji("📋", 22)} ${t('PasteFromClipboard')}</button>
<button id="audioMode" class="switch" onclick="toggle('audioMode')" aria-label="${t('AccessibilityModeToggle')}">${emoji("✨", 22, 1)}</button>
</div>
</div>
</div>
@ -324,38 +330,37 @@ export default function(obj) {
footerButtons([{
name: "about",
type: "popup",
text: `${emoji(celebrationsEmoji() , 22)} ${loc(obj.lang, 'AboutTab')}`,
aria: loc(obj.lang, 'AccessibilityOpenAbout')
text: `${emoji(celebrationsEmoji() , 22)} ${t('AboutTab')}`,
aria: t('AccessibilityOpenAbout')
}, {
name: "about",
type: "popup",
context: "donate",
text: `${emoji("💰", 22)} ${loc(obj.lang, 'Donate')}`,
aria: loc(obj.lang, 'AccessibilityOpenDonate')
text: `${emoji("💰", 22)} ${t('Donate')}`,
aria: t('AccessibilityOpenDonate')
}, {
name: "settings",
type: "popup",
text: `${emoji("⚙️", 22)} ${loc(obj.lang, 'TitlePopupSettings')}`,
aria: loc(obj.lang, 'AccessibilityOpenSettings')
}]
)}
text: `${emoji("⚙️", 22)} ${t('TitlePopupSettings')}`,
aria: t('AccessibilityOpenSettings')
}])}
</footer>
</body>
<script type="text/javascript">const loc = {
noInternet: ` + "`" + loc(obj.lang, 'ErrorNoInternet') + "`" + `,
noURLReturned: ` + "`" + loc(obj.lang, 'ErrorNoUrlReturned') + "`" + `,
unknownStatus: ` + "`" + loc(obj.lang, 'ErrorUnknownStatus') + "`" + `,
collapseHistory: ` + "`" + loc(obj.lang, 'ChangelogPressToHide') + "`" + `,
toggleDefault: '${emoji("✨")} ${loc(obj.lang, "ModeToggleAuto")}',
toggleAudio: '${emoji("🎶")} ${loc(obj.lang, "ModeToggleAudio")}',
pickerDefault: ` + "`" + loc(obj.lang, 'MediaPickerTitle') + "`" + `,
pickerImages: ` + "`" + loc(obj.lang, 'ImagePickerTitle') + "`" + `,
pickerImagesExpl: ` + "`" + loc(obj.lang, `ImagePickerExplanation${isMobile ? "Phone" : "PC"}`) + "`" + `,
pickerDefaultExpl: ` + "`" + loc(obj.lang, `MediaPickerExplanation${isMobile ? `Phone${isIOS ? "IOS" : ""}` : "PC"}`) + "`" + `,
noInternet: ` + "`" + t('ErrorNoInternet') + "`" + `,
noURLReturned: ` + "`" + t('ErrorNoUrlReturned') + "`" + `,
unknownStatus: ` + "`" + t('ErrorUnknownStatus') + "`" + `,
collapseHistory: ` + "`" + t('ChangelogPressToHide') + "`" + `,
toggleDefault: '${emoji("✨")} ${t("ModeToggleAuto")}',
toggleAudio: '${emoji("🎶")} ${t("ModeToggleAudio")}',
pickerDefault: ` + "`" + t('MediaPickerTitle') + "`" + `,
pickerImages: ` + "`" + t('ImagePickerTitle') + "`" + `,
pickerImagesExpl: ` + "`" + t(`ImagePickerExplanation${isMobile ? "Phone" : "PC"}`) + "`" + `,
pickerDefaultExpl: ` + "`" + t(`MediaPickerExplanation${isMobile ? `Phone${isIOS ? "IOS" : ""}` : "PC"}`) + "`" + `,
};</script>
<script type="text/javascript" src="cobalt.js"></script>
</html>`;
} catch (err) {
return `${loc(obj.lang, 'ErrorPageRenderFail', obj.hash)}`;
return `${t('ErrorPageRenderFail', obj.hash)}`;
}
}

View file

@ -81,7 +81,7 @@ export default async function (host, patternMatch, url, lang, obj) {
noWatermark: obj.isNoTTWatermark, fullAudio: obj.isTTFullAudio,
isAudioOnly: obj.isAudioOnly
});
if (r.isAudioOnly) obj.isAudioOnly = true
if (r.isAudioOnly) obj.isAudioOnly = true;
break;
case "tumblr":
r = await tumblr({
@ -100,6 +100,7 @@ export default async function (host, patternMatch, url, lang, obj) {
r = await soundcloud({
author: patternMatch["author"], song: patternMatch["song"], url: url,
shortLink: patternMatch["shortLink"] ? patternMatch["shortLink"] : false,
accessKey: patternMatch["accessKey"] ? patternMatch["accessKey"] : false,
format: obj.aFormat,
lang: lang
});

View file

@ -51,7 +51,7 @@ export default function(r, host, ip, audioFormat, isAudioOnly, lang, isAudioMute
return apiJSON(1, { u: r.urls });
}
}
} else if (isAudioMuted) {
} else if (isAudioMuted && !isAudioOnly) {
let isSplit = Array.isArray(r.urls);
return apiJSON(2, {
type: isSplit ? "bridge" : "mute",
@ -81,13 +81,13 @@ export default function(r, host, ip, audioFormat, isAudioOnly, lang, isAudioMute
picker: r.picker, service: host
})
}
} else {
} else if (isAudioOnly) {
if ((host === "reddit" && r.typeId === 1) || (host === "vimeo" && !r.filename) || audioIgnore.includes(host)) return apiJSON(0, { t: loc(lang, 'ErrorEmptyDownload') });
let type = "render";
let copy = false;
if (!supportedAudio.includes(audioFormat)) audioFormat = "best";
if ((host == "tiktok" || host == "douyin") && isAudioOnly && services.tiktok.audioFormats.includes(audioFormat)) {
if ((host == "tiktok" || host == "douyin") && services.tiktok.audioFormats.includes(audioFormat)) {
if (r.isMp3) {
if (audioFormat === "mp3" || audioFormat === "best") {
audioFormat = "mp3"
@ -115,5 +115,7 @@ export default function(r, host, ip, audioFormat, isAudioOnly, lang, isAudioMute
filename: r.audioFilename, isAudioOnly: true,
audioFormat: audioFormat, copy: copy, fileMetadata: r.fileMetadata ? r.fileMetadata : false
})
} else {
return apiJSON(0, { t: loc(lang, 'ErrorSomethingWentWrong') });
}
}

View file

@ -84,7 +84,7 @@
"enabled": true
},
"soundcloud": {
"patterns": [":author/:song", ":shortLink"],
"patterns": [":author/:song/s-:accessKey", ":author/:song", ":shortLink"],
"bestAudio": "none",
"enabled": true
}

View file

@ -44,7 +44,7 @@ export default async function(obj) {
}).then((r) => {return r.text()}).catch(() => {return false});
}
if (obj.author && obj.song) {
html = await fetch(`https://soundcloud.com/${obj.author}/${obj.song}`, {
html = await fetch(`https://soundcloud.com/${obj.author}/${obj.song}${obj.accessKey ? `/s-${obj.accessKey}` : ''}`, {
headers: {"user-agent": genericUserAgent}
}).then((r) => {return r.text()}).catch(() => {return false});
}
@ -54,7 +54,8 @@ export default async function(obj) {
if (json["media"]["transcodings"]) {
let clientId = await findClientID();
if (clientId) {
let fileUrl = `${json.media.transcodings[0]["url"].replace("/hls", "/progressive")}?client_id=${clientId}&track_authorization=${json.track_authorization}`;
let fileUrlBase = json.media.transcodings[0]["url"].replace("/hls", "/progressive")
let fileUrl = `${fileUrlBase}${fileUrlBase.includes("?") ? "&" : "?"}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});

View file

@ -1,40 +1,50 @@
import NodeCache from "node-cache";
import { UUID, encrypt } from "../sub/crypto.js";
import { sha256 } from "../sub/crypto.js";
import { streamLifespan } from "../config.js";
const streamCache = new NodeCache({ stdTTL: streamLifespan, checkperiod: 120 });
const streamCache = new NodeCache({ stdTTL: streamLifespan/1000, checkperiod: 10, deleteOnExpire: true });
const salt = process.env.streamSalt;
export function createStream(obj) {
let streamUUID = UUID(),
exp = Math.floor(new Date().getTime()) + streamLifespan,
ghmac = encrypt(`${streamUUID},${obj.service},${obj.ip},${exp}`, salt)
streamCache.on("expired", (key) => {
streamCache.del(key);
});
streamCache.set(streamUUID, {
id: streamUUID,
service: obj.service,
type: obj.type,
urls: obj.u,
filename: obj.filename,
hmac: ghmac,
ip: obj.ip,
exp: exp,
isAudioOnly: !!obj.isAudioOnly,
audioFormat: obj.audioFormat,
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}`;
export function createStream(obj) {
let streamID = sha256(`${obj.ip},${obj.service},${obj.filename},${obj.audioFormat},${obj.mute}`, salt),
exp = Math.floor(new Date().getTime()) + streamLifespan,
ghmac = sha256(`${streamID},${obj.service},${obj.ip},${exp}`, salt);
if (!streamCache.has(streamID)) {
streamCache.set(streamID, {
id: streamID,
service: obj.service,
type: obj.type,
urls: obj.u,
filename: obj.filename,
hmac: ghmac,
ip: obj.ip,
exp: exp,
isAudioOnly: !!obj.isAudioOnly,
audioFormat: obj.audioFormat,
time: obj.time ? obj.time : false,
copy: !!obj.copy,
mute: !!obj.mute,
metadata: obj.fileMetadata ? obj.fileMetadata : false
});
} else {
let streamInfo = streamCache.get(streamID);
exp = streamInfo.exp;
ghmac = streamInfo.hmac;
}
return `${process.env.selfURL}api/stream?t=${streamID}&e=${exp}&h=${ghmac}`;
}
export function verifyStream(ip, id, hmac, exp) {
try {
let streamInfo = streamCache.get(id);
if (streamInfo) {
let ghmac = encrypt(`${id},${streamInfo.service},${ip},${exp}`, salt);
let ghmac = sha256(`${id},${streamInfo.service},${ip},${exp}`, salt);
if (hmac == ghmac && ip == streamInfo.ip && ghmac == streamInfo.hmac && exp > Math.floor(new Date().getTime()) && exp == streamInfo.exp) {
return streamInfo;
} else {

View file

@ -1,8 +1,5 @@
import { createHmac, randomUUID } from "crypto";
import { createHmac } from "crypto";
export function encrypt(str, salt) {
export function sha256(str, salt) {
return createHmac("sha256", salt).update(str).digest("hex");
}
export function UUID() {
return randomUUID();
}

View file

@ -62,7 +62,18 @@ export function msToTime(d) {
return r;
}
export function cleanURL(url, host) {
let forbiddenChars = ['}', '{', '(', ')', '\\', '@', '%', '>', '<', '^', '*', '!', '~', ';', ':', ',', '`', '[', ']', '#', '$', '"', "'"]
let forbiddenChars = ['}', '{', '(', ')', '\\', '%', '>', '<', '^', '*', '!', '~', ';', ':', ',', '`', '[', ']', '#', '$', '"', "'", "@"]
switch(host) {
case "youtube":
url = url.split('&')[0];
break;
case "tiktok":
url = url.replace(/@([a-zA-Z]+(\.[a-zA-Z]+)+)/, "@a")
default:
url = url.split('?')[0];
if (url.substring(url.length - 1) === "/") url = url.substring(0, url.length - 1);
break;
}
for (let i in forbiddenChars) {
url = url.replaceAll(forbiddenChars[i], '')
}
@ -70,14 +81,6 @@ export function cleanURL(url, host) {
if (url.includes('youtube.com/shorts/')) {
url = url.split('?')[0].replace('shorts/', 'watch?v=');
}
if (host === "youtube") {
url = url.split('&')[0];
} else {
url = url.split('?')[0];
if (url.substring(url.length - 1) === "/") {
url = url.substring(0, url.length - 1);
}
}
return url.slice(0, 128)
}
export function languageCode(req) {