diff --git a/controllers/queueController.js b/controllers/queueController.js index dec08ce..ccae892 100644 --- a/controllers/queueController.js +++ b/controllers/queueController.js @@ -130,12 +130,15 @@ exports.status = async (req, res) => { .sort({ failed_at: -1 }) .toArray(); + const settings = + (await db.collection("settings").findOne({ _id: "global" })) || {}; + console.log; res.render("status", { - title: "Queue Status", queued, processing, finished: done, failed, + global: settings, }); }; @@ -166,31 +169,31 @@ exports.statusData = async (req, res) => { .sort({ failed_at: -1 }) .toArray(); - // =========================== - // FILE SIZE FOR DONE - // =========================== - for (let job of done) { - try { - const filePath = path.join(process.env.OUTPUT_DIR, `${job.filename}.mp4`); - const stats = fs.statSync(filePath); - job.fileSize = stats.size; - } catch { - job.fileSize = null; + // File sizes + const OUTPUT_DIR = process.env.OUTPUT_DIR || "/mnt/media/WIP"; + for (const list of [processing, done]) { + for (const job of list) { + try { + const stat = fs.statSync(path.join(OUTPUT_DIR, `${job.filename}.mp4`)); + job.fileSize = stat.size; + } catch { + job.fileSize = null; + } } } - // =========================== - // FILE SIZE FOR PROCESSING - // =========================== - for (let job of processing) { - try { - const filePath = path.join(process.env.OUTPUT_DIR, `${job.filename}.mp4`); - const stats = fs.statSync(filePath); - job.fileSize = stats.size; - } catch { - job.fileSize = null; - } - } + // Fetch global settings + const settings = await db.collection("settings").findOne({ _id: "global" }) || {}; + settings.captcha_blocked = !!settings.captcha_blocked; - res.json({ queued, processing, done, failed }); + // Send JSON including global + res.json({ + queued, + processing, + done, + failed, + global: settings, + }); }; + + diff --git a/public/assets/favicon.ico b/public/assets/favicon.ico new file mode 100644 index 0000000..97b282d Binary files /dev/null and b/public/assets/favicon.ico differ diff --git a/public/style.css b/public/style.css index d78cb31..8884044 100644 --- a/public/style.css +++ b/public/style.css @@ -112,6 +112,51 @@ button, box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); } +/* ===== Floating Pill Toggle ===== */ + +.pill-toggle { + position: relative; + display: flex; + width: 240px; + background: #333; + padding: 5px; + border-radius: 30px; + cursor: pointer; + user-select: none; +} + +.pill-option { + flex: 1; + text-align: center; + padding: 10px 0; + z-index: 2; + font-weight: 600; + color: #aaa; + transition: color 0.25s ease; +} + +.pill-option.active { + color: #fff; +} + +.pill-indicator { + position: absolute; + top: 5px; + left: 5px; + width: calc(50% - 5px); + height: calc(100% - 10px); + background: #8a190b; /* your accent red */ + border-radius: 25px; + transition: transform 0.25s ease, background 0.25s ease; + z-index: 1; +} + +/* Hover feedback */ +.pill-option:hover { + color: #ddd; +} + + /* =============================== ALERTS =============================== */ diff --git a/queue_worker.js b/queue_worker.js index 2aa415d..37dea54 100644 --- a/queue_worker.js +++ b/queue_worker.js @@ -14,52 +14,74 @@ const OUTPUT_DIR = process.env.OUTPUT_DIR || "/mnt/media/WIP/"; const client = new MongoClient(MONGO_URI); let queueCol, doneCol, failedCol; +// ======================== +// HELPER +// ======================== + +async function isBlocked() { + const settings = await queueCol.db + .collection("settings") + .findOne({ _id: "global" }); + return settings?.captcha_blocked === true; +} + // ======================== // RUN A JOB // ======================== -function runJob(job) { - return new Promise((resolve) => { - const venvPython = process.env.VENV_PYTHON +async function runJob(job) { + try { + const cmd = [ + "python3", + path.join(__dirname, "proxer-dl-video.py"), + "-u", job.url, + "-f", job.filename, + "-t", job.token, + "-o", process.env.OUTPUT_DIR + ]; - const cleanName = job.filename.replace(".mp4", ""); - const safeToken = job.token.replace(/^"+|"+$/g, ''); - const scriptPath = 'scripts/proxer-dl-video.py' - const command = `${venvPython} ${scriptPath} -u "${job.url}" -f "${cleanName}" -t "${safeToken}" -o "${OUTPUT_DIR}"`; + const proc = spawn(cmd[0], cmd.slice(1)); - console.log("Running:", command); + let output = ""; + proc.stdout.on("data", d => output += d.toString()); + proc.stderr.on("data", d => output += d.toString()); - exec(command, async (error, stdout, stderr) => { - const outputLog = `${stdout}\n${stderr}`.trim(); + const exitCode = await new Promise(resolve => + proc.on("close", resolve) + ); - try { - if (error) { - console.error(`FAILED: ${cleanName}`); - await failedCol.insertOne({ - filename: job.filename, - url: job.url, - failed_at: new Date(), - output_log: outputLog, - return_code: error.code, - }); - } else { - console.log(`SUCCESS: ${cleanName}`); - await doneCol.insertOne({ - filename: job.filename, - url: job.url, - finished_at: new Date(), - output_log: outputLog, - result: "success", - }); - } - // Remove from queue in both cases - await queueCol.deleteOne({ _id: job._id }); - } catch (dbErr) { - console.error("DB error:", dbErr); - } finally { - resolve(); // resolve promise when done - } + // ========== CAPTCHA / ERROR DETECTION ========== + const suspicious = + exitCode !== 0 || + output.toLowerCase().includes("captcha") || + output.toLowerCase().includes("403") || + output.toLowerCase().includes("blocked") || + output.toLowerCase().includes("token") || + output.toLowerCase().includes("forbidden"); + + if (suspicious) { + console.log("⛔ CAPTCHA or fatal error detected, notifying system"); + await failedCol.insertOne({ + filename: job.filename, + failed_at: new Date(), + output_log: output + }); + return true; // signals worker to halt globally + } + + // Success + await doneCol.insertOne({ + filename: job.filename, + finished_at: new Date(), + output_log: output }); - }); + + await queueCol.deleteOne({ _id: job._id }); + return false; + + } catch (err) { + console.error("Worker crash:", err); + return true; + } } @@ -78,29 +100,31 @@ async function main() { failedCol = db.collection("failed"); while (true) { + if (await isBlocked()) { + console.log("⛔ CAPTCHA BLOCK — Worker paused"); + await new Promise((r) => setTimeout(r, 5000)); + continue; + } + const job = await queueCol.findOneAndUpdate( - { - // Only pick jobs NOT being processed - $or: [ - { processing: { $exists: false } }, - { processing: false } - ] - }, - { - // Atomically claim job - $set: { processing: true, started_at: new Date() } - }, - { - sort: { created_at: 1 }, - returnDocument: "after" - } + { processing: { $ne: true } }, // prevents grabbing others + { $set: { processing: true } }, + { sort: { created_at: 1 }, returnDocument: "after" } ); if (job && job.token) { - await runJob(job); + const failed = await runJob(job); + if (failed === true) { + await queueCol.db + .collection("settings") + .updateOne( + { _id: "global" }, + { $set: { captcha_blocked: true } }, + { upsert: true } + ); + } } else { - // No available job, wait a bit - await new Promise(resolve => setTimeout(resolve, 1000)); + await new Promise((resolve) => setTimeout(resolve, 1000)); } } } catch (err) { @@ -109,4 +133,3 @@ async function main() { } main(); - diff --git a/routes/index.js b/routes/index.js index 17cd353..fc7f32d 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,13 +1,41 @@ const express = require("express"); const router = express.Router(); const queue = require("../controllers/queueController"); +const { getDb } = require("../lib/mongo"); +// ======================= +// HOME PAGE +// ======================= router.get("/", (req, res) => res.render("index", { title: "Proxer Downloader" }) ); -router.post("/queue", queue.enqueue); // <-- FIXED -router.get("/status-data", queue.statusData); +// ======================= +// QUEUE REQUEST +// ======================= +router.post("/queue", queue.enqueue); + +// ======================= +// STATUS (SSR RENDER) +// ======================= router.get("/status", queue.status); +// ======================= +// STATUS JSON API +// ======================= +router.get("/status-data", queue.statusData); + +// ======================= +// CAPTCHA CLEAR +// ======================= +router.post("/clear-captcha", async (req, res) => { + const db = await getDb(); + await db.collection("settings").updateOne( + { _id: "global" }, + { $set: { captcha_blocked: false } } + ); + // Redirect to status, controller fetches everything + res.redirect("/status"); +}); + module.exports = router; diff --git a/server.js b/server.js index 4266afe..58b410e 100644 --- a/server.js +++ b/server.js @@ -18,7 +18,12 @@ app.set('views', path.join(__dirname, 'views')); app.use(express.static(path.join(__dirname, 'public'))); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); -app.use(morgan('dev')); + +// Morgan: log only non-static requests +app.use(morgan(':method :url :status :res[content-length] - :response-time ms', { + skip: (req) => req.url.startsWith('/assets') || req.url.startsWith('/favicon.ico') +})); + // Routes app.use('/', indexRouter); diff --git a/views/index.ejs b/views/index.ejs index ddedcd5..8dc4962 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -1,99 +1,131 @@ <%- include("partials/header") %> -
-
-
- - -
+
+
+
+
+ Series +
+
Video
+
+
+
+ +
+ + + +
+
+ + +
+ + +
+ +
+
+ +
+
+ +
+
- - +
+ + +
- -
-
- - -
- - -
- -
-
- -
-
- -
-
-
- -
- - -
- -
- - -
-
- - - - - -
- - -
Full token = TOKEN_PREFIX + this value
-
- -
- - View Queue -
- +
+ + +
- <%- include("partials/footer") %> diff --git a/views/partials/header.ejs b/views/partials/header.ejs index c7e834a..de69878 100644 --- a/views/partials/header.ejs +++ b/views/partials/header.ejs @@ -1,18 +1,51 @@ - + - - - Proxer-Downloader - - + + + Proxer-Downloader + + + -
+ + +
+ ⚠ Human Action Required: Proxer CAPTCHA triggered. Workers paused until cleared. +
+ +
+
+ + +
+
-

Proxer-Downloader

- +

Proxer-Downloader

+
+ + diff --git a/views/status.ejs b/views/status.ejs index 5b05da2..9f73024 100644 --- a/views/status.ejs +++ b/views/status.ejs @@ -1,6 +1,7 @@ <%- include("partials/header") %>
+ @@ -13,7 +14,8 @@ <%= job.url %>
<%= new Date(job.created_at).toLocaleString() %> - <% }) %> <% if (queued.length === 0) { %> + <% }) %> + <% if (queued.length === 0) { %>
  • No queued jobs
  • <% } %> @@ -23,40 +25,35 @@
    -

    Processing

    +

    Processing

      + <% processing.forEach(job => { %>
    • - <%= job.filename %> - -
      - <%= job.url %>
      + <%= job.filename %> +
      + <%= job.url %>
      Started: <%= new Date(job.created_at).toLocaleString() %> + <% if (job.fileSize) { %> +
      Downloaded: <%= job.fileSize %> + <% } %> + <% if (job.output_log) { %>
      Live Log -
      +          
       <%= job.output_log %>
      -              
      +
      <% } %>
    • - <% }) %> <% if (processing.length === 0) { %> + <% }) %> + + <% if (processing.length === 0) { %>
    • Nothing processing
    • <% } %> +
    @@ -66,32 +63,32 @@

    Done

      + <% finished.forEach(job => { %>
    • <%= job.filename %>
      - <%= new Date(job.finished_at).toLocaleString() %>
      + <%= new Date(job.finished_at).toLocaleString() %>
      + + <% if (job.fileSize) { %> + Size: <%= job.fileSize %>
      + <% } %> <% if (job.output_log) { %>
      Show Log -
      +          
       <%= job.output_log %>
      -              
      +
      <% } %> +
    • - <% }) %> <% if (finished.length === 0) { %> + <% }) %> + + <% if (finished.length === 0) { %>
    • No completed jobs
    • <% } %> +
    @@ -101,106 +98,150 @@

    Failed

      + <% failed.forEach(job => { %>
    • <%= job.filename %>
      - <%= new Date(job.failed_at).toLocaleString() %>
      + <%= new Date(job.failed_at).toLocaleString() %>
      <% if (job.output_log) { %>
      Show Error Log -
      +          
       <%= job.output_log %>
      -              
      +
      <% } %> +
    • - <% }) %> <% if (failed.length === 0) { %> + <% }) %> + + <% if (failed.length === 0) { %>
    • No failed jobs
    • <% } %> +
    +
    + <%- include("partials/footer") %>