mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-12 04:50:44 +00:00
chore: improved tmdb enrichment logic
This commit is contained in:
parent
3d5a9ebf42
commit
4aa22cc1c3
8 changed files with 413 additions and 343 deletions
|
|
@ -226,7 +226,7 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const shouldFetchMeta = await stremioService.isValidContentId(type, id);
|
const shouldFetchMeta = await stremioService.isValidContentId(type, id);
|
||||||
|
|
||||||
const [metadata, basicContent, addonSpecificMeta] = await Promise.all([
|
const [metadata, basicContent, addonSpecificMeta] = await Promise.all([
|
||||||
shouldFetchMeta ? stremioService.getMetaDetails(type, id) : Promise.resolve(null),
|
shouldFetchMeta ? stremioService.getMetaDetails(type, id) : Promise.resolve(null),
|
||||||
catalogService.getBasicContentDetails(type, id),
|
catalogService.getBasicContentDetails(type, id),
|
||||||
|
|
@ -237,7 +237,7 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const preferredAddonMeta = addonSpecificMeta || metadata;
|
const preferredAddonMeta = addonSpecificMeta || metadata;
|
||||||
|
|
||||||
|
|
||||||
const finalContent = basicContent ? {
|
const finalContent = basicContent ? {
|
||||||
...basicContent,
|
...basicContent,
|
||||||
|
|
@ -245,7 +245,7 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
...(preferredAddonMeta?.poster && { poster: preferredAddonMeta.poster }),
|
...(preferredAddonMeta?.poster && { poster: preferredAddonMeta.poster }),
|
||||||
...(preferredAddonMeta?.description && { description: preferredAddonMeta.description }),
|
...(preferredAddonMeta?.description && { description: preferredAddonMeta.description }),
|
||||||
} : null;
|
} : null;
|
||||||
|
|
||||||
|
|
||||||
if (finalContent) {
|
if (finalContent) {
|
||||||
const result = {
|
const result = {
|
||||||
|
|
@ -263,11 +263,11 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
const findNextEpisode = useCallback((
|
const findNextEpisode = useCallback((
|
||||||
currentSeason: number,
|
currentSeason: number,
|
||||||
currentEpisode: number,
|
currentEpisode: number,
|
||||||
videos: any[],
|
videos: any[],
|
||||||
watchedSet?: Set<string>,
|
watchedSet?: Set<string>,
|
||||||
showId?: string
|
showId?: string
|
||||||
|
|
@ -282,16 +282,16 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
const isAlreadyWatched = (season: number, episode: number): boolean => {
|
const isAlreadyWatched = (season: number, episode: number): boolean => {
|
||||||
if (!watchedSet || !showId) return false;
|
if (!watchedSet || !showId) return false;
|
||||||
const cleanShowId = showId.startsWith('tt') ? showId : `tt${showId}`;
|
const cleanShowId = showId.startsWith('tt') ? showId : `tt${showId}`;
|
||||||
return watchedSet.has(`${cleanShowId}:${season}:${episode}`) ||
|
return watchedSet.has(`${cleanShowId}:${season}:${episode}`) ||
|
||||||
watchedSet.has(`${showId}:${season}:${episode}`);
|
watchedSet.has(`${showId}:${season}:${episode}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const video of sortedVideos) {
|
for (const video of sortedVideos) {
|
||||||
if (video.season < currentSeason) continue;
|
if (video.season < currentSeason) continue;
|
||||||
if (video.season === currentSeason && video.episode <= currentEpisode) continue;
|
if (video.season === currentSeason && video.episode <= currentEpisode) continue;
|
||||||
|
|
||||||
if (isAlreadyWatched(video.season, video.episode)) continue;
|
if (isAlreadyWatched(video.season, video.episode)) continue;
|
||||||
|
|
||||||
if (isEpisodeReleased(video)) {
|
if (isEpisodeReleased(video)) {
|
||||||
return video;
|
return video;
|
||||||
}
|
}
|
||||||
|
|
@ -299,7 +299,7 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
// Modified loadContinueWatching to render incrementally
|
// Modified loadContinueWatching to render incrementally
|
||||||
const loadContinueWatching = useCallback(async (isBackgroundRefresh = false) => {
|
const loadContinueWatching = useCallback(async (isBackgroundRefresh = false) => {
|
||||||
|
|
@ -379,7 +379,7 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
const progressPercent =
|
const progressPercent =
|
||||||
progress.duration > 0
|
progress.duration > 0
|
||||||
? (progress.currentTime / progress.duration) * 100
|
? (progress.currentTime / progress.duration) * 100
|
||||||
: 0;
|
: 0;
|
||||||
// Skip fully watched movies
|
// Skip fully watched movies
|
||||||
if (type === 'movie' && progressPercent >= 85) continue;
|
if (type === 'movie' && progressPercent >= 85) continue;
|
||||||
// Skip movies with no actual progress (ensure > 0%)
|
// Skip movies with no actual progress (ensure > 0%)
|
||||||
|
|
@ -533,7 +533,7 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nextEpisode && metadata?.videos) {
|
if (!nextEpisode && metadata?.videos) {
|
||||||
|
|
@ -558,7 +558,7 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
} as ContinueWatchingItem);
|
} as ContinueWatchingItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -711,7 +711,7 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
const movieKey = `movie:${imdbId}`;
|
const movieKey = `movie:${imdbId}`;
|
||||||
if (recentlyRemovedRef.current.has(movieKey)) continue;
|
if (recentlyRemovedRef.current.has(movieKey)) continue;
|
||||||
|
|
||||||
const cachedData = await getCachedMetadata('movie', imdbId, item.addonId);
|
const cachedData = await getCachedMetadata('movie', imdbId);
|
||||||
if (!cachedData?.basicContent) continue;
|
if (!cachedData?.basicContent) continue;
|
||||||
|
|
||||||
const pausedAt = new Date(item.paused_at).getTime();
|
const pausedAt = new Date(item.paused_at).getTime();
|
||||||
|
|
@ -743,7 +743,7 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cachedData = await getCachedMetadata('series', showImdb, item.addonId);
|
const cachedData = await getCachedMetadata('series', showImdb);
|
||||||
if (!cachedData?.basicContent) continue;
|
if (!cachedData?.basicContent) continue;
|
||||||
|
|
||||||
traktBatch.push({
|
traktBatch.push({
|
||||||
|
|
@ -1204,41 +1204,40 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
padding: isTV ? 16 : isLargeTablet ? 14 : isTablet ? 12 : 12
|
padding: isTV ? 16 : isLargeTablet ? 14 : isTablet ? 12 : 12
|
||||||
}
|
}
|
||||||
]}>
|
]}>
|
||||||
{(() => {
|
{(() => {
|
||||||
const isUpNext = item.type === 'series' && item.progress === 0;
|
const isUpNext = item.type === 'series' && item.progress === 0;
|
||||||
return (
|
return (
|
||||||
<View style={styles.titleRow}>
|
<View style={styles.titleRow}>
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
styles.contentTitle,
|
styles.contentTitle,
|
||||||
{
|
{
|
||||||
color: currentTheme.colors.highEmphasis,
|
color: currentTheme.colors.highEmphasis,
|
||||||
fontSize: isTV ? 20 : isLargeTablet ? 18 : isTablet ? 17 : 16
|
fontSize: isTV ? 20 : isLargeTablet ? 18 : isTablet ? 17 : 16
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
numberOfLines={1}
|
numberOfLines={1}
|
||||||
>
|
>
|
||||||
{item.name}
|
{item.name}
|
||||||
</Text>
|
</Text>
|
||||||
{isUpNext && (
|
{isUpNext && (
|
||||||
<View style={[
|
<View style={[
|
||||||
styles.progressBadge,
|
styles.progressBadge,
|
||||||
{
|
{
|
||||||
backgroundColor: currentTheme.colors.primary,
|
backgroundColor: currentTheme.colors.primary,
|
||||||
paddingHorizontal: isTV ? 12 : isLargeTablet ? 10 : isTablet ? 8 : 8,
|
paddingHorizontal: isTV ? 12 : isLargeTablet ? 10 : isTablet ? 8 : 8,
|
||||||
paddingVertical: isTV ? 6 : isLargeTablet ? 5 : isTablet ? 4 : 3
|
paddingVertical: isTV ? 6 : isLargeTablet ? 5 : isTablet ? 4 : 3
|
||||||
}
|
}
|
||||||
]}>
|
]}>
|
||||||
<Text style={[
|
<Text style={[
|
||||||
styles.progressText,
|
styles.progressText,
|
||||||
{ fontSize: isTV ? 14 : isLargeTablet ? 13 : isTablet ? 12 : 12 }
|
{ fontSize: isTV ? 14 : isLargeTablet ? 13 : isTablet ? 12 : 12 }
|
||||||
]}>Up Next</Text>
|
]}>Up Next</Text>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
})()}
|
})()}
|
||||||
</View>
|
|
||||||
|
|
||||||
{/* Episode Info or Year */}
|
{/* Episode Info or Year */}
|
||||||
{(() => {
|
{(() => {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
import React, { createContext, useContext, ReactNode } from 'react';
|
import React, { createContext, useContext, ReactNode } from 'react';
|
||||||
import { useTraktIntegration } from '../hooks/useTraktIntegration';
|
import { useTraktIntegration } from '../hooks/useTraktIntegration';
|
||||||
import {
|
import {
|
||||||
TraktUser,
|
TraktUser,
|
||||||
TraktWatchedItem,
|
TraktWatchedItem,
|
||||||
TraktWatchlistItem,
|
TraktWatchlistItem,
|
||||||
TraktCollectionItem,
|
TraktCollectionItem,
|
||||||
TraktRatingItem,
|
TraktRatingItem,
|
||||||
TraktPlaybackItem
|
TraktPlaybackItem,
|
||||||
|
traktService
|
||||||
} from '../services/traktService';
|
} from '../services/traktService';
|
||||||
|
|
||||||
interface TraktContextProps {
|
interface TraktContextProps {
|
||||||
|
|
@ -37,15 +38,25 @@ interface TraktContextProps {
|
||||||
removeFromCollection: (imdbId: string, type: 'movie' | 'show') => Promise<boolean>;
|
removeFromCollection: (imdbId: string, type: 'movie' | 'show') => Promise<boolean>;
|
||||||
isInWatchlist: (imdbId: string, type: 'movie' | 'show') => boolean;
|
isInWatchlist: (imdbId: string, type: 'movie' | 'show') => boolean;
|
||||||
isInCollection: (imdbId: string, type: 'movie' | 'show') => boolean;
|
isInCollection: (imdbId: string, type: 'movie' | 'show') => boolean;
|
||||||
|
// Maintenance mode
|
||||||
|
isMaintenanceMode: boolean;
|
||||||
|
maintenanceMessage: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TraktContext = createContext<TraktContextProps | undefined>(undefined);
|
const TraktContext = createContext<TraktContextProps | undefined>(undefined);
|
||||||
|
|
||||||
export function TraktProvider({ children }: { children: ReactNode }) {
|
export function TraktProvider({ children }: { children: ReactNode }) {
|
||||||
const traktIntegration = useTraktIntegration();
|
const traktIntegration = useTraktIntegration();
|
||||||
|
|
||||||
|
// Add maintenance mode values to the context
|
||||||
|
const contextValue: TraktContextProps = {
|
||||||
|
...traktIntegration,
|
||||||
|
isMaintenanceMode: traktService.isMaintenanceMode(),
|
||||||
|
maintenanceMessage: traktService.getMaintenanceMessage(),
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TraktContext.Provider value={traktIntegration}>
|
<TraktContext.Provider value={contextValue}>
|
||||||
{children}
|
{children}
|
||||||
</TraktContext.Provider>
|
</TraktContext.Provider>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -550,7 +550,7 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
if (__DEV__) logger.log('Fetching movie details from TMDB for:', tmdbId);
|
if (__DEV__) logger.log('Fetching movie details from TMDB for:', tmdbId);
|
||||||
const movieDetails = await tmdbService.getMovieDetails(
|
const movieDetails = await tmdbService.getMovieDetails(
|
||||||
tmdbId,
|
tmdbId,
|
||||||
settings.useTmdbLocalizedMetadata ? `${settings.tmdbLanguagePreference || 'en'}-US` : 'en-US'
|
settings.useTmdbLocalizedMetadata ? (settings.tmdbLanguagePreference || 'en') : 'en'
|
||||||
);
|
);
|
||||||
if (movieDetails) {
|
if (movieDetails) {
|
||||||
const imdbId = movieDetails.imdb_id || movieDetails.external_ids?.imdb_id;
|
const imdbId = movieDetails.imdb_id || movieDetails.external_ids?.imdb_id;
|
||||||
|
|
@ -634,7 +634,7 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
try {
|
try {
|
||||||
const showDetails = await tmdbService.getTVShowDetails(
|
const showDetails = await tmdbService.getTVShowDetails(
|
||||||
parseInt(tmdbId),
|
parseInt(tmdbId),
|
||||||
settings.useTmdbLocalizedMetadata ? `${settings.tmdbLanguagePreference || 'en'}-US` : 'en-US'
|
settings.useTmdbLocalizedMetadata ? (settings.tmdbLanguagePreference || 'en') : 'en'
|
||||||
);
|
);
|
||||||
if (showDetails) {
|
if (showDetails) {
|
||||||
// OPTIMIZATION: Fetch external IDs, credits, and logo in parallel
|
// OPTIMIZATION: Fetch external IDs, credits, and logo in parallel
|
||||||
|
|
@ -824,9 +824,9 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
// Store addon logo before TMDB enrichment overwrites it
|
// Store addon logo before TMDB enrichment overwrites it
|
||||||
const addonLogo = (finalMetadata as any).logo;
|
const addonLogo = (finalMetadata as any).logo;
|
||||||
|
|
||||||
// If localization is enabled, merge TMDB localized text (name/overview) before first render
|
// If localization is enabled AND title/description enrichment is enabled, merge TMDB localized text (name/overview) before first render
|
||||||
try {
|
try {
|
||||||
if (settings.enrichMetadataWithTMDB && settings.useTmdbLocalizedMetadata) {
|
if (settings.enrichMetadataWithTMDB && settings.useTmdbLocalizedMetadata && settings.tmdbEnrichTitleDescription) {
|
||||||
const tmdbSvc = TMDBService.getInstance();
|
const tmdbSvc = TMDBService.getInstance();
|
||||||
let finalTmdbId: number | null = tmdbId;
|
let finalTmdbId: number | null = tmdbId;
|
||||||
if (!finalTmdbId) {
|
if (!finalTmdbId) {
|
||||||
|
|
@ -857,8 +857,8 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
|
|
||||||
finalMetadata = {
|
finalMetadata = {
|
||||||
...finalMetadata,
|
...finalMetadata,
|
||||||
name: finalMetadata.name || localized.title,
|
name: localized.title || finalMetadata.name,
|
||||||
description: finalMetadata.description || localized.overview,
|
description: localized.overview || finalMetadata.description,
|
||||||
movieDetails: movieDetailsObj,
|
movieDetails: movieDetailsObj,
|
||||||
...(productionInfo.length > 0 && { networks: productionInfo }),
|
...(productionInfo.length > 0 && { networks: productionInfo }),
|
||||||
};
|
};
|
||||||
|
|
@ -894,8 +894,8 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
|
|
||||||
finalMetadata = {
|
finalMetadata = {
|
||||||
...finalMetadata,
|
...finalMetadata,
|
||||||
name: finalMetadata.name || localized.name,
|
name: localized.name || finalMetadata.name,
|
||||||
description: finalMetadata.description || localized.overview,
|
description: localized.overview || finalMetadata.description,
|
||||||
tvDetails,
|
tvDetails,
|
||||||
...(productionInfo.length > 0 && { networks: productionInfo }),
|
...(productionInfo.length > 0 && { networks: productionInfo }),
|
||||||
};
|
};
|
||||||
|
|
@ -909,14 +909,8 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
|
|
||||||
// Centralized logo fetching logic
|
// Centralized logo fetching logic
|
||||||
try {
|
try {
|
||||||
if (addonLogo) {
|
// When TMDB enrichment AND logos are enabled, prioritize TMDB logo over addon logo
|
||||||
finalMetadata.logo = addonLogo;
|
if (settings.enrichMetadataWithTMDB && settings.tmdbEnrichLogos) {
|
||||||
if (__DEV__) {
|
|
||||||
console.log('[useMetadata] Using addon-provided logo:', { hasLogo: true });
|
|
||||||
}
|
|
||||||
// Check both master switch AND granular logos setting
|
|
||||||
} else if (settings.enrichMetadataWithTMDB && settings.tmdbEnrichLogos) {
|
|
||||||
// Only use TMDB logos when both enrichment AND logos option are ON
|
|
||||||
const tmdbService = TMDBService.getInstance();
|
const tmdbService = TMDBService.getInstance();
|
||||||
const preferredLanguage = settings.tmdbLanguagePreference || 'en';
|
const preferredLanguage = settings.tmdbLanguagePreference || 'en';
|
||||||
const contentType = type === 'series' ? 'tv' : 'movie';
|
const contentType = type === 'series' ? 'tv' : 'movie';
|
||||||
|
|
@ -932,23 +926,26 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
|
|
||||||
if (tmdbIdForLogo) {
|
if (tmdbIdForLogo) {
|
||||||
const logoUrl = await tmdbService.getContentLogo(contentType, tmdbIdForLogo, preferredLanguage);
|
const logoUrl = await tmdbService.getContentLogo(contentType, tmdbIdForLogo, preferredLanguage);
|
||||||
finalMetadata.logo = logoUrl || undefined; // TMDB logo or undefined (no addon fallback)
|
// Use TMDB logo if found, otherwise fall back to addon logo
|
||||||
|
finalMetadata.logo = logoUrl || addonLogo || undefined;
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
console.log('[useMetadata] Logo fetch result:', {
|
console.log('[useMetadata] Logo fetch result:', {
|
||||||
contentType,
|
contentType,
|
||||||
tmdbIdForLogo,
|
tmdbIdForLogo,
|
||||||
preferredLanguage,
|
preferredLanguage,
|
||||||
logoUrl: !!logoUrl,
|
tmdbLogoFound: !!logoUrl,
|
||||||
|
usingAddonFallback: !logoUrl && !!addonLogo,
|
||||||
enrichmentEnabled: true
|
enrichmentEnabled: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
finalMetadata.logo = undefined; // No TMDB ID means no logo
|
// No TMDB ID, fall back to addon logo
|
||||||
if (__DEV__) console.log('[useMetadata] No TMDB ID found for logo, will show text title');
|
finalMetadata.logo = addonLogo || undefined;
|
||||||
|
if (__DEV__) console.log('[useMetadata] No TMDB ID found for logo, using addon logo');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// When enrichment or logos is OFF, keep addon logo or undefined
|
// When enrichment or logos is OFF, use addon logo
|
||||||
finalMetadata.logo = finalMetadata.logo || undefined;
|
finalMetadata.logo = addonLogo || finalMetadata.logo || undefined;
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
console.log('[useMetadata] TMDB logo enrichment disabled, using addon logo:', {
|
console.log('[useMetadata] TMDB logo enrichment disabled, using addon logo:', {
|
||||||
hasAddonLogo: !!finalMetadata.logo,
|
hasAddonLogo: !!finalMetadata.logo,
|
||||||
|
|
@ -1125,10 +1122,11 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
// Fetch season posters from TMDB only if enrichment AND season posters are enabled
|
// Fetch season posters from TMDB only if enrichment AND season posters are enabled
|
||||||
if (settings.enrichMetadataWithTMDB && settings.tmdbEnrichSeasonPosters) {
|
if (settings.enrichMetadataWithTMDB && settings.tmdbEnrichSeasonPosters) {
|
||||||
try {
|
try {
|
||||||
|
const lang = settings.useTmdbLocalizedMetadata ? `${settings.tmdbLanguagePreference || 'en'}` : 'en';
|
||||||
const tmdbIdToUse = tmdbId || (id.startsWith('tt') ? await tmdbService.findTMDBIdByIMDB(id) : null);
|
const tmdbIdToUse = tmdbId || (id.startsWith('tt') ? await tmdbService.findTMDBIdByIMDB(id) : null);
|
||||||
if (tmdbIdToUse) {
|
if (tmdbIdToUse) {
|
||||||
if (!tmdbId) setTmdbId(tmdbIdToUse);
|
if (!tmdbId) setTmdbId(tmdbIdToUse);
|
||||||
const showDetails = await tmdbService.getTVShowDetails(tmdbIdToUse);
|
const showDetails = await tmdbService.getTVShowDetails(tmdbIdToUse, lang);
|
||||||
if (showDetails?.seasons) {
|
if (showDetails?.seasons) {
|
||||||
Object.keys(groupedAddonEpisodes).forEach(seasonStr => {
|
Object.keys(groupedAddonEpisodes).forEach(seasonStr => {
|
||||||
const seasonNum = parseInt(seasonStr, 10);
|
const seasonNum = parseInt(seasonStr, 10);
|
||||||
|
|
@ -1156,7 +1154,8 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
try {
|
try {
|
||||||
const tmdbIdToUse = tmdbId || (id.startsWith('tt') ? await tmdbService.findTMDBIdByIMDB(id) : null);
|
const tmdbIdToUse = tmdbId || (id.startsWith('tt') ? await tmdbService.findTMDBIdByIMDB(id) : null);
|
||||||
if (tmdbIdToUse) {
|
if (tmdbIdToUse) {
|
||||||
const lang = `${settings.tmdbLanguagePreference || 'en'}-US`;
|
// Use just the language code (e.g., 'ar', not 'ar-US') for TMDB API
|
||||||
|
const lang = settings.tmdbLanguagePreference || 'en';
|
||||||
const seasons = Object.keys(groupedAddonEpisodes).map(Number);
|
const seasons = Object.keys(groupedAddonEpisodes).map(Number);
|
||||||
for (const seasonNum of seasons) {
|
for (const seasonNum of seasons) {
|
||||||
const seasonEps = groupedAddonEpisodes[seasonNum];
|
const seasonEps = groupedAddonEpisodes[seasonNum];
|
||||||
|
|
@ -1264,13 +1263,14 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
|
|
||||||
// Fallback to TMDB if no addon episodes
|
// Fallback to TMDB if no addon episodes
|
||||||
logger.log('📺 No addon episodes found, falling back to TMDB');
|
logger.log('📺 No addon episodes found, falling back to TMDB');
|
||||||
|
const lang = settings.useTmdbLocalizedMetadata ? `${settings.tmdbLanguagePreference || 'en'}` : 'en';
|
||||||
const tmdbIdResult = await tmdbService.findTMDBIdByIMDB(id);
|
const tmdbIdResult = await tmdbService.findTMDBIdByIMDB(id);
|
||||||
if (tmdbIdResult) {
|
if (tmdbIdResult) {
|
||||||
setTmdbId(tmdbIdResult);
|
setTmdbId(tmdbIdResult);
|
||||||
|
|
||||||
const [allEpisodes, showDetails] = await Promise.all([
|
const [allEpisodes, showDetails] = await Promise.all([
|
||||||
tmdbService.getAllEpisodes(tmdbIdResult),
|
tmdbService.getAllEpisodes(tmdbIdResult, lang),
|
||||||
tmdbService.getTVShowDetails(tmdbIdResult)
|
tmdbService.getTVShowDetails(tmdbIdResult, lang)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const transformedEpisodes: GroupedEpisodes = {};
|
const transformedEpisodes: GroupedEpisodes = {};
|
||||||
|
|
@ -2038,7 +2038,8 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
setLoadingRecommendations(true);
|
setLoadingRecommendations(true);
|
||||||
try {
|
try {
|
||||||
const tmdbService = TMDBService.getInstance();
|
const tmdbService = TMDBService.getInstance();
|
||||||
const results = await tmdbService.getRecommendations(type === 'movie' ? 'movie' : 'tv', String(tmdbId));
|
const lang = settings.useTmdbLocalizedMetadata ? (settings.tmdbLanguagePreference || 'en') : 'en';
|
||||||
|
const results = await tmdbService.getRecommendations(type === 'movie' ? 'movie' : 'tv', String(tmdbId), lang);
|
||||||
|
|
||||||
// Convert TMDB results to StreamingContent format (simplified)
|
// Convert TMDB results to StreamingContent format (simplified)
|
||||||
const formattedRecommendations: StreamingContent[] = results.map((item: any) => ({
|
const formattedRecommendations: StreamingContent[] = results.map((item: any) => ({
|
||||||
|
|
@ -2056,7 +2057,7 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingRecommendations(false);
|
setLoadingRecommendations(false);
|
||||||
}
|
}
|
||||||
}, [tmdbId, type]);
|
}, [tmdbId, type, settings.useTmdbLocalizedMetadata, settings.tmdbLanguagePreference]);
|
||||||
|
|
||||||
// Fetch TMDB ID if needed and then recommendations
|
// Fetch TMDB ID if needed and then recommendations
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ export interface AppSettings {
|
||||||
tmdbEnrichMovieDetails: boolean; // Show movie details (budget, revenue, tagline, etc.)
|
tmdbEnrichMovieDetails: boolean; // Show movie details (budget, revenue, tagline, etc.)
|
||||||
tmdbEnrichTvDetails: boolean; // Show TV details (status, seasons count, networks, etc.)
|
tmdbEnrichTvDetails: boolean; // Show TV details (status, seasons count, networks, etc.)
|
||||||
tmdbEnrichCollections: boolean; // Show movie collections/franchises
|
tmdbEnrichCollections: boolean; // Show movie collections/franchises
|
||||||
|
tmdbEnrichTitleDescription: boolean; // Use TMDB title/description (overrides addon when localization enabled)
|
||||||
// Trakt integration
|
// Trakt integration
|
||||||
showTraktComments: boolean; // Show Trakt comments in metadata screens
|
showTraktComments: boolean; // Show Trakt comments in metadata screens
|
||||||
// Continue Watching behavior
|
// Continue Watching behavior
|
||||||
|
|
@ -176,6 +177,7 @@ export const DEFAULT_SETTINGS: AppSettings = {
|
||||||
tmdbEnrichMovieDetails: true,
|
tmdbEnrichMovieDetails: true,
|
||||||
tmdbEnrichTvDetails: true,
|
tmdbEnrichTvDetails: true,
|
||||||
tmdbEnrichCollections: true,
|
tmdbEnrichCollections: true,
|
||||||
|
tmdbEnrichTitleDescription: true, // Enabled by default for backward compatibility
|
||||||
// Trakt integration
|
// Trakt integration
|
||||||
showTraktComments: true, // Show Trakt comments by default when authenticated
|
showTraktComments: true, // Show Trakt comments by default when authenticated
|
||||||
// Continue Watching behavior
|
// Continue Watching behavior
|
||||||
|
|
|
||||||
|
|
@ -677,6 +677,23 @@ const TMDBSettingsScreen = () => {
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{/* Title & Description */}
|
||||||
|
<View style={styles.settingRow}>
|
||||||
|
<View style={styles.settingTextContainer}>
|
||||||
|
<Text style={[styles.settingTitle, { color: currentTheme.colors.text }]}>Title & Description</Text>
|
||||||
|
<Text style={[styles.settingDescription, { color: currentTheme.colors.mediumEmphasis }]}>
|
||||||
|
Use TMDb localized title and overview text
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
<Switch
|
||||||
|
value={settings.tmdbEnrichTitleDescription}
|
||||||
|
onValueChange={(v) => updateSetting('tmdbEnrichTitleDescription', v)}
|
||||||
|
trackColor={{ false: 'rgba(255,255,255,0.1)', true: currentTheme.colors.primary }}
|
||||||
|
thumbColor={Platform.OS === 'android' ? currentTheme.colors.white : ''}
|
||||||
|
ios_backgroundColor={'rgba(255,255,255,0.1)'}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
|
||||||
{/* Title Logos */}
|
{/* Title Logos */}
|
||||||
<View style={styles.settingRow}>
|
<View style={styles.settingRow}>
|
||||||
<View style={styles.settingTextContainer}>
|
<View style={styles.settingTextContainer}>
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ const TraktSettingsScreen: React.FC = () => {
|
||||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||||
const [userProfile, setUserProfile] = useState<TraktUser | null>(null);
|
const [userProfile, setUserProfile] = useState<TraktUser | null>(null);
|
||||||
const { currentTheme } = useTheme();
|
const { currentTheme } = useTheme();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
settings: autosyncSettings,
|
settings: autosyncSettings,
|
||||||
isSyncing,
|
isSyncing,
|
||||||
|
|
@ -101,7 +101,7 @@ const TraktSettingsScreen: React.FC = () => {
|
||||||
try {
|
try {
|
||||||
const authenticated = await traktService.isAuthenticated();
|
const authenticated = await traktService.isAuthenticated();
|
||||||
setIsAuthenticated(authenticated);
|
setIsAuthenticated(authenticated);
|
||||||
|
|
||||||
if (authenticated) {
|
if (authenticated) {
|
||||||
const profile = await traktService.getUserProfile();
|
const profile = await traktService.getUserProfile();
|
||||||
setUserProfile(profile);
|
setUserProfile(profile);
|
||||||
|
|
@ -151,8 +151,8 @@ const TraktSettingsScreen: React.FC = () => {
|
||||||
'Successfully Connected',
|
'Successfully Connected',
|
||||||
'Your Trakt account has been connected successfully.',
|
'Your Trakt account has been connected successfully.',
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
label: 'OK',
|
label: 'OK',
|
||||||
onPress: () => navigation.goBack(),
|
onPress: () => navigation.goBack(),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -190,9 +190,9 @@ const TraktSettingsScreen: React.FC = () => {
|
||||||
'Sign Out',
|
'Sign Out',
|
||||||
'Are you sure you want to sign out of your Trakt account?',
|
'Are you sure you want to sign out of your Trakt account?',
|
||||||
[
|
[
|
||||||
{ label: 'Cancel', onPress: () => {} },
|
{ label: 'Cancel', onPress: () => { } },
|
||||||
{
|
{
|
||||||
label: 'Sign Out',
|
label: 'Sign Out',
|
||||||
onPress: async () => {
|
onPress: async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
|
|
@ -224,26 +224,39 @@ const TraktSettingsScreen: React.FC = () => {
|
||||||
onPress={() => navigation.goBack()}
|
onPress={() => navigation.goBack()}
|
||||||
style={styles.backButton}
|
style={styles.backButton}
|
||||||
>
|
>
|
||||||
<MaterialIcons
|
<MaterialIcons
|
||||||
name="arrow-back"
|
name="arrow-back"
|
||||||
size={24}
|
size={24}
|
||||||
color={isDarkMode ? currentTheme.colors.highEmphasis : currentTheme.colors.textDark}
|
color={isDarkMode ? currentTheme.colors.highEmphasis : currentTheme.colors.textDark}
|
||||||
/>
|
/>
|
||||||
<Text style={[styles.backText, { color: isDarkMode ? currentTheme.colors.highEmphasis : currentTheme.colors.textDark }]}>
|
<Text style={[styles.backText, { color: isDarkMode ? currentTheme.colors.highEmphasis : currentTheme.colors.textDark }]}>
|
||||||
Settings
|
Settings
|
||||||
</Text>
|
</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
|
||||||
<View style={styles.headerActions}>
|
<View style={styles.headerActions}>
|
||||||
{/* Empty for now, but ready for future actions */}
|
{/* Empty for now, but ready for future actions */}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<Text style={[styles.headerTitle, { color: isDarkMode ? currentTheme.colors.highEmphasis : currentTheme.colors.textDark }]}>
|
<Text style={[styles.headerTitle, { color: isDarkMode ? currentTheme.colors.highEmphasis : currentTheme.colors.textDark }]}>
|
||||||
Trakt Settings
|
Trakt Settings
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<ScrollView
|
{/* Maintenance Mode Banner */}
|
||||||
|
{traktService.isMaintenanceMode() && (
|
||||||
|
<View style={styles.maintenanceBanner}>
|
||||||
|
<MaterialIcons name="engineering" size={24} color="#FFF" />
|
||||||
|
<View style={styles.maintenanceBannerTextContainer}>
|
||||||
|
<Text style={styles.maintenanceBannerTitle}>Under Maintenance</Text>
|
||||||
|
<Text style={styles.maintenanceBannerMessage}>
|
||||||
|
{traktService.getMaintenanceMessage()}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
style={styles.scrollView}
|
style={styles.scrollView}
|
||||||
contentContainerStyle={styles.scrollContent}
|
contentContainerStyle={styles.scrollContent}
|
||||||
>
|
>
|
||||||
|
|
@ -255,12 +268,44 @@ const TraktSettingsScreen: React.FC = () => {
|
||||||
<View style={styles.loadingContainer}>
|
<View style={styles.loadingContainer}>
|
||||||
<ActivityIndicator size="large" color={currentTheme.colors.primary} />
|
<ActivityIndicator size="large" color={currentTheme.colors.primary} />
|
||||||
</View>
|
</View>
|
||||||
|
) : traktService.isMaintenanceMode() ? (
|
||||||
|
<View style={styles.signInContainer}>
|
||||||
|
<TraktIcon
|
||||||
|
width={120}
|
||||||
|
height={120}
|
||||||
|
style={[styles.traktLogo, { opacity: 0.5 }]}
|
||||||
|
/>
|
||||||
|
<Text style={[
|
||||||
|
styles.signInTitle,
|
||||||
|
{ color: isDarkMode ? currentTheme.colors.highEmphasis : currentTheme.colors.textDark }
|
||||||
|
]}>
|
||||||
|
Trakt Unavailable
|
||||||
|
</Text>
|
||||||
|
<Text style={[
|
||||||
|
styles.signInDescription,
|
||||||
|
{ color: isDarkMode ? currentTheme.colors.mediumEmphasis : currentTheme.colors.textMutedDark }
|
||||||
|
]}>
|
||||||
|
The Trakt integration is temporarily paused for maintenance. All syncing and authentication is disabled until maintenance is complete.
|
||||||
|
</Text>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[
|
||||||
|
styles.button,
|
||||||
|
{ backgroundColor: currentTheme.colors.border, opacity: 0.6 }
|
||||||
|
]}
|
||||||
|
disabled={true}
|
||||||
|
>
|
||||||
|
<MaterialIcons name="engineering" size={20} color={currentTheme.colors.mediumEmphasis} style={{ marginRight: 8 }} />
|
||||||
|
<Text style={[styles.buttonText, { color: currentTheme.colors.mediumEmphasis }]}>
|
||||||
|
Service Under Maintenance
|
||||||
|
</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
) : isAuthenticated && userProfile ? (
|
) : isAuthenticated && userProfile ? (
|
||||||
<View style={styles.profileContainer}>
|
<View style={styles.profileContainer}>
|
||||||
<View style={styles.profileHeader}>
|
<View style={styles.profileHeader}>
|
||||||
{userProfile.avatar ? (
|
{userProfile.avatar ? (
|
||||||
<FastImage
|
<FastImage
|
||||||
source={{ uri: userProfile.avatar }}
|
source={{ uri: userProfile.avatar }}
|
||||||
style={styles.avatar}
|
style={styles.avatar}
|
||||||
resizeMode={FastImage.resizeMode.cover}
|
resizeMode={FastImage.resizeMode.cover}
|
||||||
/>
|
/>
|
||||||
|
|
@ -315,7 +360,7 @@ const TraktSettingsScreen: React.FC = () => {
|
||||||
</View>
|
</View>
|
||||||
) : (
|
) : (
|
||||||
<View style={styles.signInContainer}>
|
<View style={styles.signInContainer}>
|
||||||
<TraktIcon
|
<TraktIcon
|
||||||
width={120}
|
width={120}
|
||||||
height={120}
|
height={120}
|
||||||
style={styles.traktLogo}
|
style={styles.traktLogo}
|
||||||
|
|
@ -497,7 +542,7 @@ const TraktSettingsScreen: React.FC = () => {
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<CustomAlert
|
<CustomAlert
|
||||||
visible={alertVisible}
|
visible={alertVisible}
|
||||||
title={alertTitle}
|
title={alertTitle}
|
||||||
|
|
@ -704,6 +749,31 @@ const styles = StyleSheet.create({
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
lineHeight: 18,
|
lineHeight: 18,
|
||||||
},
|
},
|
||||||
|
// Maintenance mode styles
|
||||||
|
maintenanceBanner: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
backgroundColor: '#E67E22',
|
||||||
|
marginHorizontal: 16,
|
||||||
|
marginBottom: 16,
|
||||||
|
padding: 16,
|
||||||
|
borderRadius: 12,
|
||||||
|
},
|
||||||
|
maintenanceBannerTextContainer: {
|
||||||
|
marginLeft: 12,
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
maintenanceBannerTitle: {
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#FFF',
|
||||||
|
marginBottom: 4,
|
||||||
|
},
|
||||||
|
maintenanceBannerMessage: {
|
||||||
|
fontSize: 13,
|
||||||
|
color: '#FFF',
|
||||||
|
opacity: 0.9,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default TraktSettingsScreen;
|
export default TraktSettingsScreen;
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -577,6 +577,10 @@ export type TraktContentCommentLegacy =
|
||||||
| TraktEpisodeComment
|
| TraktEpisodeComment
|
||||||
| TraktListComment;
|
| TraktListComment;
|
||||||
|
|
||||||
|
|
||||||
|
const TRAKT_MAINTENANCE_MODE = true;
|
||||||
|
const TRAKT_MAINTENANCE_MESSAGE = 'Trakt integration is temporarily unavailable for maintenance. Please try again later.';
|
||||||
|
|
||||||
export class TraktService {
|
export class TraktService {
|
||||||
private static instance: TraktService;
|
private static instance: TraktService;
|
||||||
private accessToken: string | null = null;
|
private accessToken: string | null = null;
|
||||||
|
|
@ -584,6 +588,16 @@ export class TraktService {
|
||||||
private tokenExpiry: number = 0;
|
private tokenExpiry: number = 0;
|
||||||
private isInitialized: boolean = false;
|
private isInitialized: boolean = false;
|
||||||
|
|
||||||
|
|
||||||
|
public isMaintenanceMode(): boolean {
|
||||||
|
return TRAKT_MAINTENANCE_MODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public getMaintenanceMessage(): string {
|
||||||
|
return TRAKT_MAINTENANCE_MESSAGE;
|
||||||
|
}
|
||||||
|
|
||||||
// Rate limiting - Optimized for real-time scrobbling
|
// Rate limiting - Optimized for real-time scrobbling
|
||||||
private lastApiCall: number = 0;
|
private lastApiCall: number = 0;
|
||||||
private readonly MIN_API_INTERVAL = 500; // Reduced to 500ms for faster updates
|
private readonly MIN_API_INTERVAL = 500; // Reduced to 500ms for faster updates
|
||||||
|
|
@ -726,6 +740,12 @@ export class TraktService {
|
||||||
* Check if the user is authenticated with Trakt
|
* Check if the user is authenticated with Trakt
|
||||||
*/
|
*/
|
||||||
public async isAuthenticated(): Promise<boolean> {
|
public async isAuthenticated(): Promise<boolean> {
|
||||||
|
// During maintenance, report as not authenticated to disable all syncing
|
||||||
|
if (this.isMaintenanceMode()) {
|
||||||
|
logger.log('[TraktService] Maintenance mode: reporting as not authenticated');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
await this.ensureInitialized();
|
await this.ensureInitialized();
|
||||||
|
|
||||||
if (!this.accessToken) {
|
if (!this.accessToken) {
|
||||||
|
|
@ -756,6 +776,12 @@ export class TraktService {
|
||||||
* Exchange the authorization code for an access token
|
* Exchange the authorization code for an access token
|
||||||
*/
|
*/
|
||||||
public async exchangeCodeForToken(code: string, codeVerifier: string): Promise<boolean> {
|
public async exchangeCodeForToken(code: string, codeVerifier: string): Promise<boolean> {
|
||||||
|
// Block authentication during maintenance
|
||||||
|
if (this.isMaintenanceMode()) {
|
||||||
|
logger.warn('[TraktService] Maintenance mode: blocking new authentication');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
await this.ensureInitialized();
|
await this.ensureInitialized();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -887,6 +913,12 @@ export class TraktService {
|
||||||
body?: any,
|
body?: any,
|
||||||
retryCount: number = 0
|
retryCount: number = 0
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
|
// Block all API requests during maintenance
|
||||||
|
if (this.isMaintenanceMode()) {
|
||||||
|
logger.warn('[TraktService] Maintenance mode: blocking API request to', endpoint);
|
||||||
|
throw new Error(TRAKT_MAINTENANCE_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
await this.ensureInitialized();
|
await this.ensureInitialized();
|
||||||
|
|
||||||
// Rate limiting: ensure minimum interval between API calls
|
// Rate limiting: ensure minimum interval between API calls
|
||||||
|
|
@ -1106,10 +1138,10 @@ export class TraktService {
|
||||||
? imdbId
|
? imdbId
|
||||||
: `tt${imdbId}`;
|
: `tt${imdbId}`;
|
||||||
|
|
||||||
const response = await this.client.get('/sync/watched/movies');
|
const movies = await this.apiRequest<any[]>('/sync/watched/movies');
|
||||||
const movies = Array.isArray(response.data) ? response.data : [];
|
const moviesArray = Array.isArray(movies) ? movies : [];
|
||||||
|
|
||||||
return movies.some(
|
return moviesArray.some(
|
||||||
(m: any) => m.movie?.ids?.imdb === imdb
|
(m: any) => m.movie?.ids?.imdb === imdb
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue