Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions addon/lib/getCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2224,16 +2224,14 @@ async function getLetterboxdCatalog(
includeVideos: boolean = false
): Promise<any[]> {
try {
// Extract identifier from catalog ID (format: letterboxd.<identifier>)
const identifier = catalogId.replace('letterboxd.', '');

// Find catalog config to determine source identifier and watchlist flag
const catalogConfig = config.catalogs?.find(c => c.id === catalogId);
// Prefer metadata identifier to support duplicated catalogs with suffixed IDs.
const identifier = catalogConfig?.metadata?.identifier || catalogId.replace('letterboxd.', '');
if (!identifier) {
logger.error(`Invalid Letterboxd catalog ID: ${catalogId}`);
return [];
}

// Find catalog config to determine if it's a watchlist
const catalogConfig = config.catalogs?.find(c => c.id === catalogId);
const isWatchlist = catalogConfig?.metadata?.isWatchlist || false;

logger.info(`Fetching Letterboxd ${isWatchlist ? 'watchlist' : 'list'}: ${identifier}, Page: ${page}`);
Expand Down
8 changes: 1 addition & 7 deletions configure/src/components/QuickAddDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,6 @@ export function QuickAddDialog({ isOpen, onClose }: QuickAddDialogProps) {
}

const { identifier, isWatchlist } = await extractResponse.json();
const catalogId = `letterboxd.${identifier}`;

if (catalogExists(catalogId)) {
toast.info("This Letterboxd list is already in your catalogs");
onClose();
return;
}

// Fetch list metadata from StremThru
const listResponse = await fetch('/api/letterboxd/list', {
Expand All @@ -566,6 +559,7 @@ export function QuickAddDialog({ isOpen, onClose }: QuickAddDialogProps) {
url: parsedUrl.url,
cacheTTL: catalogTTL,
displayTypeOverrides: config.displayTypeOverrides,
existingCatalogs: config.catalogs,
});

setConfig(prev => ({
Expand Down
12 changes: 1 addition & 11 deletions configure/src/components/sections/LetterboxdIntegration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ export function LetterboxdIntegration({ isOpen, onClose }: LetterboxdIntegration
const itemCount = listData.data?.items?.length || 0;

// Step 3: Create catalog
const catalogId = `letterboxd.${identifier}`;

// Check if catalog already exists
if (config.catalogs.some(c => c.id === catalogId)) {
toast.error("List already added", {
description: "This Letterboxd list is already in your catalogs"
});
setIsProcessing(false);
return;
}

const newCatalog = createLetterboxdCatalog({
identifier,
title: listTitle,
Expand All @@ -113,6 +102,7 @@ export function LetterboxdIntegration({ isOpen, onClose }: LetterboxdIntegration
url: listUrl,
cacheTTL: defaultCacheTTL,
displayTypeOverrides: config.displayTypeOverrides,
existingCatalogs: config.catalogs,
});

setConfig(prev => ({
Expand Down
11 changes: 10 additions & 1 deletion configure/src/utils/catalogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export interface LetterboxdCatalogOptions {
url: string;
cacheTTL?: number;
displayTypeOverrides?: { movie?: string; series?: string };
existingCatalogs?: CatalogConfig[];
}

/**
Expand All @@ -276,12 +277,20 @@ export function createLetterboxdCatalog(options: LetterboxdCatalogOptions): Cata
url,
cacheTTL = 86400, // Default 24 hours
displayTypeOverrides,
existingCatalogs = [],
} = options;

const displayType = getDisplayTypeOverride('movie', displayTypeOverrides);
const sameIdentifierCount = existingCatalogs.filter((catalog) => {
if (catalog.source !== 'letterboxd') return false;
return catalog.metadata?.identifier === identifier;
}).length;
const catalogId = sameIdentifierCount === 0
? `letterboxd.${identifier}`
: `letterboxd.${identifier}.${sameIdentifierCount + 1}`;

return {
id: `letterboxd.${identifier}`,
id: catalogId,
type: 'movie', // Letterboxd is primarily movies
name: title,
enabled: true,
Expand Down