mirror of https://github.com/aruppi/aruppi-api
Added Themes
This commit is contained in:
parent
e4697302d8
commit
2f6c29d2a0
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "aruppi",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "aruppi",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"description": "Aruppi is a custom API to obtain data from the Japanese culture for the mobile app",
|
||||
"main": "./src/api/api.js",
|
||||
"scripts": {
|
||||
|
@ -49,8 +49,6 @@
|
|||
"express": "^4.16.4",
|
||||
"helmet": "^3.22.0",
|
||||
"node-base64-image": "^2.0.1",
|
||||
"npm": "^6.14.5",
|
||||
"request": "^2.88.0",
|
||||
"rss-to-json": "^1.1.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,12 @@ const {
|
|||
animeExtraInfo,
|
||||
searchAnime,
|
||||
transformUrlServer,
|
||||
obtainPreviewNews
|
||||
obtainPreviewNews,
|
||||
structureThemes
|
||||
} = require('../utils/index');
|
||||
|
||||
const {
|
||||
BASE_ANIMEFLV, BASE_ANIMEFLV_JELU, BASE_JIKAN, BASE_IVOOX, BASE_QWANT, BASE_YOUTUBE
|
||||
BASE_ANIMEFLV, BASE_ANIMEFLV_JELU, BASE_JIKAN, BASE_IVOOX, BASE_QWANT, BASE_YOUTUBE, BASE_THEMEMOE
|
||||
} = require('./urls');
|
||||
|
||||
const schedule = async (day) =>{
|
||||
|
@ -342,6 +343,39 @@ const getRadioStations = async () => {
|
|||
return require('../assets/radiostations.json');
|
||||
}
|
||||
|
||||
const getOpAndEd = async (title) => {
|
||||
|
||||
const data = await cloudscraper.get(`${BASE_THEMEMOE}anime/search/${title}`);
|
||||
const body = JSON.parse(data);
|
||||
|
||||
return await structureThemes(body, true, 0)
|
||||
|
||||
};
|
||||
|
||||
const getThemesSeason = async (year, season) => {
|
||||
|
||||
let data
|
||||
|
||||
if (season === undefined) {
|
||||
data = await cloudscraper.get(`${BASE_THEMEMOE}seasons/${year}`);
|
||||
} else {
|
||||
data = await cloudscraper.get(`${BASE_THEMEMOE}seasons/${year}/${season}`);
|
||||
}
|
||||
const body = JSON.parse(data);
|
||||
|
||||
return await structureThemes(body, false, 0)
|
||||
|
||||
};
|
||||
|
||||
const getRandomTheme = async () => {
|
||||
|
||||
const data = await cloudscraper.get(`${BASE_THEMEMOE}roulette`);
|
||||
const body = JSON.parse(data);
|
||||
|
||||
return await structureThemes(body, true)
|
||||
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
schedule,
|
||||
top,
|
||||
|
@ -356,5 +390,8 @@ module.exports = {
|
|||
search,
|
||||
getImages,
|
||||
getYoutubeVideos,
|
||||
getRadioStations
|
||||
getRadioStations,
|
||||
getOpAndEd,
|
||||
getThemesSeason,
|
||||
getRandomTheme
|
||||
};
|
||||
|
|
|
@ -27,7 +27,10 @@ router.get('/', (req, res) => {
|
|||
'Search': '/api/v2/search/:title',
|
||||
'Images': '/api/v2/images/:query',
|
||||
'Videos': '/api/v2/videos/:channelId',
|
||||
'Radios': '/api/v2/radio'
|
||||
'Radios': '/api/v2/radio',
|
||||
'Themes': '/api/v2/themes/:title',
|
||||
'Season Themes': '/api/v2/themeSeason/:year/:season?',
|
||||
'Random Theme': '/api/v2/randomTheme'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
@ -35,4 +38,4 @@ router.get('/', (req, res) => {
|
|||
|
||||
router.use('/', routes);
|
||||
|
||||
module.exports = router;
|
||||
module.exports = router;
|
||||
|
|
|
@ -267,4 +267,48 @@ router.get('/radio' , (req, res) =>{
|
|||
|
||||
});
|
||||
|
||||
router.get('/themes/:title' , (req, res) =>{
|
||||
|
||||
let title = req.params.title;
|
||||
|
||||
api.getOpAndEd(title)
|
||||
.then(themes =>{
|
||||
res.status(200).json({
|
||||
themes
|
||||
});
|
||||
}).catch((err) =>{
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
router.get('/themeSeason/:year/:season?', (req, res) =>{
|
||||
|
||||
let year = req.params.year;
|
||||
let season = req.params.season
|
||||
|
||||
api.getThemesSeason(year, season)
|
||||
.then(themes =>{
|
||||
res.status(200).json({
|
||||
themes
|
||||
});
|
||||
}).catch((err) =>{
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
router.get('/randomTheme', (req, res) =>{
|
||||
|
||||
api.getRandomTheme()
|
||||
.then(random =>{
|
||||
res.status(200).json({
|
||||
random
|
||||
});
|
||||
}).catch((err) =>{
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
@ -11,5 +11,6 @@ module.exports = {
|
|||
BASE_CRUNCHYROLL: 'https://www.crunchyroll.com/newsrss?lang=esES',
|
||||
SEARCH_URL: 'https://animeflv.net/browse?q=',
|
||||
BASE_EPISODE_IMG_URL: 'https://cdn.animeflv.net/screenshots/',
|
||||
BASE_QWANT: 'https://api.qwant.com/search/images?'
|
||||
BASE_QWANT: 'https://api.qwant.com/search/images?',
|
||||
BASE_THEMEMOE: 'https://themes.moe/api/'
|
||||
};
|
||||
|
|
|
@ -3,6 +3,6 @@ const port = process.env.PORT || 5000;
|
|||
|
||||
app.listen(port, () => {
|
||||
/* eslint-disable no-console */
|
||||
console.log(`\n🚀 ... Listening: http://localhost:${port}`);
|
||||
console.log(`\n🚀 ... Listening: http://localhost:${port}/api/v2`);
|
||||
/* eslint-enable no-console */
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@ const cheerio = require('cheerio');
|
|||
const base64 = require('node-base64-image');
|
||||
|
||||
const {
|
||||
BASE_ANIMEFLV, BASE_JIKAN, BASE_EPISODE_IMG_URL, SEARCH_URL, BASE_ARUPPI
|
||||
BASE_ANIMEFLV, BASE_JIKAN, BASE_EPISODE_IMG_URL, SEARCH_URL, BASE_ARUPPI, BASE_THEMEMOE
|
||||
} = require('../api/urls');
|
||||
|
||||
const animeflvInfo = async (id, index) =>{
|
||||
|
@ -334,6 +334,72 @@ const obtainPreviewNews = (encoded) => {
|
|||
return image;
|
||||
}
|
||||
|
||||
const structureThemes = async (body, indv, task) => {
|
||||
|
||||
const promises = []
|
||||
let themes
|
||||
let respFinal
|
||||
|
||||
if (task === 0) {
|
||||
for(let i = 0; i <= body.length -1; i++) {
|
||||
|
||||
if (indv === true) {
|
||||
const data = await cloudscraper.get(`${BASE_THEMEMOE}themes/${body[i]}`);
|
||||
respFinal = JSON.parse(data)
|
||||
themes = await getThemes(respFinal[0].themes)
|
||||
} else {
|
||||
respFinal = body
|
||||
themes = await getThemes(body[0].themes)
|
||||
}
|
||||
|
||||
respFinal.map(doc => {
|
||||
|
||||
promises.push({
|
||||
title: doc.name,
|
||||
season: doc.season,
|
||||
year: doc.year,
|
||||
themes: themes,
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
} else {
|
||||
respFinal = body
|
||||
themes = await getThemes(respFinal.themes)
|
||||
|
||||
promises.push({
|
||||
title: respFinal.name,
|
||||
season: respFinal.season,
|
||||
year: respFinal.year,
|
||||
themes: themes,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return promises;
|
||||
|
||||
};
|
||||
|
||||
const getThemes = async (themes) => {
|
||||
|
||||
let promises = []
|
||||
|
||||
themes.map(doc => {
|
||||
|
||||
promises.push({
|
||||
name: doc.themeName,
|
||||
type: doc.themeType,
|
||||
video: doc.mirror.mirrorURL
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
return promises;
|
||||
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
animeflvInfo,
|
||||
getAnimeCharacters,
|
||||
|
@ -342,5 +408,7 @@ module.exports = {
|
|||
imageUrlToBase64,
|
||||
searchAnime,
|
||||
transformUrlServer,
|
||||
obtainPreviewNews
|
||||
obtainPreviewNews,
|
||||
structureThemes,
|
||||
getThemes
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue