Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync v3 - Adds new syncing algorithm #796

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions @types/crunchyTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,6 @@ export type CrunchyEpMeta = {
image: string,
}

export type DownloadedMedia = {
type: 'Video',
lang: LanguageItem,
path: string,
isPrimary?: boolean
} | {
type: 'Audio',
lang: LanguageItem,
path: string,
isPrimary?: boolean
} | {
type: 'Chapters',
lang: LanguageItem,
path: string
} | ({
type: 'Subtitle',
signs: boolean,
cc: boolean
} & sxItem )

export type ParseItem = {
__class__?: string;
isSelected?: boolean,
Expand Down
37 changes: 37 additions & 0 deletions @types/downloaderTypes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Font, MergerInput, SubtitleInput } from './modules/module.merger';
import type { LanguageItem } from '../modules/module.langsData';

export type sxItem = {
language: LanguageItem,
path: string,
file: string
title: string,
fonts: Font[]
}

export type DownloadedMedia = {
type: 'Video',
lang: LanguageItem,
path: string,
uncut?: boolean,
isPrimary?: boolean
} | {
type: 'Audio',
lang: LanguageItem,
path: string,
uncut?: boolean,
isPrimary?: boolean
} | {
type: 'Chapters',
lang: LanguageItem,
path: string
} | ({
type: 'Subtitle',
signs?: boolean,
cc: boolean
} & sxItem )

export type DownloadedMediaMap = {
version: string;
files: DownloadedMedia[];
}
12 changes: 1 addition & 11 deletions @types/hidiveTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,4 @@ export interface HidiveSubtitleInfo {
language: string;
cc: boolean;
url: string;
}

export type DownloadedMedia = {
type: 'Video',
lang: LanguageItem,
path: string,
uncut: boolean
} | ({
type: 'Subtitle',
cc: boolean
} & sxItem )
}
60 changes: 36 additions & 24 deletions adn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ import parseFileName, { Variable } from './modules/module.filename';
import { AvailableFilenameVars } from './modules/module.args';

// Types
import { ServiceClass } from './@types/serviceClassInterface';
import { AuthData, AuthResponse, SearchData, SearchResponse, SearchResponseItem } from './@types/messageHandler';
import { sxItem } from './crunchy';
import { DownloadedMedia } from './@types/hidiveTypes';
import { ADNSearch, ADNSearchShow } from './@types/adnSearch';
import { ADNVideo, ADNVideos } from './@types/adnVideos';
import { ADNPlayerConfig } from './@types/adnPlayerConfig';
import { ADNStreams } from './@types/adnStreams';
import { ADNSubtitles } from './@types/adnSubtitles';
import type { ServiceClass } from './@types/serviceClassInterface';
import type { AuthData, AuthResponse, SearchData, SearchResponse, SearchResponseItem } from './@types/messageHandler';
import type { DownloadedMedia, DownloadedMediaMap, sxItem } from './@types/downloaderTypes';
import type { ADNSearch, ADNSearchShow } from './@types/adnSearch';
import type { ADNVideo, ADNVideos } from './@types/adnVideos';
import type { ADNPlayerConfig } from './@types/adnPlayerConfig';
import type { ADNStreams } from './@types/adnStreams';
import type { ADNSubtitles } from './@types/adnSubtitles';

export default class AnimationDigitalNetwork implements ServiceClass {
public cfg: yamlCfg.ConfigObject;
Expand Down Expand Up @@ -316,7 +315,7 @@ export default class AnimationDigitalNetwork implements ServiceClass {
return { isOk: true, value: selEpsArr };
}

public async muxStreams(data: DownloadedMedia[], options: yargs.ArgvType) {
public async muxStreams(data: DownloadedMedia[], mediaMap: DownloadedMediaMap[], options: yargs.ArgvType) {
this.cfg.bin = await yamlCfg.loadBinCfg();
let hasAudioStreams = false;
if (options.novids || data.filter(a => a.type === 'Video').length === 0)
Expand All @@ -325,9 +324,8 @@ export default class AnimationDigitalNetwork implements ServiceClass {
hasAudioStreams = true;
}
const merger = new Merger({
mediaMap,
onlyVid: hasAudioStreams ? data.filter(a => a.type === 'Video').map((a) : MergerInput => {
if (a.type === 'Subtitle')
throw new Error('Never');
return {
lang: a.lang,
path: a.path,
Expand All @@ -337,34 +335,24 @@ export default class AnimationDigitalNetwork implements ServiceClass {
inverseTrackOrder: false,
keepAllVideos: options.keepAllVideos,
onlyAudio: hasAudioStreams ? data.filter(a => a.type === 'Audio').map((a) : MergerInput => {
if (a.type === 'Subtitle')
throw new Error('Never');
return {
lang: a.lang,
path: a.path,
};
}) : [],
output: `${options.output}.${options.mp4 ? 'mp4' : 'mkv'}`,
subtitles: data.filter(a => a.type === 'Subtitle').map((a) : SubtitleInput => {
if (a.type === 'Video')
throw new Error('Never');
if (a.type === 'Audio')
throw new Error('Never');
return {
file: a.path,
language: a.language,
closedCaption: a.cc
};
}),
simul: data.filter(a => a.type === 'Video').map((a) : boolean => {
if (a.type === 'Subtitle')
throw new Error('Never');
return !a.uncut as boolean;
})[0],
fonts: Merger.makeFontsList(this.cfg.dir.fonts, data.filter(a => a.type === 'Subtitle') as sxItem[]),
videoAndAudio: hasAudioStreams ? [] : data.filter(a => a.type === 'Video').map((a) : MergerInput => {
if (a.type === 'Subtitle')
throw new Error('Never');
return {
lang: a.lang,
path: a.path,
Expand Down Expand Up @@ -417,7 +405,7 @@ export default class AnimationDigitalNetwork implements ServiceClass {
return { isOk: false, reason: new Error('Failed to download media list') };
} else {
if (!options.skipmux) {
await this.muxStreams(res.data, { ...options, output: res.fileName });
await this.muxStreams(res.data, res.mediaMap, { ...options, output: res.fileName });
} else {
console.info('Skipping mux');
}
Expand Down Expand Up @@ -446,6 +434,12 @@ export default class AnimationDigitalNetwork implements ServiceClass {
}

const files: DownloadedMedia[] = [];
const mediaMap: DownloadedMediaMap[] = [];

const fileMap: DownloadedMediaMap = {
version: data.id.toString(),
files: []
};

let dlFailed = false;
let dlVideoOnce = false; // Variable to save if best selected video quality was downloaded
Expand Down Expand Up @@ -710,6 +704,11 @@ export default class AnimationDigitalNetwork implements ServiceClass {
path: `${tsFile}.ts`,
lang: audDub
});
fileMap.files.push({
type: 'Video',
path: `${tsFile}.ts`,
lang: audDub
});
dlVideoOnce = true;
}
} else{
Expand Down Expand Up @@ -773,7 +772,12 @@ export default class AnimationDigitalNetwork implements ServiceClass {
fs.writeFileSync(`${tsFile}.txt`, compiledChapters.join('\r\n'));
files.push({
path: `${tsFile}.txt`,
lang: langsData.languages.find(a=>a.code=='jpn'),
lang: langsData.languages.find(a=>a.code=='jpn')!,
type: 'Chapters'
});
fileMap.files.push({
path: `${tsFile}.txt`,
lang: langsData.languages.find(a=>a.code=='jpn')!,
type: 'Chapters'
});
} catch {
Expand Down Expand Up @@ -899,6 +903,11 @@ export default class AnimationDigitalNetwork implements ServiceClass {
...sxData as sxItem,
cc: false
});
fileMap.files.push({
type: 'Subtitle',
...sxData as sxItem,
cc: false
});
}
subIndex++;
}
Expand All @@ -909,9 +918,12 @@ export default class AnimationDigitalNetwork implements ServiceClass {
console.info('Subtitles downloading skipped!');
}

mediaMap.push(fileMap);

return {
error: dlFailed,
data: files,
mediaMap,
fileName: fileName ? (path.isAbsolute(fileName) ? fileName : path.join(this.cfg.dir.content, fileName)) || './unknown' : './unknown'
};
}
Expand Down
Loading
Loading