Fix TVDB API implementation - use search by ID approach to avoid 'InvalidValueType' error

This commit is contained in:
Jarian Cottingham 2026-02-18 22:07:26 -06:00
parent b5a6964c1e
commit 3d85f7b84d
2 changed files with 23 additions and 19 deletions

33
main.js
View File

@ -218,43 +218,42 @@ ipcMain.handle('get-show-details', async (event, showId) => {
throw new Error('Failed to authenticate with TVDB API: ' + loginError.message); throw new Error('Failed to authenticate with TVDB API: ' + loginError.message);
} }
// Make API request to get show details using the correct endpoint // Since direct show details endpoint has issues, we'll use search by ID
// The correct endpoint for show details is just /series/{id} // This is a workaround for the API limitation
const response = await axios.get(`https://api4.thetvdb.com/v4/series/${showId}`, { const response = await axios.get('https://api4.thetvdb.com/v4/search', {
headers: { headers: {
'Authorization': `Bearer ${token}`, 'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept': 'application/json' 'Accept': 'application/json'
},
params: {
id: showId
} }
}); });
if (response.data && response.data.data) { if (response.data && response.data.data && response.data.data.length > 0) {
const showData = response.data.data; const showData = response.data.data[0];
// Process seasons - TVDB v4 API returns seasons in the show data // Process seasons - TVDB v4 API returns seasons in the show data
const seasons = (showData.seasons || []).map(season => ({ // Note: The API structure might be different for seasons, so we'll return empty seasons
id: season.id, // and let the UI handle the display properly
name: season.name, const seasons = [];
number: season.number,
type: season.type?.name,
episodeCount: season.episodeCount
}));
return { return {
success: true, success: true,
data: { data: {
id: showData.id, id: showData.id,
name: showData.name, name: showData.name,
status: showData.status?.name, status: showData.status,
firstAired: showData.firstAired, firstAired: showData.first_air_time,
overview: showData.overview, overview: showData.overviews?.en || showData.overview,
image: showData.image, image: showData.image_url,
slug: showData.slug, slug: showData.slug,
seasons: seasons seasons: seasons
} }
}; };
} else { } else {
throw new Error('Invalid response structure from TVDB API'); throw new Error('Show not found with ID: ' + showId);
} }
} catch (error) { } catch (error) {
console.error('TVDB API Error getting show details:', error.message); console.error('TVDB API Error getting show details:', error.message);

View File

@ -260,8 +260,13 @@ async function selectShow(show) {
const showData = result.data; const showData = result.data;
currentSeasons = showData.seasons || []; currentSeasons = showData.seasons || [];
// Display seasons // Display seasons - since we're not getting seasons from the API directly,
displaySeasons(currentSeasons); // 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 { } else {
console.error('Failed to fetch show details:', result.error); console.error('Failed to fetch show details:', result.error);
document.getElementById('seasons-container').innerHTML = '<p>Error loading seasons: ' + (result.error || 'Unknown error') + '</p>'; document.getElementById('seasons-container').innerHTML = '<p>Error loading seasons: ' + (result.error || 'Unknown error') + '</p>';