class MediaFilenameParser private static readonly QUALITIES = ['1080p', '720p', '4k', '2160p']; private static readonly SOURCES = ['web-dl', 'webrip', 'bluray', 'hdtv', 'dvd'];
interface MediaInfo null; isValid: boolean; the studio s01 1080p web-dl
@classmethod def parse(cls, filename: str): lower = filename.lower() # Season season_match = re.search(r'(?:s|season)\s*(\d1,2)', lower) season = int(season_match.group(1)) if season_match else None # Quality quality = next((q for q in cls.QUALITIES if q in lower), None) # Source source = next((s for s in cls.SOURCES if s in lower), None) # Title title = re.sub(r'\s*(?:s\d1,2|season\s*\d1,2|' + '|'.join(cls.QUALITIES + cls.SOURCES) + r')\s*', '', filename, flags=re.I).strip() title = title.title() return 'original': filename, 'title': title, 'season': season, 'quality': quality, 'source': source, 'is_valid': bool(title and (season or quality or source)) print(MediaParser.parse("the studio s01 1080p web-dl")) Edge Cases Handled | Input | Title | Season | Quality | Source | |-------|-------|--------|---------|--------| | the studio s01 1080p web-dl | The Studio | 1 | 1080p | web-dl | | show.name.S02.720p.WEB-DL | Show Name | 2 | 720p | web-dl | | series season 1 4k bluray | Series | 1 | 4k | bluray | | movie 1080p | Movie | null | 1080p | null | private static readonly SOURCES = ['web-dl'
// Extract title (everything before season, quality, or source) let title = original; const removePattern = new RegExp( `\\s*(?:s\\d1,2 interface MediaInfo null
function toStandardFormat(info: MediaInfo): string const parts = [info.title]; if (info.season !== null) parts.push(`S$info.season.toString().padStart(2, '0')`); if (info.quality) parts.push(info.quality); if (info.source) parts.push(info.source); return parts.join(' ');