Ability to change the default sub and/or dub langauge in merged file
This commit is contained in:
parent
e80dd03951
commit
c3fbc34478
7 changed files with 91 additions and 8 deletions
8
@types/crunchyTypes.d.ts
vendored
8
@types/crunchyTypes.d.ts
vendored
|
|
@ -22,7 +22,9 @@ export type CrunchyDownloadOptions = {
|
|||
videoTitle: string,
|
||||
force: 'Y'|'y'|'N'|'n'|'C'|'c',
|
||||
ffmpegOptions: string[],
|
||||
mkvmergeOptions: string[]
|
||||
mkvmergeOptions: string[],
|
||||
defaultSub: LanguageItem,
|
||||
defaultAudio: LanguageItem
|
||||
}
|
||||
|
||||
export type CurnchyMultiDownload = {
|
||||
|
|
@ -41,7 +43,9 @@ export type CrunchyMuxOptions = {
|
|||
nocleanup?: boolean,
|
||||
videoTitle: string,
|
||||
ffmpegOptions: string[],
|
||||
mkvmergeOptions: string[]
|
||||
mkvmergeOptions: string[],
|
||||
defaultSub: LanguageItem,
|
||||
defaultAudio: LanguageItem
|
||||
}
|
||||
|
||||
export type CrunchyEpMeta = {
|
||||
|
|
|
|||
2
@types/messageHandler.d.ts
vendored
2
@types/messageHandler.d.ts
vendored
|
|
@ -93,7 +93,7 @@ export type FuniGetEpisodeData = { subs: FuniSubsData, fnSlug: FuniEpisodeData,
|
|||
export type FuniStreamData = { force?: 'Y'|'y'|'N'|'n'|'C'|'c', callbackMaker?: (data: DownloadInfo) => HLSCallback, q: number, x: number, fileName: string, numbers: number, novids?: boolean,
|
||||
timeout: number, partsize: number, fsRetryTime: number, noaudio?: boolean, mp4: boolean, ass: boolean, fontSize: number, fontName?: string, skipmux?: boolean,
|
||||
forceMuxer: AvailableMuxer | undefined, simul: boolean, skipSubMux: boolean, nocleanup: boolean, override: string[], videoTitle: string,
|
||||
ffmpegOptions: string[], mkvmergeOptions: string[] }
|
||||
ffmpegOptions: string[], mkvmergeOptions: string[], defaultAudio: LanguageItem, defaultSub: LanguageItem }
|
||||
export type FuniSubsData = { nosubs?: boolean, sub: boolean, dlsubs: string[] }
|
||||
export type DownloadData = { id: string, e: string, dubLang: string[], dlsubs: string[], fileName: string, q: number, novids: boolean, noaudio: boolean }
|
||||
|
||||
|
|
|
|||
|
|
@ -1202,7 +1202,7 @@ export default class Crunchy implements ServiceClass {
|
|||
const langItem = subsItem.locale;
|
||||
const sxData: Partial<sxItem> = {};
|
||||
sxData.language = langItem;
|
||||
const isCC = langItem.code === audDub
|
||||
const isCC = langItem.code === audDub;
|
||||
sxData.file = langsData.subsFile(fileName as string, subsIndex, langItem, isCC);
|
||||
sxData.path = path.join(this.cfg.dir.content, sxData.file);
|
||||
if (files.some(a => a.type === 'Subtitle' && (a.language.cr_locale == langItem.cr_locale || a.language.locale == langItem.locale) && a.cc === isCC))
|
||||
|
|
@ -1278,6 +1278,10 @@ export default class Crunchy implements ServiceClass {
|
|||
options: {
|
||||
ffmpeg: options.ffmpegOptions,
|
||||
mkvmerge: options.mkvmergeOptions
|
||||
},
|
||||
defaults: {
|
||||
audio: options.defaultAudio,
|
||||
sub: options.defaultSub
|
||||
}
|
||||
});
|
||||
const bin = Merger.checkMerger(this.cfg.bin, options.mp4, options.forceMuxer);
|
||||
|
|
|
|||
4
funi.ts
4
funi.ts
|
|
@ -819,6 +819,10 @@ export default class Funi implements ServiceClass {
|
|||
options: {
|
||||
ffmpeg: data.ffmpegOptions,
|
||||
mkvmerge: data.mkvmergeOptions
|
||||
},
|
||||
defaults: {
|
||||
audio: data.defaultAudio,
|
||||
sub: data.defaultSub
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import yargs, { Choices } from 'yargs';
|
||||
import { args, AvailableMuxer, groups } from './module.args';
|
||||
import { LanguageItem } from './module.langsData';
|
||||
|
||||
let argvC: { [x: string]: unknown; ffmpegOptions: string[], mkvmergeOptions: string[], force: 'Y'|'y'|'N'|'n'|'C'|'c', skipUpdate: boolean, videoTitle: string, override: string[], fsRetryTime: number, forceMuxer: AvailableMuxer|undefined; username: string|undefined, password: string|undefined, silentAuth: boolean, skipSubMux: boolean, downloadArchive: boolean, addArchive: boolean, but: boolean, auth: boolean | undefined; dlFonts: boolean | undefined; search: string | undefined; 'search-type': string; page: number | undefined; 'search-locale': string; new: boolean | undefined; 'movie-listing': string | undefined; series: string | undefined; s: string | undefined; e: string | undefined; q: number; x: number; kstream: number; partsize: number; hslang: string; dlsubs: string[]; novids: boolean | undefined; noaudio: boolean | undefined; nosubs: boolean | undefined; dubLang: string[]; all: boolean; fontSize: number; allDubs: boolean; timeout: number; simul: boolean; mp4: boolean; skipmux: boolean | undefined; fileName: string; numbers: number; nosess: string; debug: boolean | undefined; nocleanup: boolean; help: boolean | undefined; service: 'funi' | 'crunchy'; update: boolean; fontName: string | undefined; _: (string | number)[]; $0: string; };
|
||||
let argvC: { [x: string]: unknown; defaultAudio: LanguageItem, defaultSub: LanguageItem, ffmpegOptions: string[], mkvmergeOptions: string[], force: 'Y'|'y'|'N'|'n'|'C'|'c', skipUpdate: boolean, videoTitle: string, override: string[], fsRetryTime: number, forceMuxer: AvailableMuxer|undefined; username: string|undefined, password: string|undefined, silentAuth: boolean, skipSubMux: boolean, downloadArchive: boolean, addArchive: boolean, but: boolean, auth: boolean | undefined; dlFonts: boolean | undefined; search: string | undefined; 'search-type': string; page: number | undefined; 'search-locale': string; new: boolean | undefined; 'movie-listing': string | undefined; series: string | undefined; s: string | undefined; e: string | undefined; q: number; x: number; kstream: number; partsize: number; hslang: string; dlsubs: string[]; novids: boolean | undefined; noaudio: boolean | undefined; nosubs: boolean | undefined; dubLang: string[]; all: boolean; fontSize: number; allDubs: boolean; timeout: number; simul: boolean; mp4: boolean; skipmux: boolean | undefined; fileName: string; numbers: number; nosess: string; debug: boolean | undefined; nocleanup: boolean; help: boolean | undefined; service: 'funi' | 'crunchy'; update: boolean; fontName: string | undefined; _: (string | number)[]; $0: string; };
|
||||
|
||||
export type ArgvType = typeof argvC;
|
||||
|
||||
|
|
@ -58,6 +59,13 @@ const getArgv = (cfg: { [key:string]: unknown }) => {
|
|||
for (const item of data)
|
||||
argv.option(item.name, {
|
||||
...item,
|
||||
coerce: (value) => {
|
||||
if (item.transformer) {
|
||||
return item.transformer(value);
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
},
|
||||
choices: item.choices as unknown as Choices
|
||||
});
|
||||
return argv as unknown as yargs.Argv<typeof argvC>;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ const availableFilenameVars: AvailableFilenameVars[] = [
|
|||
export type AvailableMuxer = 'ffmpeg' | 'mkvmerge'
|
||||
export const muxer: AvailableMuxer[] = [ 'ffmpeg', 'mkvmerge' ];
|
||||
|
||||
type TAppArg<T extends boolean|string|number|unknown[]> = {
|
||||
type TAppArg<T extends boolean|string|number|unknown[], K = any> = {
|
||||
name: string,
|
||||
group: keyof typeof groups,
|
||||
type: 'boolean'|'string'|'number'|'array',
|
||||
|
|
@ -41,7 +41,8 @@ type TAppArg<T extends boolean|string|number|unknown[]> = {
|
|||
},
|
||||
service: 'funi'|'crunchy'|'both',
|
||||
usage: string // -(-)${name} will be added for each command,
|
||||
demandOption?: true
|
||||
demandOption?: true,
|
||||
transformer?: (value: T) => K
|
||||
}
|
||||
|
||||
const args: TAppArg<boolean|number|string|unknown[]>[] = [
|
||||
|
|
@ -637,7 +638,45 @@ const args: TAppArg<boolean|number|string|unknown[]>[] = [
|
|||
default: {
|
||||
default: []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'defaultAudio',
|
||||
describe: `Set the default audio track by language code\nPossible Values: ${languages.map(a => a.code).join(', ')}`,
|
||||
docDescribe: true,
|
||||
group: 'mux',
|
||||
service: 'both',
|
||||
type: 'string',
|
||||
usage: '${args}',
|
||||
default: {
|
||||
default: 'eng'
|
||||
},
|
||||
transformer: (val) => {
|
||||
const item = languages.find(a => a.code === val);
|
||||
if (!item) {
|
||||
throw new Error(`Unable to find language code ${val}!`);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'defaultSub',
|
||||
describe: `Set the default subtitle track by language code\nPossible Values: ${languages.map(a => a.code).join(', ')}`,
|
||||
docDescribe: true,
|
||||
group: 'mux',
|
||||
service: 'both',
|
||||
type: 'string',
|
||||
usage: '${args}',
|
||||
default: {
|
||||
default: 'eng'
|
||||
},
|
||||
transformer: (val) => {
|
||||
const item = languages.find(a => a.code === val);
|
||||
if (!item) {
|
||||
throw new Error(`Unable to find language code ${val}!`);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
const getDefault = <T extends boolean|string|number|unknown[]>(name: string, cfg: Record<string, T>): T => {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,10 @@ export type MergerOptions = {
|
|||
ffmpeg: string[],
|
||||
mkvmerge: string[]
|
||||
},
|
||||
defaults: {
|
||||
audio: LanguageItem,
|
||||
sub: LanguageItem
|
||||
}
|
||||
}
|
||||
|
||||
class Merger {
|
||||
|
|
@ -163,12 +167,22 @@ class Merger {
|
|||
args.push('--track-name', `0:"${trackName}"`);
|
||||
//args.push('--track-name', `1:"${trackName}"`);
|
||||
args.push(`--language 1:${vid.lang.code}`);
|
||||
if (this.options.defaults.audio.code === vid.lang.code) {
|
||||
args.push('--default-track 1');
|
||||
} else {
|
||||
args.push('--default-track 1:0')
|
||||
}
|
||||
hasVideo = true;
|
||||
} else {
|
||||
args.push(
|
||||
'--no-video',
|
||||
'--audio-tracks 1'
|
||||
);
|
||||
if (this.options.defaults.audio.code === vid.lang.code) {
|
||||
args.push(`--default-track 1`)
|
||||
} else {
|
||||
args.push('--default-track 1:0')
|
||||
}
|
||||
args.push('--track-name', `1:"${vid.lang.name}"`);
|
||||
args.push(`--language 1:${vid.lang.code}`);
|
||||
}
|
||||
|
|
@ -183,6 +197,11 @@ class Merger {
|
|||
'--no-video',
|
||||
'--audio-tracks 0'
|
||||
);
|
||||
if (this.options.defaults.audio.code === aud.lang.code) {
|
||||
args.push('--default-track 0');
|
||||
} else {
|
||||
args.push('--default-track 0:0')
|
||||
}
|
||||
args.push(`"${aud.path}"`);
|
||||
}
|
||||
|
||||
|
|
@ -190,6 +209,11 @@ class Merger {
|
|||
for (const subObj of this.options.subtitles) {
|
||||
args.push('--track-name', `0:"${(subObj.language.language || subObj.language.name) + `${subObj.closedCaption === true ? ' CC' : ''}`}"`);
|
||||
args.push('--language', `0:"${subObj.language.code}"`);
|
||||
if (this.options.defaults.sub.code === subObj.language.code) {
|
||||
args.push('--default-track 0');
|
||||
} else {
|
||||
args.push('--default-track 0:0')
|
||||
}
|
||||
args.push(`"${subObj.file}"`);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue