diff --git a/package.json b/package.json index 379435c..64d933b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "floatplane-plex-downloader", - "version": "5.12.0", + "version": "5.12.1", "private": true, "type": "module", "scripts": { diff --git a/src/float.ts b/src/float.ts index 0a82a82..083641f 100644 --- a/src/float.ts +++ b/src/float.ts @@ -5,7 +5,7 @@ import { fetchFFMPEG } from "./lib/helpers/fetchFFMPEG.js"; import { defaultSettings } from "./lib/defaults.js"; import { loginFloatplane, User } from "./logins.js"; -import { VideoDownloader } from "./Downloader.js"; +import { VideoDownloader } from "./lib/Downloader.js"; import chalk from "chalk-template"; import type { ContentPost } from "floatplane/content"; @@ -103,9 +103,10 @@ process.on("SIGTERM", process.exit); console.log(`Unable to authenticate with floatplane... ${(err).message}\nPlease login to floatplane...`); user = await loginFloatplane(); } - await initProm(user!.id); + console.log(`Initalized! Running version ${DownloaderVersion} instance ${user!.id}`); + await downloadNewVideos(); if (settings.floatplane.waitForNewVideos === true) { diff --git a/src/Downloader.ts b/src/lib/Downloader.ts similarity index 93% rename from src/Downloader.ts rename to src/lib/Downloader.ts index 1d9bf40..f68a51f 100644 --- a/src/Downloader.ts +++ b/src/lib/Downloader.ts @@ -1,12 +1,12 @@ import { Counter, Gauge } from "prom-client"; -import { Video } from "./lib/Video.js"; +import { Video } from "./Video.js"; import type { Progress } from "got"; -import { settings, args } from "./lib/helpers/index.js"; +import { settings, args } from "./helpers/index.js"; import { MyPlexAccount } from "@ctrl/plex"; -import { ProgressHeadless } from "./lib/logging/ProgressConsole.js"; -import { ProgressBars } from "./lib/logging/ProgressBars.js"; +import { ProgressHeadless } from "./logging/ProgressConsole.js"; +import { ProgressBars } from "./logging/ProgressBars.js"; import { promisify } from "util"; const sleep = promisify(setTimeout); @@ -81,6 +81,7 @@ export class VideoDownloader { let downloadInterval: NodeJS.Timeout; downloadRequest.once("downloadProgress", (downloadProgress: Progress) => { + logger.log("Starting download..."); downloadInterval = setInterval(() => logger.onDownloadProgress(downloadRequest.downloadProgress), 125); logger.onDownloadProgress(downloadProgress); }); @@ -91,6 +92,7 @@ export class VideoDownloader { }).finally(() => { clearInterval(downloadInterval); logger.onDownloadProgress(downloadRequest.downloadProgress); + logger.log("Finished download..."); }); } // eslint-disable-next-line no-fallthrough @@ -107,7 +109,7 @@ export class VideoDownloader { } // eslint-disable-next-line no-fallthrough case Video.State.Muxed: { - logger.done("Muxed"); + logger.done("Download & Muxing complete!"); VideoDownloader.ProgressLogger.CompletedVideos++; promDownloadedTotal.inc(); } diff --git a/src/lib/helpers/index.ts b/src/lib/helpers/index.ts index 262a9af..aed8370 100644 --- a/src/lib/helpers/index.ts +++ b/src/lib/helpers/index.ts @@ -13,7 +13,7 @@ import "dotenv/config"; import json5 from "json5"; const { parse } = json5; -export const DownloaderVersion = "5.12.0"; +export const DownloaderVersion = "5.12.1"; import type { PartialArgs, Settings } from "../types.js"; diff --git a/src/lib/logging/ProgressBars.ts b/src/lib/logging/ProgressBars.ts index ceb69f3..0a609a7 100644 --- a/src/lib/logging/ProgressBars.ts +++ b/src/lib/logging/ProgressBars.ts @@ -1,19 +1,15 @@ import { MultiProgressBars } from "multi-progress-bars"; import { ProgressLogger, type IProgressLogger } from "./ProgressLogger.js"; import type { Progress } from "got"; +import chalk from "chalk-template"; export class ProgressBars extends ProgressLogger implements IProgressLogger { - private static readonly _reset = "\u001b[0m"; - private static readonly cy = (str: string | number) => `\u001b[36;1m${str}\u001b[0m`; - private static readonly gr = (str: string | number) => `\u001b[32;1m${str}\u001b[0m`; - private static readonly ye = (str: string | number) => `\u001b[33;1m${str}\u001b[0m`; - private static readonly bl = (str: string | number) => `\u001b[34;1m${str}\u001b[0m`; - private static readonly _Bars: MultiProgressBars = new MultiProgressBars({ initMessage: "", anchor: "bottom" }); public static TotalBytes = 0; public static DownloadedBytes = 0; public static DownloadSpeed = 0; + public static Errors = 0; private _startTime: undefined | number = undefined; @@ -43,9 +39,12 @@ export class ProgressBars extends ProgressLogger implements IProgressLogger { this.removeBar(); } public error(message: string, final?: true) { - this.log(`${ProgressLogger.ERR}: ${message}`); + this.log(chalk`{red ERR}: ${message}`); this.reset(); - if (final) this.removeBar(); + if (final) { + this.removeBar(); + ProgressBars.Errors++; + } } private removeBar() { setTimeout(() => ProgressBars._Bars.removeTask(this.title), 10000 + Math.floor(Math.random() * 6000)); @@ -71,22 +70,22 @@ export class ProgressBars extends ProgressLogger implements IProgressLogger { const downloadETA = progress.total / this._downloadSpeed - elapsed; - const downloaded = `${ProgressBars.cy((progress.transferred / 1000000).toFixed(2))}/${ProgressBars.cy(`${(progress.total / 1000000).toFixed(2)}MB`)}`; - const speed = `${ProgressBars.gr((this._downloadSpeed / 125000).toFixed(2) + "mb/s")}`; - const eta = `ETA: ${ProgressBars.bl(`${Math.floor(downloadETA / 60)}m ${Math.floor(downloadETA) % 60}s`)}`; + const downloaded = chalk`{cyan ${(progress.transferred / 1000000).toFixed(2)}}/{cyan ${(progress.total / 1000000).toFixed(2)}MB}`; + const speed = chalk`{green ${(this._downloadSpeed / 125000).toFixed(2)} mb/s}`; + const eta = chalk`ETA: {blue ${Math.floor(downloadETA / 60)}m ${Math.floor(downloadETA) % 60}s}`; ProgressBars._Bars.updateTask(this.title, { percentage: progress.percent, - message: `${ProgressBars._reset}${downloaded} ${speed} ${eta}`, + message: `${downloaded} ${speed} ${eta}`, }); - const processed = `Processed: ${ProgressBars.ye(ProgressBars.CompletedVideos)}/${ProgressBars.ye(ProgressBars.TotalVideos)}`; - const downloadedTotal = `Total Downloaded: ${ProgressBars.cy((ProgressBars.DownloadedBytes / 1000000).toFixed(2))}/${ProgressBars.cy( - `${(ProgressBars.TotalBytes / 1000000).toFixed(2)}MB`, - )}`; - const speedTotal = `Download Speed: ${ProgressBars.gr(`${(ProgressBars.DownloadSpeed / 125000).toFixed(2)}mb/s`)}`; + const processed = chalk`Processed: {yellow ${ProgressBars.CompletedVideos}}/{yellow ${ProgressBars.TotalVideos}} Errors: {red ${ProgressBars.Errors}}`; + const downloadedTotal = chalk`Total Downloaded: {cyan ${(ProgressBars.DownloadedBytes / 1000000).toFixed(2)}}/{cyan ${( + ProgressBars.TotalBytes / 1000000 + ).toFixed(2)}MB}`; + const speedTotal = chalk`Download Speed: {green ${(ProgressBars.DownloadSpeed / 125000).toFixed(2)}mb/s}`; ProgressBars._Bars.setFooter({ - message: `${processed} ${downloadedTotal} ${speedTotal}`, + message: `${processed} ${downloadedTotal} ${speedTotal}`, pattern: "", }); } diff --git a/src/lib/logging/ProgressConsole.ts b/src/lib/logging/ProgressConsole.ts index 194f9ec..3054706 100644 --- a/src/lib/logging/ProgressConsole.ts +++ b/src/lib/logging/ProgressConsole.ts @@ -14,6 +14,6 @@ export class ProgressHeadless extends ProgressLogger implements IProgressLogger this.log(`${message} (${ProgressLogger.CompletedVideos}/${ProgressLogger.TotalVideos})`); } public error(message: string) { - this.log(`${ProgressLogger.ERR}: ${message}`); + this.log(`An error occoured: ${message}`); } } diff --git a/src/lib/logging/ProgressLogger.ts b/src/lib/logging/ProgressLogger.ts index 2339d1f..9784a3e 100644 --- a/src/lib/logging/ProgressLogger.ts +++ b/src/lib/logging/ProgressLogger.ts @@ -13,8 +13,6 @@ export class ProgressLogger { public static TotalVideos = 0; public static CompletedVideos = 0; - public static readonly ERR = "\u001b[31m\u001b[1mERR\u001b[0m"; - public downloadedBytes = 0; private static _downloadedBytesTotalCounter = new Counter({