Sakartu/next — Issue #31: Auto-rename subtitle files
Author: Sakartu
Created: 2011-11-15 21:19:40+00:00
State: open
Labels: Feature

It would be nice if next could preparse available subtitle files (.srt, .sub, etc) so they match the ep name. It would be even cooler if it could retrieve the subs from some api (bierdopje.com?), but renaming will be enough for now. Renaming is need so that players pick it up automatically. Some code that pretty much already does this is:

> #!/usr/bin/env python
> import os
> import re
>
> VID_EXTS = ['.avi', '.mkv']
> SUB_EXTS = ['.sub', '.srt']
> files = os.listdir('.')
>
> avis = filter(lambda x : x[-4:] in VID_EXTS, files)
> srts = filter(lambda x : x[-4:] in SUB_EXTS, files)
>
> se_rex = re.compile('(.*)(S\d{1,2}E\d{1,2})(.*)\.\w{3}')
> for avi in avis:
> m = se_rex.search(avi)
> prefix = m.group(1)
> se = m.group(2)
> postfix = m.group(3)
> for srt in srts:
> if se.lower() in srt.lower():
> new_name = prefix + se + postfix + srt[-4:]
> print srt, "->", new_name
> os.rename(srt, new_name)

We'll have to change some pieces (like using the regexes from util.constants) but it should work.