Skip to content

Commit

Permalink
feat: watchers will get the extension of the preset they are using fo…
Browse files Browse the repository at this point in the history
…r 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
  • Loading branch information
TheNickOfTime committed Nov 27, 2024
1 parent 7d28af3 commit 9e26d27
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
42 changes: 26 additions & 16 deletions server/src/scripts/watcher.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 } = [];

Expand Down Expand Up @@ -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, [
Expand Down
1 change: 1 addition & 0 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */,
Expand Down

0 comments on commit 9e26d27

Please sign in to comment.