Files
Showy/backend/services/tmdbService.js
T

68 lines
1.7 KiB
JavaScript

const axios = require('axios');
const tmdb_apiKey = "5323ef3dc430df54dcb9e58c37fd22bb";
async function fetchEntryData(tmdb_id, is_tvserie) {
// fetching the informations
try {
let type = is_tvserie ? "tv" : "movie";
let url = `http://api.themoviedb.org/3/${type}/${tmdb_id}?api_key=${tmdb_apiKey}&language=en-US`
let data;
await axios.get(url)
.then((response) => {
if (response.status != 200) return console.log('Error fetching the data.');
data = response.data;
})
return data;
} catch (error) {
console.log('Error fetching the entry data.', error)
return null;
}
}
async function fetchSeasonData(tmdbTvId, seasonNumber) {
// fetching the informations
try {
let url = `http://api.themoviedb.org/3/tv/${tmdbTvId}/season/${seasonNumber}?api_key=${tmdb_apiKey}&language=en-US`
let data;
await axios.get(url)
.then((response) => {
if (response.status != 200) return console.log('Error fetching the data.');
data = response.data;
})
return data;
} catch (error) {
console.log('Error fetching the data.')
return null;
}
}
async function fetchEntryMedia(tmdb_id, is_tvserie) {
try {
let type = is_tvserie ? "tv" : "movie";
let url = `http://api.themoviedb.org/3/${type}/${tmdb_id}/images?api_key=${tmdb_apiKey}`
let data;
await axios.get(url)
.then((response) => {
if (response.status != 200) return console.log('Error fetching entry media.');
data = response.data;
})
return data;
} catch (error) {
console.log('Error fetching the entry media.', error)
return null;
}
}
module.exports = {
fetchEntryData,
fetchSeasonData,
fetchEntryMedia,
}