UNPKG

crunchyroll-toolkit

Version:

Toolkit Node.js complet pour extraire données d'animés, métadonnées et thumbnails depuis Crunchyroll avec techniques anti-détection 2024/2025

94 lines (93 loc) 2.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ParserUtils = void 0; class ParserUtils { static cleanText(text) { if (!text) return ''; return text.trim().replace(/\s+/g, ' '); } static extractNumber(text) { if (!text) return undefined; const match = text.match(/\d+/); return match ? parseInt(match[0], 10) : undefined; } static extractEpisodeNumber(text) { const patterns = [ /[Ss]\d+[Ee](\d+)/, // S01E12 format /[Ee]pisode\s*(\d+)/, /[Ee]p\s*(\d+)/, /\b(\d+)\b/ ]; for (const pattern of patterns) { const match = text.match(pattern); if (match) { return parseInt(match[1], 10); } } return 0; } static extractSeasonNumber(text) { const patterns = [ /[Ss]aison\s*(\d+)/, /[Ss]eason\s*(\d+)/, /[Ss]\s*(\d+)/ ]; for (const pattern of patterns) { const match = text.match(pattern); if (match) { return parseInt(match[1], 10); } } return undefined; } static parseDate(dateStr) { if (!dateStr) return undefined; try { const date = new Date(dateStr); return isNaN(date.getTime()) ? undefined : date; } catch { return undefined; } } static extractDuration(text) { if (!text) return undefined; const patterns = [ /(\d+)\s*h\s*(\d+)\s*min/i, /(\d+)\s*min/i, /(\d+):(\d+)/ ]; for (const pattern of patterns) { const match = text.match(pattern); if (match) { if (match[2]) { // Format: Xh Ymin ou X:Y return parseInt(match[1], 10) * 60 + parseInt(match[2], 10); } else { // Format: X min return parseInt(match[1], 10); } } } return undefined; } static extractIdFromUrl(url) { const parts = url.split('/').filter(Boolean); return parts[parts.length - 1] || ''; } static normalizeUrl(url, baseUrl = 'https://www.crunchyroll.com') { if (url.startsWith('http')) { return url; } if (url.startsWith('/')) { return baseUrl + url; } return baseUrl + '/' + url; } } exports.ParserUtils = ParserUtils;