Skip to content

Instantly share code, notes, and snippets.

@vesche
Last active June 5, 2019 03:19
Show Gist options
  • Save vesche/6bdd4cc57548599d6a572e908639981e to your computer and use it in GitHub Desktop.
Save vesche/6bdd4cc57548599d6a572e908639981e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
quick incoming rename script 2
"""
import os
for f in os.listdir('.'):
is_file = False
if os.path.isfile(f):
is_file = True
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:
print("[!] ERROR: Year not found for {}".format(f))
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 or 'DVDRip' in f:
quality = '480'
else:
quality = '?'
print("[-] WARN: Quality not found for {}".format(f))
if is_file:
new_name = '{} ({}) [{}]'.format(' '.join(title), year, quality)
os.system('mkdir "{}"'.format(new_name))
os.system('mv "{}" "{}"/'.format(f, new_name))
else:
new_name = '{} ({}) [{}]'.format(' '.join(title), year, quality)
os.system('mv "{}" "{}"'.format(f, new_name))
print("[+] {}\n\t=> {}".format(f, new_name))
print("\nFinalizing...")
os.system("chmod 755 -R *")
os.system("find . -iname *sample* -exec rm -rf {} \;")
os.system("find . -iname *.txt -exec rm -rf {} \;")
print("Finished!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment