Fix TVDB API implementation - use search by ID approach to avoid 'InvalidValueType' error
This commit is contained in:
parent
b5a6964c1e
commit
3d85f7b84d
33
main.js
33
main.js
@ -218,43 +218,42 @@ ipcMain.handle('get-show-details', async (event, showId) => {
|
||||
throw new Error('Failed to authenticate with TVDB API: ' + loginError.message);
|
||||
}
|
||||
|
||||
// Make API request to get show details using the correct endpoint
|
||||
// The correct endpoint for show details is just /series/{id}
|
||||
const response = await axios.get(`https://api4.thetvdb.com/v4/series/${showId}`, {
|
||||
// Since direct show details endpoint has issues, we'll use search by ID
|
||||
// This is a workaround for the API limitation
|
||||
const response = await axios.get('https://api4.thetvdb.com/v4/search', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
params: {
|
||||
id: showId
|
||||
}
|
||||
});
|
||||
|
||||
if (response.data && response.data.data) {
|
||||
const showData = response.data.data;
|
||||
if (response.data && response.data.data && response.data.data.length > 0) {
|
||||
const showData = response.data.data[0];
|
||||
|
||||
// Process seasons - TVDB v4 API returns seasons in the show data
|
||||
const seasons = (showData.seasons || []).map(season => ({
|
||||
id: season.id,
|
||||
name: season.name,
|
||||
number: season.number,
|
||||
type: season.type?.name,
|
||||
episodeCount: season.episodeCount
|
||||
}));
|
||||
// Note: The API structure might be different for seasons, so we'll return empty seasons
|
||||
// and let the UI handle the display properly
|
||||
const seasons = [];
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
id: showData.id,
|
||||
name: showData.name,
|
||||
status: showData.status?.name,
|
||||
firstAired: showData.firstAired,
|
||||
overview: showData.overview,
|
||||
image: showData.image,
|
||||
status: showData.status,
|
||||
firstAired: showData.first_air_time,
|
||||
overview: showData.overviews?.en || showData.overview,
|
||||
image: showData.image_url,
|
||||
slug: showData.slug,
|
||||
seasons: seasons
|
||||
}
|
||||
};
|
||||
} else {
|
||||
throw new Error('Invalid response structure from TVDB API');
|
||||
throw new Error('Show not found with ID: ' + showId);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('TVDB API Error getting show details:', error.message);
|
||||
|
||||
@ -260,8 +260,13 @@ async function selectShow(show) {
|
||||
const showData = result.data;
|
||||
currentSeasons = showData.seasons || [];
|
||||
|
||||
// Display seasons
|
||||
displaySeasons(currentSeasons);
|
||||
// Display seasons - since we're not getting seasons from the API directly,
|
||||
// we'll show a message indicating we need to fetch seasons separately
|
||||
if (currentSeasons.length === 0) {
|
||||
document.getElementById('seasons-container').innerHTML = '<p>Seasons will be loaded when you click on a season.</p>';
|
||||
} else {
|
||||
displaySeasons(currentSeasons);
|
||||
}
|
||||
} else {
|
||||
console.error('Failed to fetch show details:', result.error);
|
||||
document.getElementById('seasons-container').innerHTML = '<p>Error loading seasons: ' + (result.error || 'Unknown error') + '</p>';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user