fix: properly extract anime title from URL
This commit is contained in:
@@ -178,6 +178,32 @@ async function handleAddToWatchlist(animeUrl, providerId) {
|
||||
|
||||
// Extract anime title from URL if not in metadata
|
||||
let animeTitle = metadata.title || 'Unknown Anime';
|
||||
if (animeTitle === 'Unknown Anime' || !animeTitle) {
|
||||
// Decode URL first if it's encoded
|
||||
let decodedUrl = animeUrl;
|
||||
try {
|
||||
decodedUrl = decodeURIComponent(animeUrl);
|
||||
} catch (e) {}
|
||||
|
||||
// Try to extract title from URL
|
||||
try {
|
||||
const urlParts = decodedUrl.split('/');
|
||||
// Find the anime name (usually between /catalogue/ and /saison/ or /vostfr/)
|
||||
const catalogueIndex = urlParts.indexOf('catalogue');
|
||||
if (catalogueIndex >= 0 && urlParts[catalogueIndex + 1]) {
|
||||
animeTitle = urlParts[catalogueIndex + 1];
|
||||
} else {
|
||||
// Fallback: use last part
|
||||
animeTitle = urlParts[urlParts.length - 2] || urlParts[urlParts.length - 1];
|
||||
}
|
||||
animeTitle = animeTitle.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);
|
||||
}
|
||||
}
|
||||
let animeTitle = metadata.title || 'Unknown Anime';
|
||||
if (animeTitle === 'Unknown Anime') {
|
||||
// Try to extract title from URL
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user