B: Added tmdb fetch function for entry credits and people details

This commit is contained in:
X4Lo committed 2025-07-11 15:13:58 +01:00
1 parent ef9e1911f9
commit 032d92994d
1 file changed
+58
+58
View File
@@ -93,11 +93,69 @@ async function fetchCollectionData(collectionId) {
} }
} }
/**
* Fetches credits (cast and crew) for a movie or TV show
* @param {number} tmdb_id - The TMDB ID of the movie or TV show
* @param {boolean} is_tvserie - Whether the entry is a TV series or not
* @returns {Promise<Object|null>} - The credits data or null if there's an error
*/
async function fetchEntryCredits(tmdb_id, is_tvserie) {
try {
let type = is_tvserie ? "tv" : "movie";
let url = `${TMDB_APIURL}${type}/${tmdb_id}/credits?api_key=${TMDB_APIKEY}&language=en-US`;
logToFile(`Fetching Entry Credits From: ${url}`);
let data;
await axios.get(url)
.then((response) => {
if (response.status != 200) {
logToFile(`Error Fetching Credits From: ${url}`);
return console.log('Error fetching the credits data.');
};
data = response.data;
});
return data;
} catch (error) {
console.log('Error fetching the entry credits.', error);
return null;
}
}
/**
* Fetches detailed information about a person
* @param {number} person_id - The TMDB ID of the person
* @returns {Promise<Object|null>} - The person data or null if there's an error
*/
async function fetchPersonDetails(person_id) {
try {
let url = `${TMDB_APIURL}person/${person_id}?api_key=${TMDB_APIKEY}&language=en-US&append_to_response=external_ids`;
logToFile(`Fetching Person Details From: ${url}`);
let data;
await axios.get(url)
.then((response) => {
if (response.status != 200) {
logToFile(`Error Fetching Person Details From: ${url}`);
return console.log('Error fetching the person data.');
};
data = response.data;
});
return data;
} catch (error) {
console.log('Error fetching the person details.', error);
return null;
}
}
module.exports = { module.exports = {
fetchEntryData, fetchEntryData,
fetchSeasonData, fetchSeasonData,
fetchEntryMedia, fetchEntryMedia,
fetchCollectionData, fetchCollectionData,
fetchEntryCredits,
fetchPersonDetails,
} }