fix: extract anime title from URL when metadata title is missing
This commit is contained in:
@@ -173,10 +173,26 @@ async function handleAddToWatchlist(animeUrl, providerId) {
|
||||
throw new Error('Failed to fetch anime details');
|
||||
}
|
||||
|
||||
const metadata = await response.json();
|
||||
const data = await response.json();
|
||||
const metadata = data.metadata || {};
|
||||
|
||||
// Extract anime title from URL if not in metadata
|
||||
let animeTitle = metadata.title || 'Unknown Anime';
|
||||
if (animeTitle === 'Unknown Anime') {
|
||||
// Try to extract title from URL
|
||||
try {
|
||||
const urlParts = animeUrl.split('/');
|
||||
const slug = urlParts[urlParts.length - 1] || urlParts[urlParts.length - 2];
|
||||
animeTitle = slug.replace(/-/g, ' ').replace(/\+/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
// Capitalize words
|
||||
animeTitle = animeTitle.replace(/\b\w/g, l => l.toUpperCase());
|
||||
} catch (e) {
|
||||
console.warn('Could not extract title from URL:', e);
|
||||
}
|
||||
}
|
||||
|
||||
const itemData = {
|
||||
anime_title: metadata.title || 'Unknown Anime',
|
||||
anime_title: animeTitle,
|
||||
anime_url: animeUrl,
|
||||
provider_id: providerId,
|
||||
lang: 'vostfr',
|
||||
|
||||
Reference in New Issue
Block a user