Updated utils/requestCall

Added new options to spoof user agent
New Aruppi APi user agent
Adapt relevant code to new funcionality

fixed line break on urls.ts
pull/59/head v4.2.0
Darkangeel_hd 3 years ago
parent 736ff79707
commit faf0afee8c

@ -1,4 +1,4 @@
# **Aruppi API** (v4.1.8) # **Aruppi API** (v4.2.0)
> This API has everything about Japan, from anime, music, radio, images, videos ... to japanese culture > This API has everything about Japan, from anime, music, radio, images, videos ... to japanese culture
> >

@ -1,6 +1,6 @@
{ {
"name": "aruppi", "name": "aruppi",
"version": "4.1.9", "version": "4.2.0",
"description": "Aruppi is a custom API to obtain data from the Japanese culture for the mobile app", "description": "Aruppi is a custom API to obtain data from the Japanese culture for the mobile app",
"main": "./src/api/api.ts", "main": "./src/api/api.ts",
"scripts": { "scripts": {

@ -229,6 +229,7 @@ export default class AnimeController {
data = await requestGot(`${urls.BASE_ANIMEFLV}api/animes/list`, { data = await requestGot(`${urls.BASE_ANIMEFLV}api/animes/list`, {
parse: true, parse: true,
scrapy: false, scrapy: false,
spoof: true,
}); });
} catch (err) { } catch (err) {
return next(err); return next(err);

@ -234,7 +234,7 @@ export default class UtilsController {
`${urls.BASE_QWANT}t=images&q=${encodeURIComponent( `${urls.BASE_QWANT}t=images&q=${encodeURIComponent(
title, title,
)}&count=51&locale=es_ES&safesearch=1`, )}&count=51&locale=es_ES&safesearch=1`,
{ scrapy: false, parse: true }, { scrapy: false, parse: true, spoof: true, },
); );
} catch (err) { } catch (err) {
return next(err); return next(err);
@ -637,6 +637,7 @@ export default class UtilsController {
data = await requestGot(`${urls.BASE_THEMEMOE}roulette`, { data = await requestGot(`${urls.BASE_THEMEMOE}roulette`, {
parse: true, parse: true,
scrapy: false, scrapy: false,
spoof: true,
}); });
} catch (err) { } catch (err) {
return next(err); return next(err);

@ -285,6 +285,7 @@ async function redditocall(href: string) {
const resp = await requestGot(urls.REDDIT_ANIMETHEMES + href + '.json', { const resp = await requestGot(urls.REDDIT_ANIMETHEMES + href + '.json', {
parse: true, parse: true,
scrapy: false, scrapy: false,
spoof: true,
}); });
return cheerio.load(getHTML(resp.data.content_html)); return cheerio.load(getHTML(resp.data.content_html));

@ -1,28 +1,52 @@
import got from 'got'; import got from 'got';
import cheerio from 'cheerio'; import cheerio from 'cheerio';
import { CookieJar } from 'tough-cookie'; import { CookieJar } from 'tough-cookie';
// @ts-ignore
import * as got_pjson from 'got/package.json'
const pjson = require('../../package.json');
const cookieJar = new CookieJar(); const cookieJar = new CookieJar();
const aruppi_options: any = {
cookieJar,
'headers': {
'user-agent': `Aruppi-API/${pjson.version} ${got_pjson.name}/${got_pjson.version}`,
'x-client': 'aruppi-api'
},
};
interface Options { interface Options {
scrapy: boolean; scrapy?: boolean,
parse: boolean; parse?: boolean,
spoof?: boolean
} }
export const requestGot = async ( export const requestGot = async (
url: string, url: string,
options?: Options, options?: Options,
): Promise<any> => { ): Promise<any> => {
if (options !== undefined) { const got_options: any = {...got.defaults.options, ...aruppi_options}
if (options.scrapy) { if (options) {
const response = await got(url, { cookieJar }); if (options.spoof != null) {
return await cheerio.load(response.body); got_options.headers["user-agent"] = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/69.0";
} delete got_options.headers['x-client'];
if (!options.spoof)
got_options.headers['user-agent'] = got.defaults.options.headers['user-agent'];
} else if (process.env.ALPI_KEY && (new URL(url)).hostname.match(/\.jeluchu\.xyz$/)) {
got_options.headers['x-aruppi-key'] = process.env.ALPI_KEY;
}
if (options.scrapy) {
const response = await got(url, got_options);
return cheerio.load(response.body);
}
if (options.parse) { if (options.parse) {
return await got(url, { cookieJar }).json(); got_options.responseType = 'json';
const response = await got(url, got_options);
return response.body;
}
} }
} else { const response = await got.get(url, got_options);
return await got.get(url, { cookieJar }); return response;
}
}; };

@ -8,8 +8,7 @@ export default {
BASE_YOUTUBE: 'https://aruppi.jeluchu.xyz/api/Youtube/?channelId=', BASE_YOUTUBE: 'https://aruppi.jeluchu.xyz/api/Youtube/?channelId=',
BASE_YOUTUBE_PLAYLIST: 'https://aruppi.jeluchu.xyz/api/Youtube/playlist/?playlistId=', BASE_YOUTUBE_PLAYLIST: 'https://aruppi.jeluchu.xyz/api/Youtube/playlist/?playlistId=',
BASE_JIKAN: 'https://aruppi.jeluchu.xyz/apis/jikan/v3/', BASE_JIKAN: 'https://aruppi.jeluchu.xyz/apis/jikan/v3/',
BASE_IVOOX: BASE_IVOOX: 'https://www.ivoox.com/podcast-anitakume_fg_f1660716_filtro_1.xml',
'https://www.ivoox.com/podcast-anitakume_fg_f1660716_filtro_1.xml',
BASE_KUDASAI: 'https://somoskudasai.com/feed/', BASE_KUDASAI: 'https://somoskudasai.com/feed/',
BASE_RAMENPARADOS: 'https://ramenparados.com/category/noticias/anime/feed/', BASE_RAMENPARADOS: 'https://ramenparados.com/category/noticias/anime/feed/',
BASE_CRUNCHYROLL: 'https://www.crunchyroll.com/newsrss?lang=esES', BASE_CRUNCHYROLL: 'https://www.crunchyroll.com/newsrss?lang=esES',

@ -280,6 +280,7 @@ export const getRelatedAnimesMAL = async (mal_id: number) => {
$ = await requestGot(`https://myanimelist.net/anime/${mal_id}`, { $ = await requestGot(`https://myanimelist.net/anime/${mal_id}`, {
parse: false, parse: false,
scrapy: true, scrapy: true,
spoof: true,
}); });
} catch (err) { } catch (err) {
return err; return err;
@ -606,6 +607,7 @@ export const tioanimeInfo = async (id: string | undefined, mal_id: number) => {
$ = await requestGot(`${urls.BASE_TIOANIME}anime/${id}`, { $ = await requestGot(`${urls.BASE_TIOANIME}anime/${id}`, {
scrapy: true, scrapy: true,
parse: false, parse: false,
spoof: true,
}); });
/* Extra info of the anime */ /* Extra info of the anime */
@ -785,6 +787,7 @@ export const videoServersTioAnime = async (id: string) => {
$ = await requestGot(`${urls.BASE_TIOANIME}${id}`, { $ = await requestGot(`${urls.BASE_TIOANIME}${id}`, {
scrapy: true, scrapy: true,
parse: false, parse: false,
spoof: true,
}); });
} catch (err) { } catch (err) {
return err; return err;
@ -941,7 +944,7 @@ async function desuServerUrl(url: string) {
} }
} }
$ = await requestGot(url, {scrapy: true, parse: false}); $ = await requestGot(url, {scrapy: true, parse: false, spoof: true});
} catch (err) { } catch (err) {
return err; return err;
} }
@ -1033,7 +1036,7 @@ export function getThemes(themes: any[]) {
} }
export const imageUrlToBase64 = async (url: string) => { export const imageUrlToBase64 = async (url: string) => {
let img: any = await requestGot(url); let img: any = await requestGot(url,{spoof:false});
return img.rawBody.toString('base64'); return img.rawBody.toString('base64');
}; };

Loading…
Cancel
Save