From 189ecf8fe7727360d31a1dbc43d6eca3fb53095a Mon Sep 17 00:00:00 2001 From: wukko Date: Mon, 22 Aug 2022 20:10:54 +0600 Subject: [PATCH] soundcloud and tooltip and some other stuff (3.3) --- README.md | 7 +++++ package.json | 2 +- src/config.json | 1 + src/front/cobalt.css | 12 ++++++++ src/front/cobalt.js | 7 +++-- src/localization/languages/en.json | 16 +++++----- src/localization/languages/ru.json | 12 ++++---- src/localization/languages/uk.json | 10 ++++--- src/modules/api.js | 4 +++ src/modules/config.js | 1 + src/modules/match.js | 10 +++++++ src/modules/pageRender/elements.js | 10 +++---- src/modules/pageRender/page.js | 12 ++++++-- src/modules/services/soundcloud.js | 42 +++++++++++++++++++++++++++ src/modules/servicesConfig.json | 7 +++++ src/modules/servicesPatternTesters.js | 3 ++ src/modules/sub/matchActionDecider.js | 16 +++++----- 17 files changed, 135 insertions(+), 37 deletions(-) create mode 100644 src/modules/services/soundcloud.js diff --git a/README.md b/README.md index 8617c90b..67d45203 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,13 @@ It preserves original media quality so you get best downloads possible (unless y - Polish: [@hexandcube](https://github.com/hexandcube) - Ukrainian: Löffel +## Languages that are always up to date +- English +- Russian +- Ukrainian + +Other languages may be missing some strings or changes, you can help with updating those! + ## How you can help cobalt speak your language Take English or Russian localization from [this directory](https://github.com/wukko/cobalt/tree/current/src/localization/languages) and use it as a base for your translation. Then simply make a pull request and it'll be out for everyone upon review! diff --git a/package.json b/package.json index de45f81d..1c272a79 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cobalt", "description": "save what you love", - "version": "3.2", + "version": "3.3", "author": "wukko", "exports": "./src/cobalt.js", "type": "module", diff --git a/src/config.json b/src/config.json index c36d0379..8434c240 100644 --- a/src/config.json +++ b/src/config.json @@ -1,6 +1,7 @@ { "streamLifespan": 3600000, "maxVideoDuration": 1920000, + "maxAudioDuration": 4200000, "genericUserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36", "authorInfo": { "name": "wukko", diff --git a/src/front/cobalt.css b/src/front/cobalt.css index e849e471..3218e799 100644 --- a/src/front/cobalt.css +++ b/src/front/cobalt.css @@ -453,6 +453,18 @@ input[type="checkbox"] { .emoji { margin-right: 0.4rem; } +.tooltip { + position: absolute; + margin-top: -6rem; + margin-left: -0.5rem; + line-height: 1.2; + text-align: left; + pointer-events: none; + color: var(--accent-unhover-2)!important; +} +.button:active .tooltip { + display: none; +} /* adapt the page according to screen size */ @media screen and (min-width: 2300px) { html { diff --git a/src/front/cobalt.js b/src/front/cobalt.js index 3010989c..85ba641e 100644 --- a/src/front/cobalt.js +++ b/src/front/cobalt.js @@ -1,5 +1,5 @@ let isIOS = navigator.userAgent.toLowerCase().match("iphone os"); -let version = 4 +let version = 5; let switchers = { "theme": ["auto", "light", "dark"], @@ -7,7 +7,7 @@ let switchers = { "quality": ["max", "hig", "mid", "low"], "audioFormat": ["best", "mp3", "ogg", "wav", "opus"] } -let exceptions = { // fuck you apple +let exceptions = { // used solely for ios devices, because they're less capable than everything else. "ytFormat": "mp4", "audioFormat": "mp3" } @@ -197,6 +197,7 @@ function toggle(toggle) { let state = sGet(toggle); if (state) { sSet(toggle, opposite(state)) + if (opposite(state) == "true") sSet(`${toggle}ToggledOnce`, "true"); } else { sSet(toggle, "false") } @@ -208,7 +209,7 @@ function updateToggle(toggle, state) { eid(toggle).innerHTML = loc.toggleAudio; break; case "false": - eid(toggle).innerHTML = loc.toggleDefault; + eid(toggle).innerHTML = sGet(`${toggle}ToggledOnce`) == "true" ? loc.toggleDefault : loc.pressToChange + loc.toggleDefault; break; } } diff --git a/src/localization/languages/en.json b/src/localization/languages/en.json index c0cc9d6b..212b57cc 100644 --- a/src/localization/languages/en.json +++ b/src/localization/languages/en.json @@ -5,10 +5,10 @@ "ContactLink": "let me know" }, "strings": { - "ChangelogContentTitle": "ukrainian localization and new error popup (3.2)", - "FollowTwitter": "follow cobalt's twitter account for polls, updates, and more: @justusecobalt", - "ChangelogContent": "- added ukrainian localization (thanks to löffel).\n- new error popup! it's now prettier, more compact, and has an easily accessible close button.\n- russian localization has been patched up a bit\n- cleaned up css a bit\n- added github contributors to made with love message.\n- emojis have been tuned to have the same shade of yellow.\n- updated translation guidelines in readme a bit.", + "ChangelogContentTitle": "soundcloud and better usability (3.3)", + "ChangelogContent": "- full support for soundcloud is here. you now can save your favorite songs from there, if you want to.\n- did you know that there's an audio download mode in cobalt? if you didn't, there's now a tooltip that shows you how to switch between modes.\n- added length limit to conversion of audios, because converting a 3 hour audio to wav will give you a 4gb file, and that's just unreasonable. you can still download audio in original (best) format without any limits.\n- if best and preferred audio format match, cobalt won't needlessly convert the audio anymore.\n- fixed format override for ios, you still might have to toggle between them once.\n- increased input area length limit on frontend because some reddit and soundcloud links wouldn't fit.\n- version in settings now opens current commit page on github, instead of general commits page. it also opens in a new tab instead of replacing the current one.\n- fixed some localization stuff in english, russian, and ukrainian. it's now easier to understand what mode is on, and general cobalt description in russian doesn't sound awkward anymore.", + "FollowTwitter": "follow cobalt's twitter account for polls, updates, and more: @justusecobalt", "LinkInput": "paste the link here", "AboutSummary": "{appName} is your go-to place for social media downloads. zero ads, trackers, or any other creepy bullshit attached. simply paste a share link and you're ready to rock!", "AboutSupportedServices": "currently supported services:", @@ -57,7 +57,6 @@ "SettingsQualitySwitchMedium": "medium\n", "SettingsQualitySwitchLow": "low\n", "SettingsQualitySwitchLowest": "lowest", - "SettingsFormatSwitchAudio": "only audio", "SettingsKeepDownloadButton": "keep >> visible", "AccessibilityKeepDownloadButton": "keep the download button always visible", "SettingsEnableDownloadPopup": "ask for a way to save", @@ -73,7 +72,7 @@ "DownloadPopupDescriptionIOS": "since you have an ios device, you have to press and hold the download button and then select \"download video\" 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.", "DownloadPopupDescription": "download button opens a new tab with requested file. you can disable this popup in settings.", "DownloadPopupWayToSave": "pick a way to save", - "ClickToCopy": "click to copy", + "ClickToCopy": "press to copy", "Download": "download", "CopyURL": "copy url", "AboutTab": "about", @@ -84,7 +83,6 @@ "SettingsOtherTab": "other", "ChangelogLastCommit": "last commit", "ChangelogLastMajor": "last major update", - "ModeToggleDefault": "smart mode", "AccessibilityModeToggle": "toggle download mode", "DonateLinksDescription": "donation links open in a new tab. this is the best way to donate money, if you want me to receive it directly.", "SettingsAudioFormatBest": "best", @@ -92,6 +90,10 @@ "Keyphrase": "save what you love", "SettingsDisableChangelogOnUpdate": "don't show changelog after major updates", "SettingsRemoveWatermark": "disable watermark", - "ErrorPopupCloseButton": "got it" + "ErrorPopupCloseButton": "got it", + "ModeToggle": "mode", + "ModeToggleSmart": "smart", + "PressToChange": "press to change", + "ErrorLengthAudioConvert": "current length limit for audio conversion is {s} minutes. pick \"best\" format instead!" } } diff --git a/src/localization/languages/ru.json b/src/localization/languages/ru.json index c5dbfd70..203bdd71 100644 --- a/src/localization/languages/ru.json +++ b/src/localization/languages/ru.json @@ -6,10 +6,10 @@ }, "strings": { "LinkInput": "вставь ссылку сюда", - "AboutSummary": "{appName} — твой друг при скачивании контента из соц. сетей. никакой рекламы или трекеров. вставляешь ссылку, получаешь файл, наслаждаешься жизнью.", + "AboutSummary": "{appName} — твой друг при скачивании контента из соц. сетей. никакой рекламы или трекеров. вставляешь ссылку и получаешь файл. ничего лишнего.", "AboutSupportedServices": "что поддерживается:", "EmbedBriefDescription": "сохраняй что хочешь, без мороки и вторжения в личное пространство", - "MadeWithLove": "сделано с <3 всеми контрибьюторами на гитхабе и wukko", + "MadeWithLove": "сделано с <3 контрибьюторами на гитхабе и wukko", "AccessibilityInputArea": "зона вставки ссылки", "AccessibilityOpenAbout": "открыть окно с информацией", "AccessibilityDownloadButton": "кнопка скачивания", @@ -53,7 +53,6 @@ "SettingsQualitySwitchMedium": "среднее\n", "SettingsQualitySwitchLow": "низкое\n", "SettingsQualitySwitchLowest": "худшее", - "SettingsFormatSwitchAudio": "только аудио", "SettingsKeepDownloadButton": "оставлять >> на экране", "AccessibilityKeepDownloadButton": "оставлять кнопку скачивания на экране", "SettingsEnableDownloadPopup": "спрашивать, как сохранять", @@ -80,7 +79,6 @@ "SettingsOtherTab": "другое", "ChangelogLastCommit": "последний коммит (на английском)", "ChangelogLastMajor": "последнее обновление (на английском)", - "ModeToggleDefault": "умный режим", "AccessibilityModeToggle": "переключить режим скачивания", "DonateLinksDescription": "ссылки на донаты открываются в новой вкладке. это лучший метод пожертвовать деньги, если ты хочешь, чтобы я получил их лично, а не в виде крипто.", "SettingsAudioFormatBest": "лучший", @@ -88,6 +86,10 @@ "Keyphrase": "сохраняй то, что любишь", "SettingsDisableChangelogOnUpdate": "не показывать изменения после обновлений", "SettingsRemoveWatermark": "убрать ватермарку", - "ErrorPopupCloseButton": "ясно" + "ErrorPopupCloseButton": "ясно", + "ModeToggle": "режим", + "ModeToggleSmart": "умный", + "PressToChange": "нажми, чтобы изменить", + "ErrorLengthAudioConvert": "я не могу конвертировать аудио дольше чем {s} минут(ы). выбери \"лучший\" формат аудио, чтобы скачать аудио такой продолжительности." } } diff --git a/src/localization/languages/uk.json b/src/localization/languages/uk.json index ad997d10..e9fe44fc 100644 --- a/src/localization/languages/uk.json +++ b/src/localization/languages/uk.json @@ -9,7 +9,7 @@ "AboutSummary": "{appName} – твій помічник із завантаження контенту з соцмереж. ніякої реклами, ніяких трекерів. вставляєш лінк, отримаєш файл, і допиваєш у спокої свій смузі.", "AboutSupportedServices": "ось що підтримується:", "EmbedBriefDescription": "зберігай контент із соцмереж без реклами і трекерів", - "MadeWithLove": "зроблено з <3 всіма контриб'юторами на github и wukko <3", + "MadeWithLove": "зроблено з <3 контриб'юторами на github и wukko <3", "AccessibilityInputArea": "строка, щоб вставити в неї лінк", "AccessibilityOpenAbout": "відкрити інфу про {appName}", "AccessibilityDownloadButton": "кнопка завантаження", @@ -53,7 +53,6 @@ "SettingsQualitySwitchMedium": "середня\n", "SettingsQualitySwitchLow": "низька\n", "SettingsQualitySwitchLowest": "найнижча", - "SettingsFormatSwitchAudio": "тільки аудіо", "SettingsKeepDownloadButton": "зробити >> видимим", "AccessibilityKeepDownloadButton": "завжди показувати кнопку завантаження", "SettingsEnableDownloadPopup": "питати щодо засобу зберігання", @@ -80,7 +79,6 @@ "SettingsOtherTab": "інше", "ChangelogLastCommit": "останній коммит (англійською мовою)", "ChangelogLastMajor": "останнє велике оновлення (англійською мовою)", - "ModeToggleDefault": "розумний режим", "AccessibilityModeToggle": "змінити режим завантаження", "DonateLinksDescription": "лінки на донати відкриваються у нових вкладках. це найкращій спосіб донатити, якщо хочеш, щоб ми безпосередньо отримували гроші.", "SettingsAudioFormatBest": "найкращий", @@ -88,6 +86,10 @@ "Keyphrase": "збережи, що любиш", "SettingsDisableChangelogOnUpdate": "не показувати \"що нового\" після великих оновлень", "SettingsRemoveWatermark": "прибрати вотермарку", - "ErrorPopupCloseButton": "ясно" + "ErrorPopupCloseButton": "ясно", + "ModeToggle": "режим", + "ModeToggleSmart": "розумний", + "PressToChange": "натисни, щоб змінити", + "ErrorLengthAudioConvert": "я не можу конвертувати аудіо довше ніж {s} хвилин (и). вибери \"найкращий\" формат аудіо, щоб завантажити аудіо такої тривалості." } } diff --git a/src/modules/api.js b/src/modules/api.js index 30cc5e96..ac42c380 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -18,6 +18,10 @@ export async function getJSON(originalURL, ip, lang, format, quality, audioForma host = "youtube"; url = `https://youtube.com/watch?v=${url.replace("youtu.be/", "").replace("https://", "")}`; } + if (host == "goo" && url.substring(0, 30) == "https://soundcloud.app.goo.gl/") { + host = "soundcloud" + url = `https://soundcloud.com/${url.replace("https://soundcloud.app.goo.gl/", "").split('/')[0]}` + } if (host == "tumblr" && !url.includes("blog/view")) { if (url.slice(-1) == '/') url = url.slice(0, -1); url = url.replace(url.split('/')[5], ''); diff --git a/src/modules/config.js b/src/modules/config.js index a8bb8424..297f15f1 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -8,6 +8,7 @@ export const version = packageJson.version, streamLifespan = config.streamLifespan, maxVideoDuration = config.maxVideoDuration, + maxAudioDuration = config.maxAudioDuration, genericUserAgent = config.genericUserAgent, repo = packageJson["bugs"]["url"].replace('/issues', ''), authorInfo = config.authorInfo, diff --git a/src/modules/match.js b/src/modules/match.js index 66cd4833..5ab12dbc 100644 --- a/src/modules/match.js +++ b/src/modules/match.js @@ -13,6 +13,7 @@ import douyin from "./services/douyin.js"; import tumblr from "./services/tumblr.js"; import matchActionDecider from "./sub/matchActionDecider.js"; import vimeo from "./services/vimeo.js"; +import soundcloud from "./services/soundcloud.js"; export default async function (host, patternMatch, url, ip, lang, format, quality, audioFormat, isAudioOnly, noWatermark) { try { @@ -91,6 +92,15 @@ export default async function (host, patternMatch, url, ip, lang, format, qualit lang: lang }); break; + case "soundcloud": + isAudioOnly = true; + r = await soundcloud({ + author: patternMatch["author"], song: patternMatch["song"], url: url, + shortLink: patternMatch["shortLink"] ? patternMatch["shortLink"] : false, + format: audioFormat, + lang: lang + }); + break; default: return apiJSON(0, { t: errorUnsupported(lang) }); } diff --git a/src/modules/pageRender/elements.js b/src/modules/pageRender/elements.js index 410d844a..082fe36b 100644 --- a/src/modules/pageRender/elements.js +++ b/src/modules/pageRender/elements.js @@ -44,7 +44,7 @@ export function popup(obj) { ${obj.buttonOnly ? obj.emoji : ``} @@ -52,7 +52,7 @@ export function popup(obj) { ${body}${obj.buttonOnly ? `` : ''} ${obj.footer ? `` : ''} ${obj.standalone ? `` : ''}` } @@ -69,7 +69,7 @@ export function multiPagePopup(obj) {