Back: tmdb service: add fetch collection
This commit is contained in:
1 parent
f683e7d00e
commit
9b8ff730c3
1 file changed
+38
-4
@@ -1,15 +1,19 @@
|
||||
const axios = require('axios');
|
||||
const { logToFile } = require('./logService');
|
||||
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`
|
||||
logToFile(`Fetching Entry Data From: ${url}`)
|
||||
let data;
|
||||
await axios.get(url)
|
||||
.then((response) => {
|
||||
if (response.status != 200) return console.log('Error fetching the data.');
|
||||
if (response.status != 200) {
|
||||
logToFile(`Error Fetching Data From: ${url}`)
|
||||
return console.log('Error fetching the data.')
|
||||
};
|
||||
data = response.data;
|
||||
})
|
||||
|
||||
@@ -25,10 +29,14 @@ 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`
|
||||
logToFile(`Fetching Season Data From: ${url}`)
|
||||
let data;
|
||||
await axios.get(url)
|
||||
.then((response) => {
|
||||
if (response.status != 200) return console.log('Error fetching the data.');
|
||||
if (response.status != 200) {
|
||||
logToFile(`Error Fetching Data From: ${url}`)
|
||||
return console.log('Error fetching the data.')
|
||||
};
|
||||
data = response.data;
|
||||
})
|
||||
|
||||
@@ -43,10 +51,14 @@ 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}`
|
||||
logToFile(`Fetching Entry Media Data From: ${url}`)
|
||||
let data;
|
||||
await axios.get(url)
|
||||
.then((response) => {
|
||||
if (response.status != 200) return console.log('Error fetching entry media.');
|
||||
if (response.status != 200) {
|
||||
logToFile(`Error Fetching Data From: ${url}`)
|
||||
return console.log('Error fetching the data.')
|
||||
};
|
||||
data = response.data;
|
||||
})
|
||||
|
||||
@@ -57,10 +69,32 @@ async function fetchEntryMedia(tmdb_id, is_tvserie) {
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchCollectionData(collectionId) {
|
||||
try {
|
||||
let url = `http://api.themoviedb.org/3/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,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user