Skip to content

Commit

Permalink
Added new seekAndDestroy functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Jan 3, 2023
1 parent f917069 commit 1dcded9
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 289 deletions.
22 changes: 15 additions & 7 deletions src/float.ts
Expand Up @@ -7,6 +7,7 @@ import Downloader from "./Downloader.js";
import chalk from "chalk-template";

import type Subscription from "./lib/Subscription.js";
import type { ContentPost } from "floatplane/content";

import semver from "semver";
const { gt, diff } = semver;
Expand All @@ -19,17 +20,24 @@ import pkg from "../package.json" assert { type: "json" };
* Main function that triggeres everything else in the script
*/
const fetchNewVideos = async (subscriptions: Array<Subscription>, videoProcessor: Downloader) => {
// Function that pops items out of seek and destroy until the array is empty
const posts: Promise<ContentPost>[] = [];
while (settings.floatplane.seekAndDestroy.length > 0) {
const guid = settings.floatplane.seekAndDestroy.pop();
if (guid === undefined) continue;
posts.push(fApi.content.post(guid));
}
let newVideos = 0;
for (const subscription of subscriptions) {
await subscription.deleteOldVideos();
console.log();
newVideos += (
await Promise.all(
videoProcessor.processVideos(
await subscription.fetchNewVideos(settings.floatplane.videosToSearch, settings.extras.stripSubchannelPrefix, settings.floatplane.forceFullSearch)
)
)
).length;
const subVideos = await subscription.fetchNewVideos(
settings.floatplane.videosToSearch,
settings.extras.stripSubchannelPrefix,
settings.floatplane.forceFullSearch
);
const seekVideos = await subscription.seekAndDestroy(await Promise.all(posts), settings.extras.stripSubchannelPrefix);
newVideos += (await Promise.all(videoProcessor.processVideos([...subVideos, ...seekVideos]))).length;
}

if (newVideos !== 0 && settings.plex.enabled) {
Expand Down
37 changes: 36 additions & 1 deletion src/lib/Subscription.ts
@@ -1,10 +1,11 @@
import { BlogPost } from "floatplane/creator";
import { fApi } from "./helpers.js";
import Channel from "./Channel.js";
import db from "@inrixia/db";

import type { SubscriptionSettings } from "./types.js";
import type Video from "./Video.js";
import type { ContentPost } from "floatplane/content";
import type { BlogPost } from "floatplane/creator";

type LastSeenVideo = {
guid: BlogPost["guid"];
Expand Down Expand Up @@ -103,4 +104,38 @@ export default class Subscription {
process.stdout.write(` Skipped ${videos.length - videos.length}.\n`);
return videos;
}

public async seekAndDestroy(contentPosts: ContentPost[], stripSubchannelPrefix: boolean): Promise<Video[]> {
const thisSubsPosts = contentPosts.filter((post) => post.creator.id === this.creatorId);
if (thisSubsPosts.length === 0) return [];
process.stdout.write(`> Seeking and destroying ${thisSubsPosts.length} videos... Destroyed 0`);
let count = 0;
const videos: Video[] = [];
for (const contentPost of thisSubsPosts) {
// Convert as best able to a BlogPost
const blogPost: BlogPost = <BlogPost>(<unknown>{
...contentPost,
videoAttachments: contentPost.videoAttachments === undefined ? undefined : contentPost.videoAttachments.map((att) => att.id),
audioAttachments: contentPost.audioAttachments === undefined ? undefined : contentPost.audioAttachments.map((att) => att.id),
pictureAttachments: contentPost.pictureAttachments === undefined ? undefined : contentPost.pictureAttachments.map((att) => att.id),
creator: {
...contentPost.creator,
owner: {
id: contentPost.creator.owner,
username: "",
},
category: {
title: contentPost.creator.category,
},
card: null,
},
});
const video = this.addVideo(blogPost, stripSubchannelPrefix);
if (video === null) continue;
videos.push(video);
process.stdout.write(`\r> Seeking and destroying ${thisSubsPosts.length} videos... Destroyed ${++count}`);
}
console.log();
return videos;
}
}
1 change: 1 addition & 0 deletions src/lib/defaults.ts
Expand Up @@ -198,6 +198,7 @@ export const defaultSettings: Settings = {
_availableResolutions: defaultResolutions,
downloadEdge: "",
retries: 3,
seekAndDestroy: [],
},
_filePathFormattingOPTIONS: ["%channelTitle%", "%videoTitle%", "%year%", "%month%", "%day%", "%hour%", "%minute%", "%second%"],
filePathFormatting: "./videos/%channelTitle%/%channelTitle% - S%year%E%month%%day%%hour%%minute%%second% - %videoTitle%",
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Expand Up @@ -76,6 +76,7 @@ export type Settings = {
_availableResolutions: Resolutions;
downloadEdge: string;
retries: number;
seekAndDestroy: string[];
};
_filePathFormattingOPTIONS: (keyof FilePathFormattingOptions)[];
filePathFormatting: string;
Expand Down

0 comments on commit 1dcded9

Please sign in to comment.