[AO] Add --locale support

Currently known supported API locales are "pt" and "es"
This commit is contained in:
AnimeDL 2024-04-11 13:11:33 -07:00
parent 67cdc42d64
commit d2117a1390
4 changed files with 20 additions and 7 deletions

11
ao.ts
View file

@ -56,6 +56,7 @@ export default class AnimeOnegai implements ServiceClass {
public cfg: yamlCfg.ConfigObject;
private token: Record<string, any>;
private req: reqModule.Req;
public locale: string;
public jpnStrings: string[] = [
'Japonés con Subtítulos en Español',
'Japonés con Subtítulos en Portugués',
@ -75,11 +76,13 @@ export default class AnimeOnegai implements ServiceClass {
this.cfg = yamlCfg.loadCfg();
this.token = yamlCfg.loadAOToken();
this.req = new reqModule.Req(domain, debug, false, 'ao');
this.locale = 'es';
}
public async cli() {
console.info(`\n=== Multi Downloader NX ${packageJson.version} ===\n`);
const argv = yargs.appArgv(this.cfg.cli);
this.locale = argv.locale;
if (argv.debug)
this.debug = true;
@ -118,7 +121,7 @@ export default class AnimeOnegai implements ServiceClass {
}
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) {
console.error('Search FAILED!');
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) {
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) {
console.error('Failed to get Show Data');
return { isOk: false };
}
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) {
console.error('Failed to get Show Data');
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){
console.error('Request Stream URLs FAILED!');
return undefined;

View file

@ -14,6 +14,12 @@ class AnimeOnegaiHandler extends Base implements MessageHandler {
super(ws);
this.ao = new AnimeOnegai();
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) {

View file

@ -1,4 +1,4 @@
import { dubLanguageCodes, languages, searchLocales, subtitleLanguagesFilter } from './module.langsData';
import { aoSearchLocales, dubLanguageCodes, languages, searchLocales, subtitleLanguagesFilter } from './module.langsData';
const groups = {
'auth': 'Authentication:',
@ -107,12 +107,12 @@ const args: TAppArg<boolean|number|string|unknown[]>[] = [
describe: 'Set the service locale',
docDescribe: 'Set the local that will be used for the API.',
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: 'en-US'
},
type: 'string',
service: ['crunchy'],
service: ['crunchy', 'ao'],
usage: '${locale}'
},
{

View file

@ -73,6 +73,10 @@ const searchLocales = (() => {
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
const fixLanguageTag = (tag: string) => {
tag = typeof tag == 'string' ? tag : 'und';