Skip to content

Commit

Permalink
pkg updates, sanity check fixes & linting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Aug 14, 2023
1 parent 8765eb9 commit 25095b0
Show file tree
Hide file tree
Showing 12 changed files with 1,308 additions and 906 deletions.
2,156 changes: 1,279 additions & 877 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -30,7 +30,7 @@
"process.argv": "^0.6.1",
"prompts": "^2.4.2",
"sanitize-filename": "^1.6.3",
"semver": "^7.5.3",
"semver": "^7.5.4",
"stream-throttle": "^0.1.3",
"tough-cookie": "^4.1.3",
"tough-cookie-file-store": "^2.0.3"
Expand All @@ -43,12 +43,12 @@
"@types/semver": "^7.5.0",
"@types/stream-throttle": "^0.1.1",
"@types/tough-cookie-file-store": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"esbuild": "^0.18.10",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"esbuild": "^0.19.2",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"pkg": "^5.8.1",
"typescript": "^5.1.5"
"typescript": "^5.1.6"
}
}
6 changes: 3 additions & 3 deletions src/Downloader.ts
Expand Up @@ -57,7 +57,7 @@ const updateSummaryBar = () => {
}
return summary;
},
{ totalMB: 0, downloadedMB: 0, downloadSpeed: 0 }
{ totalMB: 0, downloadedMB: 0, downloadSpeed: 0 },
);
// (videos remaining * avg time to download a video)
const processed = `Processed: ${ye(completedVideos)}/${ye(totalVideos)}`;
Expand Down Expand Up @@ -126,10 +126,10 @@ const processVideo = async (fTitle: string, video: Video, retries = 0) => {
{
percentage: downloadProgress.percent,
message: `${reset}${cy(downloadedMB.toFixed(2))}/${cy(totalMB.toFixed(2) + "MB")} ${gr(((downloadSpeed / 1024000) * 8).toFixed(2) + "mb/s")} ETA: ${bl(
Math.floor(downloadETA / 60) + "m " + (Math.floor(downloadETA) % 60) + "s"
Math.floor(downloadETA / 60) + "m " + (Math.floor(downloadETA) % 60) + "s",
)}`,
},
false
false,
);
summaryStats[fTitle] = { totalMB, downloadedMB, downloadSpeed };
updateSummaryBar();
Expand Down
2 changes: 1 addition & 1 deletion src/float.ts
Expand Up @@ -66,7 +66,7 @@ process.on("SIGTERM", process.exit);
console.log(
chalk`There is a ${diff(latest.version, DownloaderVersion)} update available! ${DownloaderVersion} > ${
latest.version
}.\nHead to {cyanBright https://github.com/Inrixia/Floatplane-Downloader/releases} to update!\n`
}.\nHead to {cyanBright https://github.com/Inrixia/Floatplane-Downloader/releases} to update!\n`,
);

if (args.sanityCheck) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Subscription.ts
Expand Up @@ -40,7 +40,7 @@ export default class Subscription {
if (channel.daysToKeepVideos !== undefined) {
const ignoreBeforeTimestamp = Subscription.getIgnoreBeforeTimestamp(channel);
process.stdout.write(
chalk`Checking for videos older than {cyanBright ${channel.daysToKeepVideos}} days in channel {yellow ${channel.title}} for {redBright deletion}...`
chalk`Checking for videos older than {cyanBright ${channel.daysToKeepVideos}} days in channel {yellow ${channel.title}} for {redBright deletion}...`,
);
let deletedFiles = 0;
let deletedVideos = 0;
Expand Down Expand Up @@ -82,7 +82,7 @@ export default class Subscription {
for (const identifier of channel.identifiers) {
if (typeof identifier.type !== "string")
throw new Error(
`Value for channel identifier type ${post[identifier.type]} on channel ${channel.title} is of type ${typeof post[identifier.type]} not string!`
`Value for channel identifier type ${post[identifier.type]} on channel ${channel.title} is of type ${typeof post[identifier.type]} not string!`,
);

let nextChannel = false;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/Video.ts
Expand Up @@ -20,7 +20,7 @@ import type { BlogPost } from "floatplane/creator";
import type { DeliveryResponse } from "floatplane/cdn";
import type { ValueOfA } from "@inrixia/helpers/ts";
import db from "@inrixia/db";
import { ThrottleGroup } from "stream-throttle";
import { ThrottleGroup, type ThrottleOptions } from "stream-throttle";

const fileExists = async (path: string): Promise<boolean> => {
try {
Expand Down Expand Up @@ -62,7 +62,7 @@ export class Video {

private static Attachments = db<Record<string, Attachment>>(`./db/attachments.json`);

private static ThrottleGroup = new ThrottleGroup({ rate: settings.maxDownloadSpeed * byteToMbits });
private static ThrottleGroup = settings.maxDownloadSpeed > -1 ? new ThrottleGroup({ rate: settings.maxDownloadSpeed * byteToMbits }) : undefined;

private folderPath: string;
private filePath: string;
Expand Down Expand Up @@ -300,7 +300,7 @@ export class Video {
const downloadRequest = fApi.got.stream(`${downloadOrigin.url}${downloadVariant.url}`, requestOptions);
// Pipe the download to the file once response starts
const writeStream = createWriteStream(this.partialPath, writeStreamOptions);
if (settings.maxDownloadSpeed !== -1) downloadRequest.pipe(Video.ThrottleGroup.throttle(<any>null)).pipe(writeStream);
if (Video.ThrottleGroup) downloadRequest.pipe(Video.ThrottleGroup.throttle(<ThrottleOptions>(<unknown>null))).pipe(writeStream);
downloadRequest.pipe(writeStream);

// Set the videos expectedSize once we know how big it should be for download validation.
Expand Down Expand Up @@ -357,8 +357,8 @@ export class Video {
error.message += stderr;
reject(error);
} else resolve(stdout);
}
)
},
),
);
await fs.unlink(this.partialPath);
// Set the files update time to when the video was released
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ffbinaries.d.ts
Expand Up @@ -10,7 +10,7 @@ declare module "ffbinaries" {
destination?: string;
platform?: string;
},
callback: (err: Error, result: ffbinariesResult) => void
callback: (err: Error, result: ffbinariesResult) => void,
): void;

function detectPlatform(): string;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/helpers.ts
Expand Up @@ -25,7 +25,7 @@ export const cookieJar = new CookieJar(new FileCookieStore("./db/cookies.json"))
import { Floatplane } from "floatplane";
export const fApi = new Floatplane(
cookieJar,
`Floatplane-Downloader/${DownloaderVersion} (Inrix, +https://github.com/Inrixia/Floatplane-Downloader), CFNetwork`
`Floatplane-Downloader/${DownloaderVersion} (Inrix, +https://github.com/Inrixia/Floatplane-Downloader), CFNetwork`,
);

export const settings = db<Settings>("./db/settings.json", { template: defaultSettings, pretty: true, forceCreate: true, updateOnExternalChanges: true });
Expand Down Expand Up @@ -77,7 +77,7 @@ export const fetchFFMPEG = (): Promise<void> =>
process.stdout.write("\u001b[36mDone!\u001b[0m\n\n");
resolve();
}
}
},
);
} else resolve();
});
2 changes: 1 addition & 1 deletion src/lib/prompts/helpers.ts
Expand Up @@ -10,7 +10,7 @@ export const requiredPrompts = (
prompt: prompts.PromptObject,
maxDepth = 2,
cancelPrompt = "\nAnswering this prompt is required to continue.\n",
depth = 0
depth = 0,
): Promise<prompts.Answers<string>> =>
new Promise((res) => {
if (depth > 0 && depth < maxDepth) process.stdout.write(cancelPrompt);
Expand Down
8 changes: 4 additions & 4 deletions src/logins.ts
Expand Up @@ -17,14 +17,14 @@ export const loginFloatplane = async (): Promise<void> => {
} else {
loginResponse = await loopError(
async () => fApi.auth.login(await floatplane.username(), await floatplane.password()),
async (err) => console.error(`\nLooks like those login details didnt work, Please try again... ${err}`)
async (err) => console.error(`\nLooks like those login details didnt work, Please try again... ${err}`),
);

if (loginResponse.needs2FA) {
console.log("Looks like you have 2Factor authentication enabled. Nice!\n");
loginResponse = await loopError(
async () => fApi.auth.factor(await floatplane.token()),
async (err) => console.error(`\nLooks like that 2Factor token didnt work, Please try again... ${err}`)
async (err) => console.error(`\nLooks like that 2Factor token didnt work, Please try again... ${err}`),
);
}
}
Expand All @@ -38,13 +38,13 @@ export const loginPlex = async (): Promise<string> => {
throw new Error('Need plex username/password to login. Please pass them as --plexUsername="" --plexPassword="" or enviroment variables!');
plexToken = (await loopError(
async () => (await new MyPlexAccount(undefined, args.plexUsername, args.plexPassword).connect()).token,
async (err) => console.error(`\nLooks like those login details didnt work, Please try again... ${err}`)
async (err) => console.error(`\nLooks like those login details didnt work, Please try again... ${err}`),
)) as string;
} else {
console.log("\n> Please enter your plex details. (Username and Password is not saved, only used to generate a token.)");
plexToken = (await loopError(
async () => (await new MyPlexAccount(undefined, await plex.username(), await plex.password()).connect()).token,
async (err) => console.error(`\nLooks like those login details didnt work, Please try again... ${err}`)
async (err) => console.error(`\nLooks like those login details didnt work, Please try again... ${err}`),
)) as string;
console.log(`> Fetched plex token: \u001b[36m${plexToken}\u001b[0m!\n`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/quickStart.ts
Expand Up @@ -15,11 +15,11 @@ export const promptPlexSections = async (): Promise<void> => {
const connectedServer = await server.connect();
const library = await connectedServer.library();
return (await library.sections()).filter((section) => section.type === "show");
})
}),
);
settings.plex.sectionsToUpdate = await prompts.plex.sections(
settings.plex.sectionsToUpdate,
serverSections.flatMap((sections) => sections)
serverSections.flatMap((sections) => sections),
);
if (settings.plex.sectionsToUpdate.length === 0) {
console.log("No sectionsToUpdate in config! Disabling plex integration...\n");
Expand Down
2 changes: 1 addition & 1 deletion src/subscriptionFetching.ts
Expand Up @@ -16,7 +16,7 @@ export async function* fetchSubscriptions() {
// Make sure that new subchannels from defaults are added to settings
if (defaultSubChannels[userSubscription.creator] !== undefined) {
const channelsToAdd = defaultSubChannels[userSubscription.creator].filter(
(channel) => settingSubscription.channels.findIndex((chan) => chan.title === channel.title) === -1
(channel) => settingSubscription.channels.findIndex((chan) => chan.title === channel.title) === -1,
);
if (channelsToAdd.length > 0) settingSubscription.channels = [...settingSubscription.channels, ...channelsToAdd];
}
Expand Down

0 comments on commit 25095b0

Please sign in to comment.