diff --git a/.gitignore b/.gitignore
index 8f5e467c..75454837 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
node_modules
package-lock.json
-.env
\ No newline at end of file
+.env
diff --git a/README.md b/README.md
index b29c1162..51b38d3c 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# cobalt
Sleek and easy to use social media downloader built on JavaScript. Try it out live: [co.wukko.me](https://co.wukko.me/)!
-![cobalt logo](https://raw.githubusercontent.com/wukko/cobalt/current/files/icons/wide.png "cobalt logo")
+![cobalt logo](https://raw.githubusercontent.com/wukko/cobalt/current/src/static/icons/wide.png "cobalt logo")
## What is cobalt?
Everyone is annoyed by the mess video downloaders are on the web, and cobalt aims to be the ultimate social media downloader, that is efficient, pretty, and doesn't bother you with ads or privacy invasion agreement popups.
diff --git a/modules/config.js b/modules/config.js
deleted file mode 100644
index 9e3e8d11..00000000
--- a/modules/config.js
+++ /dev/null
@@ -1,19 +0,0 @@
-import loadJson from "./sub/load-json.js";
-
-let config = loadJson("./config.json");
-let services = loadJson("./modules/services/all.json");
-
-let appName = config.appName
-let version = config.version
-let streamLifespan = config.streamLifespan
-let maxVideoDuration = config.maxVideoDuration
-let genericUserAgent = config.genericUserAgent
-let repo = config.repo
-let authorInfo = config.authorInfo
-let supportedLanguages = config.supportedLanguages
-let quality = config.quality
-let internetExplorerRedirect = config.internetExplorerRedirect
-let donations = config.donations
-let ffmpegArgs = config.ffmpegArgs
-
-export {appName, version, streamLifespan, maxVideoDuration, genericUserAgent, repo, authorInfo, services, supportedLanguages, quality, internetExplorerRedirect, donations, ffmpegArgs}
\ No newline at end of file
diff --git a/package.json b/package.json
index b48a2f6f..b9c52126 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cobalt",
- "description": "easy to use social media downloader",
+ "description": "probably the friendliest social media downloader yet",
"version": "2.2",
"author": "wukko",
"exports": "./cobalt.js",
@@ -9,8 +9,8 @@
"node": ">=14.16"
},
"scripts": {
- "start": "node cobalt",
- "setup": "node modules/setup.js"
+ "start": "node src/cobalt",
+ "setup": "node src/modules/setup"
},
"repository": {
"type": "git",
diff --git a/cobalt.js b/src/cobalt.js
similarity index 97%
rename from cobalt.js
rename to src/cobalt.js
index 2f6539a8..d6cccb86 100644
--- a/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/page-renderer.js";
import { apiJSON } from "./modules/sub/api-helper.js";
-import loc from "./modules/sub/loc.js";
+import loc from "./modules/sub/i18n.js";
import { Bright, Cyan } from "./modules/sub/console-text.js";
import stream from "./modules/stream/stream.js";
@@ -19,7 +19,7 @@ const app = express();
app.disable('x-powered-by');
-if (fs.existsSync('./.env') && fs.existsSync('./config.json')) {
+if (fs.existsSync('./.env')) {
const apiLimiter = rateLimit({
windowMs: 20 * 60 * 1000,
max: 100,
@@ -41,7 +41,7 @@ if (fs.existsSync('./.env') && fs.existsSync('./config.json')) {
app.use('/api/', apiLimiter);
app.use('/api/stream', apiLimiterStream);
- app.use('/', express.static('files'));
+ app.use('/', express.static('./src/static'));
app.use((req, res, next) => {
try {
diff --git a/config.json b/src/config.json
similarity index 100%
rename from config.json
rename to src/config.json
diff --git a/src/i18n/en/accessibility.json b/src/i18n/en/accessibility.json
new file mode 100644
index 00000000..6cefa134
--- /dev/null
+++ b/src/i18n/en/accessibility.json
@@ -0,0 +1,11 @@
+{
+ "about": "View about",
+ "settings": "Open settings",
+ "input": "Link input area",
+ "download": "Download button",
+ "changelog": "View changelog",
+ "close": "Close the popup",
+ "alwaysVisibleButton": "Keep the download button always visible",
+ "downloadPopup": "Ask what to do with downloads",
+ "donate": "Open donation popup"
+}
\ No newline at end of file
diff --git a/strings/en/apiError.json b/src/i18n/en/apiError.json
similarity index 100%
rename from strings/en/apiError.json
rename to src/i18n/en/apiError.json
diff --git a/strings/en/desc.json b/src/i18n/en/desc.json
similarity index 100%
rename from strings/en/desc.json
rename to src/i18n/en/desc.json
diff --git a/strings/en/settings.json b/src/i18n/en/settings.json
similarity index 100%
rename from strings/en/settings.json
rename to src/i18n/en/settings.json
diff --git a/strings/en/title.json b/src/i18n/en/title.json
similarity index 100%
rename from strings/en/title.json
rename to src/i18n/en/title.json
diff --git a/modules/api.js b/src/modules/api.js
similarity index 97%
rename from modules/api.js
rename to src/modules/api.js
index 0fdeb1b1..09337aea 100644
--- a/modules/api.js
+++ b/src/modules/api.js
@@ -4,7 +4,7 @@ import { services as patterns } from "./config.js";
import { cleanURL, apiJSON } from "./sub/api-helper.js";
import { errorUnsupported } from "./sub/errors.js";
-import loc from "./sub/loc.js";
+import loc from "./sub/i18n.js";
import match from "./match.js";
export async function getJSON(originalURL, ip, lang, format, quality) {
diff --git a/src/modules/config.js b/src/modules/config.js
new file mode 100644
index 00000000..9bf126bd
--- /dev/null
+++ b/src/modules/config.js
@@ -0,0 +1,17 @@
+import loadJson from "./sub/load-json.js";
+const config = loadJson("./src/config.json");
+
+export const
+services = loadJson("./src/modules/services/all.json"),
+appName = config.appName,
+version = config.version,
+streamLifespan = config.streamLifespan,
+maxVideoDuration = config.maxVideoDuration,
+genericUserAgent = config.genericUserAgent,
+repo = config.repo,
+authorInfo = config.authorInfo,
+supportedLanguages = config.supportedLanguages,
+quality = config.quality,
+internetExplorerRedirect = config.internetExplorerRedirect,
+donations = config.donations,
+ffmpegArgs = config.ffmpegArgs
\ No newline at end of file
diff --git a/modules/match.js b/src/modules/match.js
similarity index 96%
rename from modules/match.js
rename to src/modules/match.js
index ec28531e..205b5ef5 100644
--- a/modules/match.js
+++ b/src/modules/match.js
@@ -41,9 +41,9 @@ export default async function (host, patternMatch, url, ip, lang, format, qualit
}) : apiJSON(0, { t: r.error });
} else throw Error()
case "youtube":
- if (patternMatch["id"]) {
+ if (patternMatch["id"] && patternMatch["id"].length >= 11) {
let fetchInfo = {
- id: patternMatch["id"].slice(0, 11),
+ id: patternMatch["id"].slice(0,11),
lang: lang, quality: quality,
format: "mp4"
};
diff --git a/modules/page-renderer.js b/src/modules/page-renderer.js
similarity index 99%
rename from modules/page-renderer.js
rename to src/modules/page-renderer.js
index 499ff7bc..6af6a4a2 100644
--- a/modules/page-renderer.js
+++ b/src/modules/page-renderer.js
@@ -1,6 +1,6 @@
import { services, appName, authorInfo, version, quality, repo, donations } from "./config.js";
import { getCommitInfo } from "./sub/current-commit.js";
-import loc from "./sub/loc.js";
+import loc from "./sub/i18n.js";
let s = services
let enabledServices = Object.keys(s).filter((p) => {
diff --git a/modules/services/all.json b/src/modules/services/all.json
similarity index 100%
rename from modules/services/all.json
rename to src/modules/services/all.json
diff --git a/modules/services/bilibili.js b/src/modules/services/bilibili.js
similarity index 87%
rename from modules/services/bilibili.js
rename to src/modules/services/bilibili.js
index 7282dada..65717d2f 100644
--- a/modules/services/bilibili.js
+++ b/src/modules/services/bilibili.js
@@ -1,5 +1,5 @@
import got from "got";
-import loc from "../sub/loc.js";
+import loc from "../sub/i18n.js";
import { genericUserAgent, maxVideoDuration } from "../config.js";
export default async function(obj) {
@@ -15,14 +15,10 @@ export default async function(obj) {
let streamData = JSON.parse(html.split('')[0]);
if (streamData.data.timelength <= maxVideoDuration) {
let video = streamData["data"]["dash"]["video"].filter((v) => {
- if (!v["baseUrl"].includes("https://upos-sz-mirrorcosov.bilivideo.com/") && v["height"] != 4320) {
- return true;
- }
+ if (!v["baseUrl"].includes("https://upos-sz-mirrorcosov.bilivideo.com/") && v["height"] != 4320) return true;
}).sort((a, b) => Number(b.bandwidth) - Number(a.bandwidth));
let audio = streamData["data"]["dash"]["audio"].filter((a) => {
- if (!a["baseUrl"].includes("https://upos-sz-mirrorcosov.bilivideo.com/")) {
- return true;
- }
+ if (!a["baseUrl"].includes("https://upos-sz-mirrorcosov.bilivideo.com/")) return true;
}).sort((a, b) => Number(b.bandwidth) - Number(a.bandwidth));
return { urls: [video[0]["baseUrl"], audio[0]["baseUrl"]], time: streamData.data.timelength, filename: `bilibili_${obj.id}_${video[0]["width"]}x${video[0]["height"]}.mp4` };
} else {
diff --git a/modules/services/reddit.js b/src/modules/services/reddit.js
similarity index 96%
rename from modules/services/reddit.js
rename to src/modules/services/reddit.js
index 38e0771c..f41cff78 100644
--- a/modules/services/reddit.js
+++ b/src/modules/services/reddit.js
@@ -1,5 +1,5 @@
import got from "got";
-import loc from "../sub/loc.js";
+import loc from "../sub/i18n.js";
import { genericUserAgent, maxVideoDuration } from "../config.js";
export default async function(obj) {
diff --git a/modules/services/twitter.js b/src/modules/services/twitter.js
similarity index 98%
rename from modules/services/twitter.js
rename to src/modules/services/twitter.js
index 494e48ca..e96a5f6a 100644
--- a/modules/services/twitter.js
+++ b/src/modules/services/twitter.js
@@ -1,5 +1,5 @@
import got from "got";
-import loc from "../sub/loc.js";
+import loc from "../sub/i18n.js";
import { services } from "../config.js";
const configSt = services.twitter;
diff --git a/modules/services/vk.js b/src/modules/services/vk.js
similarity index 98%
rename from modules/services/vk.js
rename to src/modules/services/vk.js
index aa81e56c..17a32887 100644
--- a/modules/services/vk.js
+++ b/src/modules/services/vk.js
@@ -1,6 +1,6 @@
import got from "got";
import { xml2json } from "xml-js";
-import loc from "../sub/loc.js";
+import loc from "../sub/i18n.js";
import { genericUserAgent, maxVideoDuration, services } from "../config.js";
import selectQuality from "../stream/select-quality.js";
diff --git a/modules/services/youtube.js b/src/modules/services/youtube.js
similarity index 99%
rename from modules/services/youtube.js
rename to src/modules/services/youtube.js
index 02a55d05..538615c5 100644
--- a/modules/services/youtube.js
+++ b/src/modules/services/youtube.js
@@ -1,5 +1,5 @@
import ytdl from "ytdl-core";
-import loc from "../sub/loc.js";
+import loc from "../sub/i18n.js";
import { maxVideoDuration, quality as mq } from "../config.js";
import selectQuality from "../stream/select-quality.js";
diff --git a/modules/setup.js b/src/modules/setup.js
similarity index 100%
rename from modules/setup.js
rename to src/modules/setup.js
diff --git a/modules/stream/manage.js b/src/modules/stream/manage.js
similarity index 100%
rename from modules/stream/manage.js
rename to src/modules/stream/manage.js
diff --git a/modules/stream/select-quality.js b/src/modules/stream/select-quality.js
similarity index 100%
rename from modules/stream/select-quality.js
rename to src/modules/stream/select-quality.js
diff --git a/modules/stream/stream.js b/src/modules/stream/stream.js
similarity index 100%
rename from modules/stream/stream.js
rename to src/modules/stream/stream.js
diff --git a/modules/stream/types.js b/src/modules/stream/types.js
similarity index 99%
rename from modules/stream/types.js
rename to src/modules/stream/types.js
index 950025af..9d0ee06a 100644
--- a/modules/stream/types.js
+++ b/src/modules/stream/types.js
@@ -4,7 +4,7 @@ import got from "got";
import { ffmpegArgs, genericUserAgent } from "../config.js";
import { msToTime } from "../sub/api-helper.js";
import { internalError } from "../sub/errors.js";
-import loc from "../sub/loc.js";
+import loc from "../sub/i18n.js";
export async function streamDefault(streamInfo, res) {
try {
diff --git a/modules/sub/api-helper.js b/src/modules/sub/api-helper.js
similarity index 100%
rename from modules/sub/api-helper.js
rename to src/modules/sub/api-helper.js
diff --git a/modules/sub/console-text.js b/src/modules/sub/console-text.js
similarity index 100%
rename from modules/sub/console-text.js
rename to src/modules/sub/console-text.js
diff --git a/modules/sub/crypto.js b/src/modules/sub/crypto.js
similarity index 100%
rename from modules/sub/crypto.js
rename to src/modules/sub/crypto.js
diff --git a/modules/sub/current-commit.js b/src/modules/sub/current-commit.js
similarity index 100%
rename from modules/sub/current-commit.js
rename to src/modules/sub/current-commit.js
diff --git a/modules/sub/errors.js b/src/modules/sub/errors.js
similarity index 92%
rename from modules/sub/errors.js
rename to src/modules/sub/errors.js
index a56cb0e1..7a250f46 100644
--- a/modules/sub/errors.js
+++ b/src/modules/sub/errors.js
@@ -1,4 +1,4 @@
-import loc from "./loc.js";
+import loc from "./i18n.js";
export function internalError(res) {
res.status(501).json({ status: "error", text: "Internal Server Error" });
diff --git a/modules/sub/loc.js b/src/modules/sub/i18n.js
similarity index 90%
rename from modules/sub/loc.js
rename to src/modules/sub/i18n.js
index 91c925af..b131d684 100644
--- a/modules/sub/loc.js
+++ b/src/modules/sub/i18n.js
@@ -6,7 +6,7 @@ export default function(lang, cat, string, replacement) {
lang = 'en'
}
try {
- let str = loadJson(`./strings/${lang}/${cat}.json`);
+ let str = loadJson(`./src/i18n/${lang}/${cat}.json`);
if (str && str[string]) {
let s = str[string].replace(/\n/g, '
').replace(/{appName}/g, appName).replace(/{repo}/g, repo)
if (replacement) {
diff --git a/modules/sub/load-json.js b/src/modules/sub/load-json.js
similarity index 100%
rename from modules/sub/load-json.js
rename to src/modules/sub/load-json.js
diff --git a/files/cobalt.css b/src/static/cobalt.css
similarity index 100%
rename from files/cobalt.css
rename to src/static/cobalt.css
diff --git a/files/cobalt.js b/src/static/cobalt.js
similarity index 100%
rename from files/cobalt.js
rename to src/static/cobalt.js
diff --git a/files/cobalt.webmanifest b/src/static/cobalt.webmanifest
similarity index 100%
rename from files/cobalt.webmanifest
rename to src/static/cobalt.webmanifest
diff --git a/files/fonts/notosansmono/notosansmono.css b/src/static/fonts/notosansmono/notosansmono.css
similarity index 100%
rename from files/fonts/notosansmono/notosansmono.css
rename to src/static/fonts/notosansmono/notosansmono.css
diff --git a/files/fonts/notosansmono/notosansmono_3dVQ.woff2 b/src/static/fonts/notosansmono/notosansmono_3dVQ.woff2
similarity index 100%
rename from files/fonts/notosansmono/notosansmono_3dVQ.woff2
rename to src/static/fonts/notosansmono/notosansmono_3dVQ.woff2
diff --git a/files/fonts/notosansmono/notosansmono_7dVXQQ.woff2 b/src/static/fonts/notosansmono/notosansmono_7dVXQQ.woff2
similarity index 100%
rename from files/fonts/notosansmono/notosansmono_7dVXQQ.woff2
rename to src/static/fonts/notosansmono/notosansmono_7dVXQQ.woff2
diff --git a/files/fonts/notosansmono/notosansmono_DdVXQQ.woff2 b/src/static/fonts/notosansmono/notosansmono_DdVXQQ.woff2
similarity index 100%
rename from files/fonts/notosansmono/notosansmono_DdVXQQ.woff2
rename to src/static/fonts/notosansmono/notosansmono_DdVXQQ.woff2
diff --git a/files/fonts/notosansmono/notosansmono_HdVXQQ.woff2 b/src/static/fonts/notosansmono/notosansmono_HdVXQQ.woff2
similarity index 100%
rename from files/fonts/notosansmono/notosansmono_HdVXQQ.woff2
rename to src/static/fonts/notosansmono/notosansmono_HdVXQQ.woff2
diff --git a/files/fonts/notosansmono/notosansmono_LdVXQQ.woff2 b/src/static/fonts/notosansmono/notosansmono_LdVXQQ.woff2
similarity index 100%
rename from files/fonts/notosansmono/notosansmono_LdVXQQ.woff2
rename to src/static/fonts/notosansmono/notosansmono_LdVXQQ.woff2
diff --git a/files/fonts/notosansmono/notosansmono_PdVXQQ.woff2 b/src/static/fonts/notosansmono/notosansmono_PdVXQQ.woff2
similarity index 100%
rename from files/fonts/notosansmono/notosansmono_PdVXQQ.woff2
rename to src/static/fonts/notosansmono/notosansmono_PdVXQQ.woff2
diff --git a/files/fonts/notosansmono/notosansmono_ndVXQQ.woff2 b/src/static/fonts/notosansmono/notosansmono_ndVXQQ.woff2
similarity index 100%
rename from files/fonts/notosansmono/notosansmono_ndVXQQ.woff2
rename to src/static/fonts/notosansmono/notosansmono_ndVXQQ.woff2
diff --git a/files/icons/android-chrome-192x192.png b/src/static/icons/android-chrome-192x192.png
similarity index 100%
rename from files/icons/android-chrome-192x192.png
rename to src/static/icons/android-chrome-192x192.png
diff --git a/files/icons/android-chrome-512x512.png b/src/static/icons/android-chrome-512x512.png
similarity index 100%
rename from files/icons/android-chrome-512x512.png
rename to src/static/icons/android-chrome-512x512.png
diff --git a/files/icons/apple-touch-icon.png b/src/static/icons/apple-touch-icon.png
similarity index 100%
rename from files/icons/apple-touch-icon.png
rename to src/static/icons/apple-touch-icon.png
diff --git a/files/icons/favicon-16x16.png b/src/static/icons/favicon-16x16.png
similarity index 100%
rename from files/icons/favicon-16x16.png
rename to src/static/icons/favicon-16x16.png
diff --git a/files/icons/favicon-32x32.png b/src/static/icons/favicon-32x32.png
similarity index 100%
rename from files/icons/favicon-32x32.png
rename to src/static/icons/favicon-32x32.png
diff --git a/files/icons/favicon.ico b/src/static/icons/favicon.ico
similarity index 100%
rename from files/icons/favicon.ico
rename to src/static/icons/favicon.ico
diff --git a/files/icons/generic.png b/src/static/icons/generic.png
similarity index 100%
rename from files/icons/generic.png
rename to src/static/icons/generic.png
diff --git a/files/icons/maskable/x128.png b/src/static/icons/maskable/x128.png
similarity index 100%
rename from files/icons/maskable/x128.png
rename to src/static/icons/maskable/x128.png
diff --git a/files/icons/maskable/x1280.png b/src/static/icons/maskable/x1280.png
similarity index 100%
rename from files/icons/maskable/x1280.png
rename to src/static/icons/maskable/x1280.png
diff --git a/files/icons/maskable/x192.png b/src/static/icons/maskable/x192.png
similarity index 100%
rename from files/icons/maskable/x192.png
rename to src/static/icons/maskable/x192.png
diff --git a/files/icons/maskable/x384.png b/src/static/icons/maskable/x384.png
similarity index 100%
rename from files/icons/maskable/x384.png
rename to src/static/icons/maskable/x384.png
diff --git a/files/icons/maskable/x48.png b/src/static/icons/maskable/x48.png
similarity index 100%
rename from files/icons/maskable/x48.png
rename to src/static/icons/maskable/x48.png
diff --git a/files/icons/maskable/x512.png b/src/static/icons/maskable/x512.png
similarity index 100%
rename from files/icons/maskable/x512.png
rename to src/static/icons/maskable/x512.png
diff --git a/files/icons/maskable/x72.png b/src/static/icons/maskable/x72.png
similarity index 100%
rename from files/icons/maskable/x72.png
rename to src/static/icons/maskable/x72.png
diff --git a/files/icons/maskable/x96.png b/src/static/icons/maskable/x96.png
similarity index 100%
rename from files/icons/maskable/x96.png
rename to src/static/icons/maskable/x96.png
diff --git a/files/icons/wide.png b/src/static/icons/wide.png
similarity index 100%
rename from files/icons/wide.png
rename to src/static/icons/wide.png
diff --git a/files/robots.txt b/src/static/robots.txt
similarity index 100%
rename from files/robots.txt
rename to src/static/robots.txt
diff --git a/strings/en/accessibility.json b/strings/en/accessibility.json
deleted file mode 100644
index 946027ef..00000000
--- a/strings/en/accessibility.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "about": "About",
- "settings": "Settings",
- "input": "URL input area",
- "download": "Download button",
- "changelog": "Changelog",
- "close": "Close button",
- "alwaysVisibleButton": "Keep the download button always visible",
- "donate": "Support development of {appName} by donating"
-}
\ No newline at end of file