Skip to content

Instantly share code, notes, and snippets.

@vesche
Created June 25, 2018 21:45
Show Gist options
  • Save vesche/dc159a87f887a4f98123c4af7ea9d4cf to your computer and use it in GitHub Desktop.
Save vesche/dc159a87f887a4f98123c4af7ea9d4cf to your computer and use it in GitHub Desktop.
Incoming rename script
#!/usr/bin/env python
"""
quick incoming rename script
"""
import os
for f in os.listdir('.'):
if not os.path.isdir(f) or '_' in f:
continue
f_split = f.split('.')
if len(f_split) > 3:
pass
else:
f_split = f.split(' ')
if len(f_split) > 3:
pass
else:
continue
year = False
for i in f_split[::-1]:
try:
year = int(i)
if 1900 < year < 2020:
year = str(year)
break
except:
continue
if not year:
continue
title = []
for i in f_split:
if i == year:
break
title.append(i)
quality = ''
if '1080' in f:
quality = '1080'
elif '720' in f:
quality = '720'
elif '576' in f:
quality = '576'
elif '480' in f:
quality = '480'
else:
quality = '?'
new_name = '{} ({}) [{}]'.format(' '.join(title), year, quality)
os.system('mv "{}" "{}"'.format(f, new_name))
print("{}\n\t=> {}".format(f, new_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment