mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-28 20:03:34 +00:00
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: {
|
singleRowLayout: {
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
gap: 8,
|
gap: 4,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
|
@ -2163,11 +2163,11 @@ const styles = StyleSheet.create({
|
||||||
},
|
},
|
||||||
singleRowPlayButtonFullWidth: {
|
singleRowPlayButtonFullWidth: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
marginHorizontal: 4,
|
marginHorizontal: 2,
|
||||||
},
|
},
|
||||||
singleRowSaveButtonFullWidth: {
|
singleRowSaveButtonFullWidth: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
marginHorizontal: 4,
|
marginHorizontal: 2,
|
||||||
},
|
},
|
||||||
primaryActionRow: {
|
primaryActionRow: {
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
|
|
|
||||||
|
|
@ -155,24 +155,6 @@ const TrailersSection: React.FC<TrailersSectionProps> = memo(({
|
||||||
sectionTranslateYSV.value = withDelay(500, withTiming(0, { duration: 400 }));
|
sectionTranslateYSV.value = withDelay(500, withTiming(0, { duration: 400 }));
|
||||||
}, [sectionOpacitySV, sectionTranslateYSV]);
|
}, [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
|
// Fetch trailers from TMDB
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -180,17 +162,7 @@ const TrailersSection: React.FC<TrailersSectionProps> = memo(({
|
||||||
|
|
||||||
const initializeTrailers = async () => {
|
const initializeTrailers = async () => {
|
||||||
resetSectionAnimation();
|
resetSectionAnimation();
|
||||||
// First check if backend is available
|
setBackendAvailable(true); // Assume available, let TrailerService handle errors
|
||||||
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
|
|
||||||
await fetchTrailers();
|
await fetchTrailers();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -334,7 +306,7 @@ const TrailersSection: React.FC<TrailersSectionProps> = memo(({
|
||||||
};
|
};
|
||||||
|
|
||||||
initializeTrailers();
|
initializeTrailers();
|
||||||
}, [tmdbId, type, checkBackendAvailability]);
|
}, [tmdbId, type]);
|
||||||
|
|
||||||
// Categorize trailers by type
|
// Categorize trailers by type
|
||||||
const categorizeTrailers = (videos: any[]): CategorizedTrailers => {
|
const categorizeTrailers = (videos: any[]): CategorizedTrailers => {
|
||||||
|
|
|
||||||
|
|
@ -53,29 +53,31 @@ export class TrailerService {
|
||||||
* @returns Promise<string | null> - The trailer URL or null if not found
|
* @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> {
|
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 {
|
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, {
|
const response = await fetch(url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|
@ -86,6 +88,8 @@ export class TrailerService {
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logger.info('TrailerService', `Fetch request completed. Response status: ${response.status}`);
|
||||||
|
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
const elapsed = Date.now() - startTime;
|
const elapsed = Date.now() - startTime;
|
||||||
|
|
@ -137,6 +141,12 @@ export class TrailerService {
|
||||||
} else {
|
} else {
|
||||||
const msg = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
const msg = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
||||||
logger.error('TrailerService', `Error in auto-search: ${msg}`);
|
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
|
return null; // Return null to trigger XPrime fallback
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue