From 9127b7fb23a07548e203b36535ac757dac7d57d5 Mon Sep 17 00:00:00 2001 From: Peter Eskdale Date: Mon, 5 Jul 2021 19:05:29 +0100 Subject: [PATCH 1/2] Add option for post-processing command/script --- src/lib/Video.ts | 26 +++++++++++++++++++++----- src/lib/defaults.ts | 1 + src/lib/types.ts | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/lib/Video.ts b/src/lib/Video.ts index e893717..9a81a41 100644 --- a/src/lib/Video.ts +++ b/src/lib/Video.ts @@ -1,4 +1,4 @@ -import { execFile } from 'child_process'; +import { exec, execFile } from 'child_process'; import { createWriteStream } from 'fs'; import fs from 'fs/promises'; @@ -38,7 +38,7 @@ export default class Video { this.thumbnail = video.thumbnail; } - private get fullPath(): string { + private formatString(string: string): string { const formatLookup: FilePathFormattingOptions = { '%channelTitle%': this.channel.title, '%episodeNumber%': this.channel.lookupVideoDB(this.guid).episodeNo.toString(), @@ -51,12 +51,15 @@ export default class Video { '%videoTitle%': this.title.replace(/ - /g, ' ').replace(/\//g, ' ').replace(/\\/g, ' '), }; - let fullPath = settings.filePathFormatting; for (const [match, value] of Object.entries(formatLookup)) { - fullPath = fullPath.replace(new RegExp(match, 'g'), value); + string = string.replace(new RegExp(match, 'g'), value); } - return fullPath; + return string; + } + + private get fullPath(): string { + return this.formatString(settings.filePathFormatting); } private get folderPath(): string { @@ -193,8 +196,21 @@ export default class Video { ); this.expectedSize = await this.muxedBytes(); await this.markCompleted(); + await this.postProcessingCommand(); await fs.unlink(`${this.filePath}.partial`); // Set the files update time to when the video was released await fs.utimes(`${this.filePath}.mp4`, new Date(), this.releaseDate); } + + public async postProcessingCommand(): Promise { + const command = this.formatString(settings.postProcessingCommand); + await new Promise((resolve, reject) => + exec(command, + (error, stdout) => { + if (error !== null) reject(error); + else resolve(stdout); + } + ) + ); + } } diff --git a/src/lib/defaults.ts b/src/lib/defaults.ts index b20edd1..c2c1369 100644 --- a/src/lib/defaults.ts +++ b/src/lib/defaults.ts @@ -174,4 +174,5 @@ export const defaultSettings: Settings = { 'ltt supporter plus': 'Linus Tech Tips', }, subscriptions: {}, + postProcessingCommand: '', }; diff --git a/src/lib/types.ts b/src/lib/types.ts index 942eeab..b2477d1 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -86,4 +86,5 @@ export type Settings = { [key: string]: SubscriptionSettings; }; plex: PlexSettings; + postProcessingCommand: string; }; From a20ee0be97a5c27746b7d9efde8abd1f22559bbb Mon Sep 17 00:00:00 2001 From: Peter Eskdale Date: Mon, 5 Jul 2021 19:09:51 +0100 Subject: [PATCH 2/2] Add postProcessingCommand to wiki --- wiki/settings.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wiki/settings.md b/wiki/settings.md index b35e0f2..1255f9f 100644 --- a/wiki/settings.md +++ b/wiki/settings.md @@ -122,6 +122,17 @@ Added for Kodi support as Kodi looks for artwork in the format `VideoName-thumb.
+**postProcessingCommand**:
+A command to run after a video has sucessfully downloaded.
+You can refer to `_filePathFormattingOPTIONS` for options on what can be used.
+Strings surounded by % will be replaced with their respective values.
+ +```json +"postProcessingCommand": "" +``` + +
+ ## Plex Use **quickstartPrompts** to easily set plex settings.