Skip to content

Commit

Permalink
Updated packages & migrated to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Sep 17, 2022
1 parent 0670f07 commit b654ea5
Show file tree
Hide file tree
Showing 18 changed files with 852 additions and 365 deletions.
1,010 changes: 780 additions & 230 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions package.json
Expand Up @@ -2,6 +2,7 @@
"name": "floatplane-plex-downloader",
"version": "5.4.0",
"private": true,
"type": "module",
"scripts": {
"prep": "npm install && npm run build",
"prestart": "tsc",
Expand All @@ -14,23 +15,24 @@
},
"dependencies": {
"@ctrl/plex": "^1.5.3",
"@inrixia/db": "^1.8.0",
"@inrixia/helpers": "^1.23.3",
"chalk": "^4.1.2",
"dotenv": "^16.0.1",
"@inrixia/db": "^2.0.0",
"@inrixia/helpers": "^1.23.4",
"chalk": "^5.0.1",
"default-import": "^1.1.5",
"dotenv": "^16.0.2",
"ffbinaries": "^1.1.4",
"floatplane": "^3.2.0",
"html-to-text": "^8.2.0",
"floatplane": "^4.0.0",
"html-to-text": "^8.2.1",
"json5": "^2.2.1",
"multi-progress-bars": "^4.3.1",
"pkg": "^5.8.0",
"process.argv": "^0.6.0",
"prompts": "^2.4.2",
"sanitize-filename": "^1.6.3",
"semver": "^7.3.7",
"tough-cookie": "^4.0.0",
"tough-cookie": "^4.1.2",
"tough-cookie-file-store": "^2.0.3",
"typescript": "^4.7.4"
"typescript": "^4.8.3"
},
"pkg": {
"scripts": "./float.js",
Expand All @@ -41,14 +43,14 @@
]
},
"devDependencies": {
"@types/html-to-text": "^8.1.0",
"@types/html-to-text": "^8.1.1",
"@types/multi-progress": "^2.0.3",
"@types/prompts": "^2.0.14",
"@types/semver": "^7.3.10",
"@types/semver": "^7.3.12",
"@types/tough-cookie-file-store": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"eslint": "^8.19.0",
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"eslint": "^8.23.1",
"eslint-plugin-prettier": "^4.2.1"
}
}
4 changes: 2 additions & 2 deletions src/Downloader.ts
@@ -1,7 +1,7 @@
import { MultiProgressBars, UpdateOptions } from 'multi-progress-bars';
import Video from './lib/Video';
import Video from './lib/Video.js';

import { settings, args } from './lib/helpers';
import { settings, args } from './lib/helpers.js';

type promiseFunction = (f: Promise<void>) => void;

Expand Down
14 changes: 7 additions & 7 deletions src/float.ts
@@ -1,15 +1,15 @@
import { quickStart, validatePlexSettings } from './quickStart';
import { fetchSubscriptions } from './subscriptionFetching';
import { settings, fetchFFMPEG } from './lib/helpers';
import { quickStart, validatePlexSettings } from './quickStart.js';
import { fetchSubscriptions } from './subscriptionFetching.js';
import { settings, fetchFFMPEG } from './lib/helpers.js';
import { MyPlexAccount } from '@ctrl/plex';
import { fApi } from './lib/FloatplaneAPI';
import { loginFloatplane } from './logins';
import Downloader from './Downloader';
import { fApi } from './lib/FloatplaneAPI.js';
import { loginFloatplane } from './logins.js';
import Downloader from './Downloader.js';
import { gt, diff } from 'semver';
import { resolve } from 'path';
import chalk from 'chalk';

import type Subscription from './lib/Subscription';
import type Subscription from './lib/Subscription.js';

/**
* Main function that triggeres everything else in the script
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Channel.ts
Expand Up @@ -2,11 +2,11 @@ import fs from 'fs/promises';
import chalk from 'chalk';

import db from '@inrixia/db';
import Video from './Video';
import Video from './Video.js';

import type { BlogPost } from 'floatplane/creator';
import type { ChannelOptions } from './types';
import type Subscription from './Subscription';
import type { ChannelOptions } from './types.js';
import type Subscription from './Subscription.js';

// e = episodeNo, d = downloaded, s = filesize in bytes, f = file
export type VideoDBEntry = { episodeNo: number; expectedSize?: number; filePath?: string; releaseDate: number };
Expand Down
10 changes: 5 additions & 5 deletions src/lib/Subscription.ts
@@ -1,10 +1,10 @@
import { BlogPost } from 'floatplane/creator';
import { fApi } from './FloatplaneAPI';
import Channel from './Channel';
import { fApi } from './FloatplaneAPI.js';
import Channel from './Channel.js';
import db from '@inrixia/db';

import type { SubscriptionSettings } from './types';
import type Video from './Video';
import type { SubscriptionSettings } from './types.js';
import type Video from './Video.js';

type LastSeenVideo = {
guid: BlogPost['guid'];
Expand Down Expand Up @@ -88,7 +88,7 @@ export default class Subscription {

process.stdout.write(`> Fetching latest videos from [${coloredTitle}]... Fetched ${videos.length} videos!`);

for await (const video of fApi.creator.blogPostsIterable(this.creatorId, { type: 'video' })) {
for await (const video of fApi.creator.blogPostsIterable(this.creatorId, { hasVideo: true })) {
if (!forceFullSearch && video.guid === this.lastSeenVideo.guid) {
// If we have found the last seen video, check if its downloaded.
// If it is then break here and return the videos we have found.
Expand Down
9 changes: 5 additions & 4 deletions src/lib/Video.ts
Expand Up @@ -5,18 +5,18 @@ import fs from 'fs/promises';

const exec = promisify(execCallback);

import { settings, args } from './helpers';
import { settings, args } from './helpers.js';

import { htmlToText } from 'html-to-text';
import sanitize from 'sanitize-filename';
import builder from 'xmlbuilder';

import { nPad } from '@inrixia/helpers/math';
import { fApi } from './FloatplaneAPI';
import { fApi } from './FloatplaneAPI.js';

import type { FilePathFormattingOptions } from './types';
import type { FilePathFormattingOptions } from './types.js';
import type { BlogPost } from 'floatplane/creator';
import type Channel from './Channel';
import type Channel from './Channel.js';

export default class Video {
public guid: BlogPost['guid'];
Expand Down Expand Up @@ -174,6 +174,7 @@ export default class Video {
const cdnInfo = await fApi.cdn.delivery('download', this.videoAttachments[i]);

// Pick a random edge to download off, eventual even distribution
if (cdnInfo.edges === undefined) throw new Error('No edges found for video');
const downloadEdge = cdnInfo.edges[Math.floor(Math.random() * cdnInfo.edges.length)];
if (settings.floatplane.downloadEdge !== '') downloadEdge.hostname = settings.floatplane.downloadEdge;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/defaults.ts
@@ -1,4 +1,4 @@
import { Resolutions, SubChannels, Settings, Args } from './types';
import { Resolutions, SubChannels, Settings, Args } from './types.js';

export const defaultResolutions: Resolutions = ['360', '720', '1080', '2160'];
export const defaultSubChannels: { [key: string]: SubChannels } = {
Expand Down
8 changes: 5 additions & 3 deletions src/lib/helpers.ts
@@ -1,14 +1,16 @@
import { downloadBinaries, detectPlatform, getBinaryFilename } from 'ffbinaries';
import { getEnv, rebuildTypes, recursiveUpdate } from '@inrixia/helpers/object';
import { defaultArgs, defaultSettings } from './defaults';
import ARGV from 'process.argv';
import { defaultArgs, defaultSettings } from './defaults.js';
import db from '@inrixia/db';
import fs from 'fs';

import { defaultImport } from 'default-import';
const ARGV = defaultImport(await import('process.argv'));

import 'dotenv/config';
import { parse } from 'json5';

import type { Args, PartialArgs, Settings } from './types';
import type { Args, PartialArgs, Settings } from './types.js';

export const settings = db<Settings>('./db/settings.json', { template: defaultSettings, pretty: true, forceCreate: true, updateOnExternalChanges: true });
recursiveUpdate(settings, defaultSettings);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/prompts/index.ts
@@ -1,3 +1,3 @@
export * as settings from './settings';
export * as floatplane from './floatplane';
export * as plex from './plex';
export * as settings from './settings.js';
export * as floatplane from './floatplane.js';
export * as plex from './plex.js';
4 changes: 2 additions & 2 deletions src/lib/prompts/plex.ts
@@ -1,5 +1,5 @@
import prompts from 'prompts';
import { requiredPrompts } from './helpers';
import { requiredPrompts } from './helpers.js';

/**
* Prompts user if they want to automatically refresh plex libraries.
Expand All @@ -19,7 +19,7 @@ export const usePlex = async (initial: boolean): Promise<boolean> =>
).usePlex;

import type { Section } from '@ctrl/plex';
import { PlexSections } from '../types';
import { PlexSections } from '../types.js';
/**
* Prompts user to select plex sections to refresh
* @param selectedSections Sections already selected
Expand Down
2 changes: 1 addition & 1 deletion src/lib/prompts/settings.ts
@@ -1,5 +1,5 @@
import prompts from 'prompts';
import type { Extras, Resolution } from '../types';
import type { Extras, Resolution } from '../types.js';

/**
* Prompts user to set the max number of parallel downloads.
Expand Down
16 changes: 7 additions & 9 deletions src/lib/types.ts
@@ -1,16 +1,16 @@
export type Resolutions = ['360', '720', '1080', '2160'];

import type { ValueOfA } from '@inrixia/helpers/ts';
import type { BlogPost } from 'floatplane/creator';

type ChannelIdentifier = {
check: string;
type: keyof BlogPost | 'description';
};
export type ChannelOptions = {
title: string;
skip: boolean;
identifiers:
| Array<{
check: string;
type: keyof BlogPost | 'description';
}>
| false;
identifiers: ChannelIdentifier[] | false;
consoleColor?: string;
daysToKeepVideos: number;
};
Expand Down Expand Up @@ -51,8 +51,6 @@ export type Extras = {
saveNfo: boolean;
};

export type ValueOf<T> = T[keyof T];

export type FilePathFormattingOptions = {
'%channelTitle%': string;
'%episodeNumber%': string;
Expand All @@ -65,7 +63,7 @@ export type FilePathFormattingOptions = {
'%videoTitle%': string;
};

export type Resolution = ValueOf<Resolutions>;
export type Resolution = ValueOfA<Resolutions>;

export type Settings = {
runQuickstartPrompts: boolean;
Expand Down
8 changes: 4 additions & 4 deletions src/logins.ts
@@ -1,8 +1,8 @@
import { loopError } from '@inrixia/helpers/object';
import { floatplane, plex } from './lib/prompts';
import { fApi } from './lib/FloatplaneAPI';
import { floatplane, plex } from './lib/prompts/index.js';
import { fApi } from './lib/FloatplaneAPI.js';
import { MyPlexAccount } from '@ctrl/plex';
import { args } from './lib/helpers';
import { args } from './lib/helpers.js';

export const loginFloatplane = async (): Promise<void> => {
let loginResponse;
Expand All @@ -29,7 +29,7 @@ export const loginFloatplane = async (): Promise<void> => {
);
}
}
console.log(`\nSigned in as \u001b[36m${loginResponse.user.username}\u001b[0m!\n`);
if (loginResponse.user !== undefined) console.log(`\nSigned in as \u001b[36m${loginResponse.user.username}\u001b[0m!\n`);
};

export const loginPlex = async (): Promise<string> => {
Expand Down
12 changes: 6 additions & 6 deletions src/quickStart.ts
@@ -1,11 +1,11 @@
import { loginFloatplane, loginPlex } from './logins';
import { defaultResolutions } from './lib/defaults';
import { args, settings } from './lib/helpers';
import { loginFloatplane, loginPlex } from './logins.js';
import { defaultResolutions } from './lib/defaults.js';
import { args, settings } from './lib/helpers.js';
import { MyPlexAccount } from '@ctrl/plex';
import { fApi } from './lib/FloatplaneAPI';
import * as prompts from './lib/prompts';
import { fApi } from './lib/FloatplaneAPI.js';
import * as prompts from './lib/prompts/index.js';

import type { Extras } from './lib/types';
import type { Extras } from './lib/types.js';

export const promptPlexSections = async (): Promise<void> => {
const plexApi = await new MyPlexAccount(undefined, undefined, undefined, settings.plex.token).connect();
Expand Down
8 changes: 4 additions & 4 deletions src/subscriptionFetching.ts
@@ -1,7 +1,7 @@
import { defaultSubChannels } from './lib/defaults';
import Subscription from './lib/Subscription';
import { fApi } from './lib/FloatplaneAPI';
import { settings } from './lib/helpers';
import { defaultSubChannels } from './lib/defaults.js';
import Subscription from './lib/Subscription.js';
import { fApi } from './lib/FloatplaneAPI.js';
import { settings } from './lib/helpers.js';

export const fetchSubscriptions = async (): Promise<Subscription[]> =>
(await fApi.user.subscriptions())
Expand Down
65 changes: 0 additions & 65 deletions src/test.ts

This file was deleted.

0 comments on commit b654ea5

Please sign in to comment.