Simplified and fixed TVDB API show details implementation - removed problematic fallback code
This commit is contained in:
parent
093a455bcf
commit
e0a350b65f
41
main.js
41
main.js
@ -198,6 +198,7 @@ ipcMain.handle('get-show-details', async (event, showId) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For TVDB v4 API, we need to first get an authentication token
|
// For TVDB v4 API, we need to first get an authentication token
|
||||||
|
// The token is valid for 1 month
|
||||||
let token = null;
|
let token = null;
|
||||||
|
|
||||||
// Try to get token from cache or login
|
// 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);
|
throw new Error('Failed to authenticate with TVDB API: ' + loginError.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make API request to get show details
|
// Make API request to get show details using the correct endpoint
|
||||||
// Let's try a different approach - first get the show by ID using the slug or direct ID approach
|
// The correct endpoint for show details is just /series/{id}
|
||||||
const response = await axios.get(`https://api4.thetvdb.com/v4/series/${showId}?apikey=${apiKey}`, {
|
const response = await axios.get(`https://api4.thetvdb.com/v4/series/${showId}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${token}`,
|
'Authorization': `Bearer ${token}`,
|
||||||
'Content-Type': 'application/json',
|
'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 status:', error.response?.status);
|
||||||
console.error('Error data:', error.response?.data);
|
console.error('Error data:', error.response?.data);
|
||||||
|
|
||||||
// Try a fallback approach - get the show using search by ID
|
// Return the error without trying fallbacks that cause scope issues
|
||||||
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 { success: false, error: 'Failed to fetch show details from TVDB API: ' + error.message };
|
return { success: false, error: 'Failed to fetch show details from TVDB API: ' + error.message };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user