From 9e26d270ff7afef3598ee3cbe0d40fd8be9656c8 Mon Sep 17 00:00:00 2001 From: Nick Cunningham <10342737+TheNickOfTime@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:15:43 -0800 Subject: [PATCH] feat: watchers will get the extension of the preset they are using for naming the output file (#286) * feat: adding a shared path alias to access anything in the shared path * feat: watchers will get the extension of the preset they are using for naming the output file --- server/src/scripts/watcher.ts | 42 ++++++++++++++++++++++------------- server/tsconfig.json | 1 + 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/server/src/scripts/watcher.ts b/server/src/scripts/watcher.ts index 570b124f..cbfb7cb4 100644 --- a/server/src/scripts/watcher.ts +++ b/server/src/scripts/watcher.ts @@ -1,17 +1,11 @@ import chokidar from 'chokidar'; +import fs from 'fs/promises'; +import logger from 'logging'; import mime from 'mime'; import path from 'path'; -import fs from 'fs/promises'; -import { - GetWatcherIDFromRuleIDFromDatabase, - GetWatchersFromDatabase, - GetWatcherWithIDFromDatabase, - InsertWatcherRuleToDatabase, - InsertWatcherToDatabase, - RemoveWatcherFromDatabase, - RemoveWatcherRuleFromDatabase, - UpdateWatcherRuleInDatabase, -} from './database/database-watcher'; +import { PresetFormatDict } from 'shared/dict/presets.dict'; +import { QueueRequestType } from 'types/queue'; +import { TranscodeStage } from 'types/transcode'; import { WatcherDefinitionType, WatcherDefinitionWithRulesType, @@ -25,13 +19,22 @@ import { WatcherRuleNumberComparisonMethods, WatcherRuleStringComparisonMethods, } from 'types/watcher'; -import logger from 'logging'; import { EmitToAllClients } from './connections'; -import { AddJob, GetQueue, RemoveJob } from './queue'; -import { QueueRequestType } from 'types/queue'; +import { + GetWatcherIDFromRuleIDFromDatabase, + GetWatchersFromDatabase, + GetWatcherWithIDFromDatabase, + InsertWatcherRuleToDatabase, + InsertWatcherToDatabase, + RemoveWatcherFromDatabase, + RemoveWatcherRuleFromDatabase, + UpdateWatcherRuleInDatabase, +} from './database/database-watcher'; import { CheckFilenameCollision } from './files'; -import { TranscodeStage } from 'types/transcode'; import { ConvertBitsToKilobits, ConvertBytesToMegabytes, GetMediaInfo } from './media'; +import { GetDefaultPresetByName, GetPresetByName } from './presets'; +import { AddJob, GetQueue, RemoveJob } from './queue'; +// import {PresetFormatDict} from ''; const watchers: { [index: number]: chokidar.FSWatcher } = []; @@ -259,10 +262,17 @@ async function onWatcherDetectFileAdd(watcher: WatcherDefinitionWithRulesType, f const isVideo = mime.getType(filePath); if (isVideo && isVideo.includes('video')) { + const presetData = watcher.preset_category.match(/Default:/) + ? GetDefaultPresetByName( + watcher.preset_category.replace(/Default:\s/, ''), + watcher.preset_id + ) + : GetPresetByName(watcher.preset_category, watcher.preset_id); + const parsedPath = path.parse(filePath); const outputPathBase = watcher.output_path ? watcher.output_path : parsedPath.dir; const outputPathName = parsedPath.name; - const outputPathExtension = '.mkv'; + const outputPathExtension = PresetFormatDict[presetData.PresetList[0].FileFormat]; const outputPathFull = path.join(outputPathBase, outputPathName) + outputPathExtension; const checkedOutputPath = ( await CheckFilenameCollision(outputPathBase, [ diff --git a/server/tsconfig.json b/server/tsconfig.json index 89489fa8..a8c5aedd 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -35,6 +35,7 @@ "logging": ["./src/scripts/logging"], "scripts/*": ["./src/scripts/*"], "socket/*": ["./src/socket/*"], + "shared/*": ["../shared/*"], "types/*": ["../shared/types/*"], "funcs/*": ["../shared/funcs/*"] } /* Specify a set of entries that re-map imports to additional lookup locations. */,