Skip to content

Add Channel selection during quick Start #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/lib/prompts/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prompts from "prompts";
import type { Extras, Resolution } from "../types.js";
import { Channels, PROMPT_CONFIRM, Settings, type Extras, type Resolution } from "../types.js";
import { Video } from "../Video.js";

/**
Expand Down Expand Up @@ -79,3 +79,26 @@ export const daysToKeepVideos = async (initial: number): Promise<number> =>
min: 1,
})
).daysToKeepVideos || initial;

export const multiSelectChannelPrompt = async (initial: Channels): Promise<string[]> => {
return (
await prompts({
type: "multiselect",
name: "downloadChannels",
message: "Enable/Disable channels:",
choices: initial.map((initial) => ({ title: initial.title, value: initial.title, selected: !initial.skip })),
hint: "- Space to select. Return to submit",
})
).downloadChannels;
};

export const selectSubscriptionPrompt = async (initial: Settings["subscriptions"]): Promise<string> => {
return (
await prompts({
type: "select",
name: "subscription",
message: "Select a subscription",
choices: [...Object.keys(initial).map((option) => ({ title: initial[option].plan, value: option })), { title: "Confirm", value: PROMPT_CONFIRM }],
})
).subscription;
};
2 changes: 2 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ export type Settings = {
contributeMetrics: boolean;
};
};

export const PROMPT_CONFIRM = "confirm";
52 changes: 51 additions & 1 deletion src/quickStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { args, settings, fApi } from "./lib/helpers/index.js";
import { MyPlexAccount } from "@ctrl/plex";
import * as prompts from "./lib/prompts/index.js";

import type { Extras } from "./lib/types.js";
import { PROMPT_CONFIRM, Settings, type Extras } from "./lib/types.js";
import { Video } from "./lib/Video.js";
import { multiSelectChannelPrompt, selectSubscriptionPrompt } from "./lib/prompts/settings.js";

export const promptPlexSections = async (): Promise<void> => {
const plexApi = await new MyPlexAccount(undefined, undefined, undefined, settings.plex.token).connect();
Expand Down Expand Up @@ -41,6 +42,52 @@ export const validatePlexSettings = async (): Promise<void> => {
}
};

export const promptSubscriptionSection = async (): Promise<void> => {
const userSubscription = await fApi.user.subscriptions();
const channels = await fApi.creator.channels(userSubscription.map((channel) => channel.creator));

const subscriptions = userSubscription.reduce<Settings["subscriptions"]>((acc, subscription) => {
acc[subscription.creator] = {
creatorId: subscription.creator,
plan: subscription.plan.title,
skip: false,
channels: channels
.filter((channel) => channel.creator === subscription.creator)
.map((channel) => ({
title: channel.title,
skip: false,
isChannel:
channel.id === "6413623f5b12cca228a28e78"
? `(post, video) => isChannel(post, '${channel.id}') && !video?.title?.toLowerCase().startsWith('caption')`
: `(post) => isChannel(post, '${channel.id}')`,
})),
};
return acc;
}, {});

let selectedSubscriptionId: string | undefined = undefined;

while (selectedSubscriptionId !== PROMPT_CONFIRM) {
selectedSubscriptionId = await selectSubscriptionPrompt(subscriptions);

const subscription = subscriptions[selectedSubscriptionId];

if (subscription) {
const selectedChannels = await multiSelectChannelPrompt(subscription.channels);
subscription.channels = subscription.channels.map((channel) => ({ ...channel, skip: !selectedChannels.includes(channel.title) }));
}
}

for (const subscription of Object.values(subscriptions)) {
settings.subscriptions[subscription.creatorId] ??= {
creatorId: subscription.creatorId,
plan: subscription.plan,
skip: false,
channels: subscription.channels.map((channel) => ({ title: channel.title, skip: channel.skip, isChannel: channel.isChannel })),
};
}
};

export const quickStart = async (): Promise<void> => {
console.log("Welcome to Floatplane Downloader! Thanks for checking it out <3.");
console.log("According to your settings.json this is your first launch! So lets go through the basic setup...\n");
Expand All @@ -62,6 +109,9 @@ export const quickStart = async (): Promise<void> => {
for (const extra in settings.extras) settings.extras[extra as keyof Extras] = extras.indexOf(extra) > -1 ? true : false;
}

console.log("\n== \u001b[38;5;208mSubscriptions\u001b[0m ==\n");
await promptSubscriptionSection();

console.log("\n== \u001b[38;5;208mPlex\u001b[0m ==\n");
settings.plex.enabled = await prompts.plex.usePlex(settings.plex.enabled);
if (settings.plex.enabled) {
Expand Down
Loading