Last active
August 29, 2015 14:08
-
-
Save yadomi/4388f85eeba2b5994c2e to your computer and use it in GitHub Desktop.
Utility to sanitize some movie filenames
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf8 -*- | |
"""Utility to sanitize some warez movies filename""" | |
__author__ = "Felix Yadomi" | |
__version__ = "0.0.3" | |
__email__ = "[email protected]" | |
import sys, os, re | |
from titlecase import titlecase | |
def sanitize(filename): | |
title = [] | |
warez = ['truefrench','fansub','bluray','720', '720p', 'x264','french', 'fr', 'divx','hdcam','xvid','appz','bdrip','board','cam','dvd','dvd-r','dvdrip','dupecheck','fake','fs','gamez','hddvd','hddvdrip','hdrip','hdtv','pdtv','internal','int','keygen','leecher','limited','nuke','proper','repack','retail','rip','rip','screener','serial','subforced','hardsub','stv','telecine','telesync','tvrip','unrated','vhsrip','vo','vost','vostfr','workprint','french','wp','subbed','unsubbed', 'r5', 'r6', 'md'] | |
filename = re.sub('[\(\[].*?[\)\]]', '', os.path.splitext(filename)[0].strip().lower()) | |
match = re.search('\d{4}', filename) | |
year = match.group(0) if match else False | |
filename = re.sub('[^\w]|[\_]', ' ', filename).split() | |
filename.remove(year) | |
for word in filename: | |
if word not in warez: | |
title.append(word) | |
if year: | |
title.append( '(' + year + ')' ) | |
title = ' '.join(title) | |
return titlecase(title) | |
def usage(): | |
print('usage: ' + sys.argv[0] + ' target [--dry]') | |
args = sys.argv[1:] | |
if ( len(args) > 2) or len(args) < 1: | |
usage() | |
sys.exit() | |
f = os.path.split(sys.argv[1]) | |
if not f[0]: | |
filepath = '.' | |
else: | |
filepath = f[0] | |
filename = os.path.splitext(os.path.basename(sys.argv[1]))[0] | |
extension = os.path.splitext(sys.argv[1])[1] | |
newname = sanitize(filename) | |
print(newname + extension) | |
if '--dry' not in sys.argv: | |
os.rename(filepath + '/' + filename + extension, filepath + '/' + newname + extension) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment