mirror of
https://github.com/anidl/multi-downloader-nx.git
synced 2026-04-27 19:12:56 +00:00
[AO] Add --locale support
Currently known supported API locales are "pt" and "es"
This commit is contained in:
parent
67cdc42d64
commit
d2117a1390
4 changed files with 20 additions and 7 deletions
11
ao.ts
11
ao.ts
|
|
@ -56,6 +56,7 @@ export default class AnimeOnegai implements ServiceClass {
|
||||||
public cfg: yamlCfg.ConfigObject;
|
public cfg: yamlCfg.ConfigObject;
|
||||||
private token: Record<string, any>;
|
private token: Record<string, any>;
|
||||||
private req: reqModule.Req;
|
private req: reqModule.Req;
|
||||||
|
public locale: string;
|
||||||
public jpnStrings: string[] = [
|
public jpnStrings: string[] = [
|
||||||
'Japonés con Subtítulos en Español',
|
'Japonés con Subtítulos en Español',
|
||||||
'Japonés con Subtítulos en Portugués',
|
'Japonés con Subtítulos en Portugués',
|
||||||
|
|
@ -75,11 +76,13 @@ export default class AnimeOnegai implements ServiceClass {
|
||||||
this.cfg = yamlCfg.loadCfg();
|
this.cfg = yamlCfg.loadCfg();
|
||||||
this.token = yamlCfg.loadAOToken();
|
this.token = yamlCfg.loadAOToken();
|
||||||
this.req = new reqModule.Req(domain, debug, false, 'ao');
|
this.req = new reqModule.Req(domain, debug, false, 'ao');
|
||||||
|
this.locale = 'es';
|
||||||
}
|
}
|
||||||
|
|
||||||
public async cli() {
|
public async cli() {
|
||||||
console.info(`\n=== Multi Downloader NX ${packageJson.version} ===\n`);
|
console.info(`\n=== Multi Downloader NX ${packageJson.version} ===\n`);
|
||||||
const argv = yargs.appArgv(this.cfg.cli);
|
const argv = yargs.appArgv(this.cfg.cli);
|
||||||
|
this.locale = argv.locale;
|
||||||
if (argv.debug)
|
if (argv.debug)
|
||||||
this.debug = true;
|
this.debug = true;
|
||||||
|
|
||||||
|
|
@ -118,7 +121,7 @@ export default class AnimeOnegai implements ServiceClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async doSearch(data: SearchData): Promise<SearchResponse> {
|
public async doSearch(data: SearchData): Promise<SearchResponse> {
|
||||||
const searchReq = await this.req.getData(`https://api.animeonegai.com/v1/search/algolia/${encodeURIComponent(data.search)}`);
|
const searchReq = await this.req.getData(`https://api.animeonegai.com/v1/search/algolia/${encodeURIComponent(data.search)}?lang=${this.locale}`);
|
||||||
if (!searchReq.ok || !searchReq.res) {
|
if (!searchReq.ok || !searchReq.res) {
|
||||||
console.error('Search FAILED!');
|
console.error('Search FAILED!');
|
||||||
return { isOk: false, reason: new Error('Search failed. No more information provided') };
|
return { isOk: false, reason: new Error('Search failed. No more information provided') };
|
||||||
|
|
@ -157,14 +160,14 @@ export default class AnimeOnegai implements ServiceClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getShow(id: number) {
|
public async getShow(id: number) {
|
||||||
const getSeriesData = await this.req.getData(`https://api.animeonegai.com/v1/asset/${id}`);
|
const getSeriesData = await this.req.getData(`https://api.animeonegai.com/v1/asset/${id}?lang=${this.locale}`);
|
||||||
if (!getSeriesData.ok || !getSeriesData.res) {
|
if (!getSeriesData.ok || !getSeriesData.res) {
|
||||||
console.error('Failed to get Show Data');
|
console.error('Failed to get Show Data');
|
||||||
return { isOk: false };
|
return { isOk: false };
|
||||||
}
|
}
|
||||||
const seriesData = await getSeriesData.res.json() as AnimeOnegaiSeries;
|
const seriesData = await getSeriesData.res.json() as AnimeOnegaiSeries;
|
||||||
|
|
||||||
const getSeasonData = await this.req.getData(`https://api.animeonegai.com/v1/asset/content/${id}`);
|
const getSeasonData = await this.req.getData(`https://api.animeonegai.com/v1/asset/content/${id}?lang=${this.locale}`);
|
||||||
if (!getSeasonData.ok || !getSeasonData.res) {
|
if (!getSeasonData.ok || !getSeasonData.res) {
|
||||||
console.error('Failed to get Show Data');
|
console.error('Failed to get Show Data');
|
||||||
return { isOk: false };
|
return { isOk: false };
|
||||||
|
|
@ -409,7 +412,7 @@ export default class AnimeOnegai implements ServiceClass {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const playbackReq = await this.req.getData(`https://api.animeonegai.com/v1/media/${media.videoId}`, AuthHeaders);
|
const playbackReq = await this.req.getData(`https://api.animeonegai.com/v1/media/${media.videoId}?lang=${this.locale}`, AuthHeaders);
|
||||||
if(!playbackReq.ok || !playbackReq.res){
|
if(!playbackReq.ok || !playbackReq.res){
|
||||||
console.error('Request Stream URLs FAILED!');
|
console.error('Request Stream URLs FAILED!');
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,12 @@ class AnimeOnegaiHandler extends Base implements MessageHandler {
|
||||||
super(ws);
|
super(ws);
|
||||||
this.ao = new AnimeOnegai();
|
this.ao = new AnimeOnegai();
|
||||||
this.initState();
|
this.initState();
|
||||||
|
this.getDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
public getDefaults() {
|
||||||
|
const _default = yargs.appArgv(this.ao.cfg.cli, true);
|
||||||
|
this.ao.locale = _default.locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async auth(data: AuthData) {
|
public async auth(data: AuthData) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { dubLanguageCodes, languages, searchLocales, subtitleLanguagesFilter } from './module.langsData';
|
import { aoSearchLocales, dubLanguageCodes, languages, searchLocales, subtitleLanguagesFilter } from './module.langsData';
|
||||||
|
|
||||||
const groups = {
|
const groups = {
|
||||||
'auth': 'Authentication:',
|
'auth': 'Authentication:',
|
||||||
|
|
@ -107,12 +107,12 @@ const args: TAppArg<boolean|number|string|unknown[]>[] = [
|
||||||
describe: 'Set the service locale',
|
describe: 'Set the service locale',
|
||||||
docDescribe: 'Set the local that will be used for the API.',
|
docDescribe: 'Set the local that will be used for the API.',
|
||||||
group: 'search',
|
group: 'search',
|
||||||
choices: (searchLocales.filter(a => a !== undefined) as string[]),
|
choices: ([...searchLocales.filter(a => a !== undefined), ...aoSearchLocales.filter(a => a !== undefined)] as string[]),
|
||||||
default: {
|
default: {
|
||||||
default: 'en-US'
|
default: 'en-US'
|
||||||
},
|
},
|
||||||
type: 'string',
|
type: 'string',
|
||||||
service: ['crunchy'],
|
service: ['crunchy', 'ao'],
|
||||||
usage: '${locale}'
|
usage: '${locale}'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,10 @@ const searchLocales = (() => {
|
||||||
return ['', ...new Set(languages.map(l => { return l.cr_locale; }).slice(0, -1))];
|
return ['', ...new Set(languages.map(l => { return l.cr_locale; }).slice(0, -1))];
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
export const aoSearchLocales = (() => {
|
||||||
|
return ['', ...new Set(languages.map(l => { return l.ao_locale; }).slice(0, -1))];
|
||||||
|
})();
|
||||||
|
|
||||||
// convert
|
// convert
|
||||||
const fixLanguageTag = (tag: string) => {
|
const fixLanguageTag = (tag: string) => {
|
||||||
tag = typeof tag == 'string' ? tag : 'und';
|
tag = typeof tag == 'string' ? tag : 'und';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue