trailer service improvements
This commit is contained in:
parent
ce7f92b540
commit
dc8c27dfc4
3 changed files with 37 additions and 55 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -155,24 +155,6 @@ const TrailersSection: React.FC<TrailersSectionProps> = memo(({
|
|||
sectionTranslateYSV.value = withDelay(500, withTiming(0, { duration: 400 }));
|
||||
}, [sectionOpacitySV, sectionTranslateYSV]);
|
||||
|
||||
// Check if trailer service backend is available
|
||||
const checkBackendAvailability = useCallback(async (): Promise<boolean> => {
|
||||
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<TrailersSectionProps> = 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<TrailersSectionProps> = memo(({
|
|||
};
|
||||
|
||||
initializeTrailers();
|
||||
}, [tmdbId, type, checkBackendAvailability]);
|
||||
}, [tmdbId, type]);
|
||||
|
||||
// Categorize trailers by type
|
||||
const categorizeTrailers = (videos: any[]): CategorizedTrailers => {
|
||||
|
|
|
|||
|
|
@ -53,29 +53,31 @@ export class TrailerService {
|
|||
* @returns Promise<string | null> - The trailer URL or null if not found
|
||||
*/
|
||||
private static async getTrailerFromLocalServer(title: string, year: number, tmdbId?: string, type?: 'movie' | 'tv'): Promise<string | null> {
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue