Add Artists and Fix News Images

pull/1/head
Jéluchu 5 years ago
parent 83ee21bb57
commit 0b532a1855

@ -376,6 +376,38 @@ const getRandomTheme = async () => {
};
const getArtist = async (id) => {
let data
let body
let promises = []
if (id === undefined) {
data = await cloudscraper.get(`${BASE_THEMEMOE}artists`);
body = JSON.parse(data);
body.map(doc => {
promises.push({
id: doc.artistID,
name: doc.artistName
})
});
return promises;
} else {
data = await cloudscraper.get(`${BASE_THEMEMOE}artists/${id}`);
body = JSON.parse(data);
return await structureThemes(body, false, 1)
}
};
module.exports = {
schedule,
top,
@ -393,5 +425,6 @@ module.exports = {
getRadioStations,
getOpAndEd,
getThemesSeason,
getRandomTheme
getRandomTheme,
getArtist
};

@ -30,7 +30,8 @@ router.get('/', (req, res) => {
'Radios': '/api/v2/radio',
'Themes': '/api/v2/themes/:title',
'Season Themes': '/api/v2/themeSeason/:year/:season?',
'Random Theme': '/api/v2/randomTheme'
'Random Theme': '/api/v2/randomTheme',
'Artists Theme': '/api/v2/artists/:id?'
}
]
});

@ -311,4 +311,19 @@ router.get('/randomTheme', (req, res) =>{
});
router.get('/artists/:id?', (req, res) =>{
let id = req.params.id;
api.getArtist(id)
.then(artists =>{
res.status(200).json({
artists
});
}).catch((err) =>{
console.error(err);
});
});
module.exports = router;

@ -317,7 +317,7 @@ const obtainPreviewNews = (encoded) => {
.replace("httpss", "https")
} else if (encoded.includes('<img')) {
image = encoded.split("src=")[1].split(" class=")[0].replace("\"", "")
image = encoded.split("src=")[1].split(" class=")[0].replace("\"", '').replace('\"','')
} else if (encoded.includes('https://www.youtube.com/embed/')) {
let getSecondThumb = encoded.split('https://www.youtube.com/embed/')[1].split('?feature')[0]
image = `https://img.youtube.com/vi/${getSecondThumb}/0.jpg`
@ -363,7 +363,19 @@ const structureThemes = async (body, indv, task) => {
});
}
} else if (task === 1) {
respFinal = body
themes = await getHeaderTheme(respFinal.themes)
promises.push({
title: respFinal.artistName,
season: respFinal.season,
year: respFinal.year,
series: themes,
});
} else {
respFinal = body
themes = await getThemes(respFinal.themes)
@ -376,7 +388,27 @@ const structureThemes = async (body, indv, task) => {
}
return promises;
};
const getHeaderTheme = async (series) => {
let promises = []
let data
for(let i = 0; i <= series.length -1; i++) {
data = await getThemes(series[i].themes)
promises.push({
title: series[i].name,
season: series[i].season,
year: series[i].year,
themes: data,
});
}
return promises;

Loading…
Cancel
Save