Skip to content

Commit

Permalink
Removed all the separate pathing and only have FFMPEG path in args
Browse files Browse the repository at this point in the history
This moves everything back into the db directory, and only allows the
FFMPEG path to be changed. This also moves around some logic, and
removes unnecessary blobs out of the distribution.
  • Loading branch information
Noodlez1232 committed Nov 7, 2024
1 parent 5c43d4e commit 7414ccf
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 39 deletions.
5 changes: 1 addition & 4 deletions sea-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@
"main": "dist/float.cjs",
"output": "dist/float.blob",
"disableExperimentalSEAWarning": true,
"useCodeCache": true,
"assets": {
"./package.json": "./package.json"
}
"useCodeCache": true
}
2 changes: 1 addition & 1 deletion src/lib/Attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum Extensions {
}

export class Attachment implements AttachmentAttributes {
private static readonly AttachmentsDB: Record<string, AttachmentInfo> = db<Record<string, AttachmentInfo>>(args.attachmentsPath);
private static readonly AttachmentsDB: Record<string, AttachmentInfo> = db<Record<string, AttachmentInfo>>(`${args.dbPath}/attachments.json`);
public static readonly Extensions = Extensions;

public readonly attachmentId: string;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { updatePlex } from "./helpers/updatePlex.js";
import { ProgressHeadless } from "./logging/ProgressConsole.js";
import { ProgressBars } from "./logging/ProgressBars.js";

import { ffmpegPath } from "./helpers/fetchFFMPEG.js"

const exec = promisify(execCallback);
const sleep = promisify(setTimeout);

Expand Down Expand Up @@ -363,7 +365,7 @@ export class Video extends Attachment {

await new Promise((resolve, reject) =>
execFile(
args.ffmpegPath,
ffmpegPath,
[
"-i",
this.partialPath,
Expand Down
19 changes: 1 addition & 18 deletions src/lib/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,9 @@ export const defaultArgs: Args = {
plexUsername: "",
plexPassword: "",
sanityCheck: false,
workPath: "./db",
dbPath: "./db",
ffmpegPath: "",
settingsPath: "",
cookiesPath: "",
attachmentsPath: "",
};
export function fixArgs(args: Args) {
if (args.ffmpegPath === "") {
args.ffmpegPath = `${args.workPath}/${getBinaryFilename("ffmpeg", detectPlatform() )}`;
}
if (args.settingsPath === "") {
args.settingsPath = `${args.workPath}/settings.json`;
}
if (args.cookiesPath === "") {
args.cookiesPath = `${args.workPath}/cookies.json`;
}
if (args.attachmentsPath === "") {
args.attachmentsPath = `${args.workPath}/attachments.json`;
}
}

export const defaultSettings: Settings = {
__SettingsWiki: "https://github.com/Inrixia/Floatplane-Downloader/blob/master/wiki/settings.md",
Expand Down
9 changes: 5 additions & 4 deletions src/lib/helpers/fetchFFMPEG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { args } from "./index.js";
import fs from "fs";
import { dirname, basename } from "path";

export const ffmpegPath = args.ffmpegPath ?? `${args.dbPath}/${getBinaryFilename("ffmpeg", detectPlatform())}`;

export const fetchFFMPEG = (): Promise<void> =>
new Promise((resolve, reject) => {
let platform = detectPlatform();
let path = args.ffmpegPath;
if (fs.existsSync(path) === false) {
if (!fs.existsSync(ffmpegPath)) {
process.stdout.write("> Ffmpeg binary missing! Downloading... ");
downloadBinaries(
basename(path),
"ffmpeg",
{
destination: dirname(path),
destination: dirname(ffmpegPath),
platform,
},
(err) => {
Expand Down
10 changes: 3 additions & 7 deletions src/lib/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getEnv, rebuildTypes, recursiveUpdate } from "@inrixia/helpers/object";
import { defaultArgs, defaultSettings, fixArgs } from "../defaults.js";
import { defaultArgs, defaultSettings } from "../defaults.js";
import { Histogram } from "prom-client";
import db from "@inrixia/db";

Expand Down Expand Up @@ -31,10 +31,9 @@ const env = getEnv();
export const args = defaultArgs;
recursiveUpdate(args, env, { setUndefined: false, setDefined: true });
recursiveUpdate(args, argv, { setUndefined: false, setDefined: true });
fixArgs(args);

export const settings = defaultSettings;
let newSettings = db<Settings>(args.settingsPath, { template: defaultSettings, pretty: true, forceCreate: true, updateOnExternalChanges: true });
let newSettings = db<Settings>(`${args.dbPath}/settings.json`, { template: defaultSettings, pretty: true, forceCreate: true, updateOnExternalChanges: true });
recursiveUpdate(settings, newSettings, { setUndefined: true, setDefined: true });

recursiveUpdate(settings, argv, { setUndefined: false, setDefined: true });
Expand All @@ -46,7 +45,7 @@ if (env.__FPDSettings !== undefined) {

recursiveUpdate(settings, env, { setUndefined: false, setDefined: true });

export const cookieJar = new CookieJar(new FileCookieStore(args.cookiesPath));
export const cookieJar = new CookieJar(new FileCookieStore(`${args.dbPath}/cookies.json`));
export const fApi = new Floatplane(
cookieJar,
`Floatplane-Downloader/${DownloaderVersion} (Inrix, +https://github.com/Inrixia/Floatplane-Downloader), CFNetwork`,
Expand Down Expand Up @@ -81,9 +80,6 @@ fApi.extend({
});





// eslint-disable-next-line no-control-regex
const headlessStdoutRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
// Override stdout if headless to not include formatting tags
Expand Down
5 changes: 1 addition & 4 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ export type Args = {
plexUsername: string;
plexPassword: string;
sanityCheck: boolean;
workPath: string;
settingsPath: string;
dbPath: string;
ffmpegPath: string;
cookiesPath: string;
attachmentsPath: string;
};

export type PartialArgs = Partial<Args & Settings>;
Expand Down

0 comments on commit 7414ccf

Please sign in to comment.