The Studio S01 1080p Web-dl ((hot)) Review
@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 |
I'll provide a implementation, but the logic can be adapted to Python, C#, etc. Feature: Media Filename Parser Goal Extract title , season , quality , and source from a string like "the studio s01 1080p web-dl" . Output Example "original": "the studio s01 1080p web-dl", "title": "The Studio", "season": 1, "quality": "1080p", "source": "web-dl", "isValid": true the studio s01 1080p web-dl
// Output: "The Studio S01 1080p web-dl" import re class MediaParser: QUALITIES = ['1080p', '720p', '4k', '2160p'] SOURCES = ['web-dl', 'webrip', 'bluray', 'hdtv', 'dvd'] @classmethod def parse(cls, filename: str): lower = filename
// Example usage const result = MediaFilenameParser.parse("the studio s01 1080p web-dl"); console.log(result); If you want to normalize filenames into a consistent format: @classmethod def parse(cls
static parse(filename: string): MediaInfo $this.SOURCES.join(')\\s*`, 'gi' ); title = title.replace(removePattern, '').trim(); // Capitalize words title = title.replace(/\b\w/g, c => c.toUpperCase());
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(' ');