diff --git a/package-lock.json b/package-lock.json index 2bab9bd..b9e554e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "aruppi", - "version": "1.0.0", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 28c4ca9..8eccbd9 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/api/api.js b/src/api/api.js index 3e886ef..bef79ff 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -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 }; diff --git a/src/api/index.js b/src/api/index.js index 31dc71d..0ed2f4f 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -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; \ No newline at end of file +module.exports = router; diff --git a/src/api/routes/index.js b/src/api/routes/index.js index c4061d1..c5481bc 100644 --- a/src/api/routes/index.js +++ b/src/api/routes/index.js @@ -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; diff --git a/src/api/urls.js b/src/api/urls.js index 2fac886..4068092 100644 --- a/src/api/urls.js +++ b/src/api/urls.js @@ -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/' }; diff --git a/src/index.js b/src/index.js index 50d9575..96f95b7 100644 --- a/src/index.js +++ b/src/index.js @@ -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 */ -}); \ No newline at end of file +}); diff --git a/src/utils/index.js b/src/utils/index.js index d23aaf0..e16b77d 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -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 }