Simplified and fixed TVDB API show details implementation - removed problematic fallback code

This commit is contained in:
Jarian Cottingham 2026-02-18 22:01:51 -06:00
parent 093a455bcf
commit e0a350b65f

41
main.js
View File

@ -198,6 +198,7 @@ ipcMain.handle('get-show-details', async (event, showId) => {
}
// For TVDB v4 API, we need to first get an authentication token
// The token is valid for 1 month
let token = null;
// Try to get token from cache or login
@ -217,9 +218,9 @@ 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
// Let's try a different approach - first get the show by ID using the slug or direct ID approach
const response = await axios.get(`https://api4.thetvdb.com/v4/series/${showId}?apikey=${apiKey}`, {
// 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}`, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
@ -260,39 +261,7 @@ ipcMain.handle('get-show-details', async (event, showId) => {
console.error('Error status:', error.response?.status);
console.error('Error data:', error.response?.data);
// Try a fallback approach - get the show using search by ID
try {
const searchResponse = await axios.get(`https://api4.thetvdb.com/v4/search`, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
},
params: {
id: showId
}
});
if (searchResponse.data && searchResponse.data.data && searchResponse.data.data.length > 0) {
const showData = searchResponse.data.data[0];
return {
success: true,
data: {
id: showData.id,
name: showData.name,
status: showData.status?.name,
firstAired: showData.firstAired,
overview: showData.overview,
image: showData.image,
slug: showData.slug,
seasons: [] // We'll need to fetch seasons separately if this approach works
}
};
}
} catch (fallbackError) {
console.error('Fallback approach also failed:', fallbackError.message);
}
// Return the error without trying fallbacks that cause scope issues
return { success: false, error: 'Failed to fetch show details from TVDB API: ' + error.message };
}
});