Just For Fun

July 1, 2012

Just the other day...

import re, os
avi_re = '(Friends)(\\.)(S)(01)(E)(?P<epi>.*?)(\\.)(DVDRip)(\\.)(XviD)(\\.)(avi)'
sub_re = '(Friends)( )(-)( )(1)(\\.)(?P<epi>\w+)(?P<name>.*?)(\\(EN\\))(\\.)(sub)'

for avi_f in filelist:
  if re.match(avi_re, avi_f):
    e = re.match(avi_re, avi_f).group('epi')
    for sub_f in filelist:
      if re.match(sub_re, sub_f):
        ep = re.match(sub_re, sub_f).group('epi')
        if e == ep:
          new = 'Friends - 1.' + ep + re.match(sub_re, sub_f).group('name')
          os.rename(avi_f, new + '.avi')
          os.rename(sub_f, new + '.sub')

because I can! ;)