From e7dfc28513b3ad364bb1dd7643142848f71305a8 Mon Sep 17 00:00:00 2001 From: AnimeDL Date: Mon, 15 Apr 2024 11:00:18 -0700 Subject: [PATCH] [ADN] Add Chapter Support --- @types/adnStreams.d.ts | 12 ++++---- adn.ts | 64 ++++++++++++++++++++++++++++++++++++++++++ modules/module.args.ts | 2 +- 3 files changed, 71 insertions(+), 7 deletions(-) diff --git a/@types/adnStreams.d.ts b/@types/adnStreams.d.ts index 64cbcf7..8942942 100644 --- a/@types/adnStreams.d.ts +++ b/@types/adnStreams.d.ts @@ -42,10 +42,10 @@ export interface Video { duration: number; url: string; image: string; - tcEpisodeStart: string; - tcEpisodeEnd: string; - tcIntroStart: string; - tcIntroEnd: string; - tcEndingStart: string; - tcEndingEnd: string; + tcEpisodeStart?:string; + tcEpisodeEnd?: string; + tcIntroStart?: string; + tcIntroEnd?: string; + tcEndingStart?: string; + tcEndingEnd?: string; } diff --git a/adn.ts b/adn.ts index 859a5f6..7c393be 100644 --- a/adn.ts +++ b/adn.ts @@ -374,6 +374,12 @@ export default class AnimationDigitalNetwork implements ServiceClass { path: a.path, }; }), + chapters: data.filter(a => a.type === 'Chapters').map((a) : MergerInput => { + return { + path: a.path, + lang: a.lang + }; + }), videoTitle: options.videoTitle, options: { ffmpeg: options.ffmpegOptions, @@ -721,6 +727,64 @@ export default class AnimationDigitalNetwork implements ServiceClass { await this.sleep(options.waittime); } + const compiledChapters: string[] = []; + if (options.chapters) { + if (streams.video.tcIntroStart) { + if (streams.video.tcIntroStart != '00:00:00') { + compiledChapters.push( + `CHAPTER${(compiledChapters.length/2)+1}=00:00:00.00`, + `CHAPTER${(compiledChapters.length/2)+1}NAME=Prologue` + ); + } + compiledChapters.push( + `CHAPTER${(compiledChapters.length/2)+1}=${streams.video.tcIntroStart+'.00'}`, + `CHAPTER${(compiledChapters.length/2)+1}NAME=Opening` + ); + compiledChapters.push( + `CHAPTER${(compiledChapters.length/2)+1}=${streams.video.tcIntroEnd+'.00'}`, + `CHAPTER${(compiledChapters.length/2)+1}NAME=Episode` + ); + } else { + compiledChapters.push( + `CHAPTER${(compiledChapters.length/2)+1}=00:00:00.00`, + `CHAPTER${(compiledChapters.length/2)+1}NAME=Episode` + ); + } + + if (streams.video.tcEndingStart) { + compiledChapters.push( + `CHAPTER${(compiledChapters.length/2)+1}=${streams.video.tcEndingStart+'.00'}`, + `CHAPTER${(compiledChapters.length/2)+1}NAME=Ending Start` + ); + compiledChapters.push( + `CHAPTER${(compiledChapters.length/2)+1}=${streams.video.tcEndingEnd+'.00'}`, + `CHAPTER${(compiledChapters.length/2)+1}NAME=Ending End` + ); + } + + if (compiledChapters.length > 0) { + try { + fileName = parseFileName(options.fileName, variables, options.numbers, options.override).join(path.sep); + const outFile = parseFileName(options.fileName, variables, options.numbers, options.override).join(path.sep); + const tsFile = path.isAbsolute(outFile as string) ? outFile : path.join(this.cfg.dir.content, outFile); + const split = outFile.split(path.sep).slice(0, -1); + split.forEach((val, ind, arr) => { + const isAbsolut = path.isAbsolute(outFile as string); + if (!fs.existsSync(path.join(isAbsolut ? '' : this.cfg.dir.content, ...arr.slice(0, ind), val))) + fs.mkdirSync(path.join(isAbsolut ? '' : this.cfg.dir.content, ...arr.slice(0, ind), val)); + }); + fs.writeFileSync(`${tsFile}.txt`, compiledChapters.join('\r\n')); + files.push({ + path: `${tsFile}.txt`, + lang: langsData.languages.find(a=>a.code=='jpn'), + type: 'Chapters' + }); + } catch { + console.error('Failed to write chapter file'); + } + } + } + if(options.dlsubs.indexOf('all') > -1){ options.dlsubs = ['all']; } diff --git a/modules/module.args.ts b/modules/module.args.ts index fcea3e1..61aef8e 100644 --- a/modules/module.args.ts +++ b/modules/module.args.ts @@ -208,7 +208,7 @@ const args: TAppArg[] = [ describe: 'Will fetch the chapters and add them into the final video', type: 'boolean', group: 'dl', - service: ['crunchy'], + service: ['crunchy', 'adn'], docDescribe: 'Will fetch the chapters and add them into the final video.' + '\nCurrently only works with mkvmerge.', usage: '',