105 lines
2.8 KiB
JavaScript
105 lines
2.8 KiB
JavaScript
const axios = require('axios');
|
|
const { logToFile } = require('./logService');
|
|
const configService = require('./configService');
|
|
|
|
const TMDB_APIURL = configService.getTmdbApiUrl();
|
|
const TMDB_APIKEY = configService.getTmdbApiKey();
|
|
|
|
async function fetchEntryData(tmdb_id, is_tvserie) {
|
|
try {
|
|
let type = is_tvserie ? "tv" : "movie";
|
|
let url = `${TMDB_APIURL}${type}/${tmdb_id}?api_key=${TMDB_APIKEY}&language=en-US`
|
|
logToFile(`Fetching Entry Data From: ${url}`)
|
|
let data;
|
|
await axios.get(url)
|
|
.then((response) => {
|
|
if (response.status != 200) {
|
|
logToFile(`Error Fetching Data From: ${url}`)
|
|
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 = `${TMDB_APIURL}tv/${tmdbTvId}/season/${seasonNumber}?api_key=${TMDB_APIKEY}&language=en-US`
|
|
logToFile(`Fetching Season Data From: ${url}`)
|
|
let data;
|
|
await axios.get(url)
|
|
.then((response) => {
|
|
if (response.status != 200) {
|
|
logToFile(`Error Fetching Data From: ${url}`)
|
|
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 = `${TMDB_APIURL}${type}/${tmdb_id}/images?api_key=${TMDB_APIKEY}`
|
|
logToFile(`Fetching Entry Media Data From: ${url}`)
|
|
let data;
|
|
await axios.get(url)
|
|
.then((response) => {
|
|
if (response.status != 200) {
|
|
logToFile(`Error Fetching Data From: ${url}`)
|
|
return console.log('Error fetching the data.')
|
|
};
|
|
data = response.data;
|
|
})
|
|
|
|
return data;
|
|
} catch (error) {
|
|
console.log('Error fetching the entry media.', error)
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function fetchCollectionData(collectionId) {
|
|
try {
|
|
let url = `${TMDB_APIURL}collection/${collectionId}?api_key=${TMDB_APIKEY}&language=en-US`
|
|
logToFile(`Fetching Collection Data From: ${url}`)
|
|
let data;
|
|
await axios.get(url)
|
|
.then((response) => {
|
|
if (response.status != 200) return console.log('Error fetching collection data from tmdb:', response);
|
|
data = response.data;
|
|
})
|
|
|
|
return data;
|
|
} catch (error) {
|
|
if (response.status != 200) {
|
|
logToFile(`Error Fetching Data From: ${url}`)
|
|
return console.log('Error fetching the data.')
|
|
};
|
|
return null;
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
fetchEntryData,
|
|
fetchSeasonData,
|
|
fetchEntryMedia,
|
|
fetchCollectionData,
|
|
}
|
|
|
|
|
|
|