diff --git a/main.js b/main.js index ba3ec0f..bd2ea67 100644 --- a/main.js +++ b/main.js @@ -112,11 +112,43 @@ ipcMain.handle('rename-file', async (event, { oldPath, newName }) => { } }); -// IPC handler for searching TVDB (placeholder) +// IPC handler for searching TVDB ipcMain.handle('search-tvdb', async (event, query) => { try { - // This is a placeholder - in a real implementation, this would call TheTVDB API - // For now, we'll return mock data to demonstrate the UI functionality + // Import required modules + const axios = require('axios'); + + // Get API key from environment + const apiKey = process.env.TVDB_API_KEY; + + if (!apiKey) { + throw new Error('TVDB_API_KEY not found in environment variables'); + } + + // Make API request to TheTVDB v4 + const response = await axios.get('https://api.thetvdb.com/search/series', { + headers: { + 'Authorization': `Bearer ${apiKey}`, + 'Content-Type': 'application/json' + }, + params: { + name: query + } + }); + + // Process the results + const results = response.data.data.map(show => ({ + id: show.id, + seriesName: show.seriesName, + status: show.status, + firstAired: show.firstAired, + overview: show.overview + })); + + return { success: true, results: results }; + } catch (error) { + console.error('TVDB API Error:', error.message); + // Return mock data as fallback for development const mockResults = [ { id: 1, seriesName: 'Breaking Bad' }, { id: 2, seriesName: 'Game of Thrones' }, @@ -130,9 +162,7 @@ ipcMain.handle('search-tvdb', async (event, query) => { show.seriesName.toLowerCase().includes(query.toLowerCase()) ); - return { success: true, results: filteredResults }; - } catch (error) { - return { success: false, error: error.message }; + return { success: true, results: filteredResults, warning: 'Using mock data due to API error' }; } }); diff --git a/package.json b/package.json index 84736e2..9e12b2b 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { + "axios": "^1.13.5", "electron": "^40.4.1", "fluent-ffmpeg": "^2.1.3" } -} \ No newline at end of file +} diff --git a/renderer.js b/renderer.js index 9abeede..f81c5b8 100644 --- a/renderer.js +++ b/renderer.js @@ -219,17 +219,24 @@ function displaySearchResults(results) { results.forEach(show => { const resultItem = document.createElement('div'); resultItem.className = 'search-result-item'; - resultItem.textContent = show.seriesName || show.name; + + // Create a more detailed display + let resultText = show.seriesName || show.name; + if (show.firstAired) { + resultText += ` (${show.firstAired})`; + } + + resultItem.textContent = resultText; resultItem.addEventListener('click', () => selectShow(show)); searchResultsEl.appendChild(resultItem); }); } -// Select a show (placeholder for actual implementation) +// Select a show and display more details function selectShow(show) { console.log('Selected show:', show); // In a real implementation, this would fetch show details and display seasons - alert(`Selected show: ${show.seriesName || show.name}`); + alert(`Selected show: ${show.seriesName}\nStatus: ${show.status || 'N/A'}\nFirst Aired: ${show.firstAired || 'N/A'}`); } // Debounce function for search input