From dc8c27dfc4173e17d475c62f73b2155de419f234 Mon Sep 17 00:00:00 2001 From: tapframe Date: Wed, 22 Oct 2025 17:17:20 +0530 Subject: [PATCH] trailer service improvements --- src/components/metadata/HeroSection.tsx | 6 +-- src/components/metadata/TrailersSection.tsx | 32 +----------- src/services/trailerService.ts | 54 ++++++++++++--------- 3 files changed, 37 insertions(+), 55 deletions(-) diff --git a/src/components/metadata/HeroSection.tsx b/src/components/metadata/HeroSection.tsx index 4de55e5e..24ab07c2 100644 --- a/src/components/metadata/HeroSection.tsx +++ b/src/components/metadata/HeroSection.tsx @@ -2140,7 +2140,7 @@ const styles = StyleSheet.create({ }, singleRowLayout: { flexDirection: 'row', - gap: 8, + gap: 4, alignItems: 'center', justifyContent: 'center', width: '100%', @@ -2163,11 +2163,11 @@ const styles = StyleSheet.create({ }, singleRowPlayButtonFullWidth: { flex: 1, - marginHorizontal: 4, + marginHorizontal: 2, }, singleRowSaveButtonFullWidth: { flex: 1, - marginHorizontal: 4, + marginHorizontal: 2, }, primaryActionRow: { flexDirection: 'row', diff --git a/src/components/metadata/TrailersSection.tsx b/src/components/metadata/TrailersSection.tsx index df1edd48..f55359f3 100644 --- a/src/components/metadata/TrailersSection.tsx +++ b/src/components/metadata/TrailersSection.tsx @@ -155,24 +155,6 @@ const TrailersSection: React.FC = memo(({ sectionTranslateYSV.value = withDelay(500, withTiming(0, { duration: 400 })); }, [sectionOpacitySV, sectionTranslateYSV]); - // Check if trailer service backend is available - const checkBackendAvailability = useCallback(async (): Promise => { - try { - const serverStatus = TrailerService.getServerStatus(); - const healthUrl = `${serverStatus.localUrl.replace('/trailer', '/health')}`; - - const response = await fetch(healthUrl, { - method: 'GET', - signal: AbortSignal.timeout(3000), // 3 second timeout - }); - const isAvailable = response.ok; - logger.info('TrailersSection', `Backend availability check: ${isAvailable ? 'AVAILABLE' : 'UNAVAILABLE'}`); - return isAvailable; - } catch (error) { - logger.warn('TrailersSection', 'Backend availability check failed:', error); - return false; - } - }, []); // Fetch trailers from TMDB useEffect(() => { @@ -180,17 +162,7 @@ const TrailersSection: React.FC = memo(({ const initializeTrailers = async () => { resetSectionAnimation(); - // First check if backend is available - const available = await checkBackendAvailability(); - setBackendAvailable(available); - - if (!available) { - logger.warn('TrailersSection', 'Trailer service backend is not available - skipping trailer loading'); - setLoading(false); - return; - } - - // Backend is available, proceed with fetching trailers + setBackendAvailable(true); // Assume available, let TrailerService handle errors await fetchTrailers(); }; @@ -334,7 +306,7 @@ const TrailersSection: React.FC = memo(({ }; initializeTrailers(); - }, [tmdbId, type, checkBackendAvailability]); + }, [tmdbId, type]); // Categorize trailers by type const categorizeTrailers = (videos: any[]): CategorizedTrailers => { diff --git a/src/services/trailerService.ts b/src/services/trailerService.ts index fa4c7366..ad6b4050 100644 --- a/src/services/trailerService.ts +++ b/src/services/trailerService.ts @@ -53,29 +53,31 @@ export class TrailerService { * @returns Promise - The trailer URL or null if not found */ private static async getTrailerFromLocalServer(title: string, year: number, tmdbId?: string, type?: 'movie' | 'tv'): Promise { + const startTime = Date.now(); + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), this.TIMEOUT); + + // Build URL with parameters + const params = new URLSearchParams(); + + // Always send title and year for logging and fallback + params.append('title', title); + params.append('year', year.toString()); + + if (tmdbId) { + params.append('tmdbId', tmdbId); + params.append('type', type || 'movie'); + logger.info('TrailerService', `Using TMDB API for: ${title} (TMDB ID: ${tmdbId})`); + } else { + logger.info('TrailerService', `Auto-searching trailer for: ${title} (${year})`); + } + + const url = `${this.AUTO_SEARCH_URL}?${params.toString()}`; + logger.info('TrailerService', `Local server request URL: ${url}`); + logger.info('TrailerService', `Local server timeout set to ${this.TIMEOUT}ms`); + logger.info('TrailerService', `Making fetch request to: ${url}`); + try { - const startTime = Date.now(); - const controller = new AbortController(); - const timeoutId = setTimeout(() => controller.abort(), this.TIMEOUT); - - // Build URL with parameters - const params = new URLSearchParams(); - - // Always send title and year for logging and fallback - params.append('title', title); - params.append('year', year.toString()); - - if (tmdbId) { - params.append('tmdbId', tmdbId); - params.append('type', type || 'movie'); - logger.info('TrailerService', `Using TMDB API for: ${title} (TMDB ID: ${tmdbId})`); - } else { - logger.info('TrailerService', `Auto-searching trailer for: ${title} (${year})`); - } - - const url = `${this.AUTO_SEARCH_URL}?${params.toString()}`; - logger.info('TrailerService', `Local server request URL: ${url}`); - logger.info('TrailerService', `Local server timeout set to ${this.TIMEOUT}ms`); const response = await fetch(url, { method: 'GET', @@ -85,6 +87,8 @@ export class TrailerService { }, signal: controller.signal, }); + + logger.info('TrailerService', `Fetch request completed. Response status: ${response.status}`); clearTimeout(timeoutId); @@ -137,6 +141,12 @@ export class TrailerService { } else { const msg = error instanceof Error ? `${error.name}: ${error.message}` : String(error); logger.error('TrailerService', `Error in auto-search: ${msg}`); + logger.error('TrailerService', `Error details:`, { + name: (error as any)?.name, + message: (error as any)?.message, + stack: (error as any)?.stack, + url: url + }); } return null; // Return null to trigger XPrime fallback }