From 40cfebb904f169977e1c0f6d8c9f1548cabd83f1 Mon Sep 17 00:00:00 2001 From: AnimeDL Date: Sat, 28 Oct 2023 18:14:00 -0700 Subject: [PATCH] Make sync options configurable --- @types/crunchyTypes.d.ts | 8 +++++ crunchy.ts | 2 +- hidive.ts | 2 +- modules/module.app-args.ts | 4 +++ modules/module.args.ts | 70 ++++++++++++++++++++++++++++++++++---- modules/module.merger.ts | 3 +- 6 files changed, 79 insertions(+), 10 deletions(-) diff --git a/@types/crunchyTypes.d.ts b/@types/crunchyTypes.d.ts index 3ded499..54ac21c 100644 --- a/@types/crunchyTypes.d.ts +++ b/@types/crunchyTypes.d.ts @@ -31,6 +31,10 @@ export type CrunchyDownloadOptions = { dlVideoOnce: boolean, skipmux?: boolean, syncTiming: boolean, + maxSecurityFrames: number, + maxOffsetSeconds: number, + targetLikeness: number, + syncMethod: number, } export type CurnchyMultiDownload = { @@ -55,6 +59,10 @@ export type CrunchyMuxOptions = { defaultAudio: LanguageItem, ccTag: string, syncTiming: boolean, + maxSecurityFrames: number; + maxOffsetSeconds: number; + targetLikeness: number; + syncMethod: number; } export type CrunchyEpMeta = { diff --git a/crunchy.ts b/crunchy.ts index 8d0060e..b60cc1a 100644 --- a/crunchy.ts +++ b/crunchy.ts @@ -1507,7 +1507,7 @@ export default class Crunchy implements ServiceClass { // mergers let isMuxed = false; if (options.syncTiming) { - await merger.createDelays(); + await merger.createDelays(options.syncMethod, options.targetLikeness, options.maxOffsetSeconds, options.maxSecurityFrames); } if (bin.MKVmerge) { await merger.merge('mkvmerge', bin.MKVmerge); diff --git a/hidive.ts b/hidive.ts index ed65dfe..e30c976 100644 --- a/hidive.ts +++ b/hidive.ts @@ -841,7 +841,7 @@ export default class Hidive implements ServiceClass { // mergers let isMuxed = false; if (options.syncTiming) { - await merger.createDelays(); + await merger.createDelays(options.syncMethod, options.targetLikeness, options.maxOffsetSeconds, options.maxSecurityFrames); } if (bin.MKVmerge) { await merger.merge('mkvmerge', bin.MKVmerge); diff --git a/modules/module.app-args.ts b/modules/module.app-args.ts index 60c281e..84b953b 100644 --- a/modules/module.app-args.ts +++ b/modules/module.app-args.ts @@ -68,6 +68,10 @@ let argvC: { originalFontSize: boolean; keepAllVideos: boolean; syncTiming: boolean; + maxSecurityFrames: number; + maxOffsetSeconds: number; + targetLikeness: number; + syncMethod: number; }; export type ArgvType = typeof argvC; diff --git a/modules/module.args.ts b/modules/module.args.ts index ddfe1fe..8d77de3 100644 --- a/modules/module.args.ts +++ b/modules/module.args.ts @@ -6,6 +6,7 @@ const groups = { 'search': 'Search:', 'dl': 'Downloading:', 'mux': 'Muxing:', + 'timing': 'Timing Sync Options:', 'fileName': 'Filename Template:', 'debug': 'Debug:', 'util': 'Utilities:', @@ -420,8 +421,17 @@ const args: TAppArg[] = [ } }, { - name: 'syncTiming', + name: 'skipmux', + describe: 'Skip muxing video, audio and subtitles', + docDescribe: true, group: 'mux', + service: ['all'], + type: 'boolean', + usage: '' + }, + { + name: 'syncTiming', + group: 'timing', describe: 'Attempts to sync timing for multi-dub downloads EXPERIMENTAL', docDescribe: 'If enabled attempts to sync timing for multi-dub downloads.' + '\nNOTE: This is currently experimental and syncs audio and subtitles, though subtitles has a lot of guesswork' @@ -434,13 +444,59 @@ const args: TAppArg[] = [ } }, { - name: 'skipmux', - describe: 'Skip muxing video, audio and subtitles', - docDescribe: true, - group: 'mux', - service: ['all'], + name: 'maxSecurityFrames', + group: 'timing', + describe: 'Sets the maximum consecutive frames to check when syncing timing', + docDescribe: 'Sets the maximum consecutive frames to check when syncing timing' + + '\nNOTE: The higher this is set, the longer it will take to process the timing differences.', + service: ['crunchy','hidive'], type: 'boolean', - usage: '' + usage: '', + default: { + default: 10 + } + }, + { + name: 'maxOffsetSeconds', + group: 'timing', + describe: 'The maximum amount of time that should be scanned for sync timing before failing.', + docDescribe: 'The maximum amount of time that should be scanned for sync timing before failing.' + + '\nNOTE: The higher this is set, the more temporary images will be stored in the temp folder.', + service: ['crunchy','hidive'], + type: 'boolean', + usage: '', + default: { + default: 20 + } + }, + { + name: 'targetLikeness', + group: 'timing', + describe: 'The target for how like a frame should be to be considered a match.', + docDescribe: 'The target for how like a frame should be to be considered a match.' + + '\nNOTE: Setting this too high or too low could lead to issues.', + service: ['crunchy','hidive'], + type: 'boolean', + usage: '', + default: { + default: 0.95 + } + }, + { + name: 'syncMethod', + choices: [1,2,3], + group: 'timing', + describe: 'Method for Syncing. Options: (1) Difference, (2) Frame Analysis, (3) Frame Analysis Slow', + docDescribe: 'Method for Syncing, Options:' + + '\nDifference: Calculates the length difference and uses that (Fastest)' + + '\nFrame Analysis: Analyzes frames to find a match and uses that (Medium) [Default]' + + '\nFrame Analysis Slow: Analyzes frames using the netflix library (may not be available on every platform) for accuracy to find a match and uses that (Very Slow)', + service: ['crunchy','hidive'], + type: 'boolean', + usage: '', + default: { + default: 2 + } }, { name: 'fileName', diff --git a/modules/module.merger.ts b/modules/module.merger.ts index 51abcee..8635041 100644 --- a/modules/module.merger.ts +++ b/modules/module.merger.ts @@ -65,6 +65,7 @@ export type MergerOptions = { } } +/* Defaults */ const SECURITY_FRAMES = 10; const MAX_OFFSET_SEC = 20; const LIKENESS_TARGET = 0.95; @@ -78,7 +79,7 @@ class Merger { this.options.videoTitle = this.options.videoTitle.replace(/"/g, '\''); } - public async createDelays() { + public async createDelays(syncMethod: number, LIKENESS_TARGET: number, MAX_OFFSET_SEC: number, SECURITY_FRAMES: number) { if (this.options.videoAndAudio.length > 1) { const bin = await yamlCfg.loadBinCfg(); const vnas = this.options.videoAndAudio;