Revision dc9a1b9e
Added by dsorber almost 12 years ago
| software/renamer/pic_renamer.py | ||
|---|---|---|
|
import os
|
||
|
import random
|
||
|
import sys
|
||
|
|
||
|
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
|
||
|
|
||
|
def make_new_filename(length=8):
|
||
|
new_filename = []
|
||
|
for idx in xrange(length):
|
||
|
new_filename.append(random.choice(chars))
|
||
|
new_filename.extend(['.', 'j', 'p', 'g'])
|
||
|
return ''.join(new_filename)
|
||
|
|
||
|
def main():
|
||
|
""" This script is intended to rename .jpg files to a randomly selected
|
||
|
8 character name. It could easily be extended to deal with other types
|
||
|
of files at some point.
|
||
|
|
||
|
USAGE:
|
||
|
|
||
|
python pic_renamer.py <pictures_directory>
|
||
|
"""
|
||
|
|
||
|
if len(sys.argv) < 2:
|
||
|
print 'ERROR: not enough arguments specified'
|
||
|
return -1
|
||
|
|
||
|
dir_path = sys.argv[1]
|
||
|
|
||
|
for filename in os.listdir(dir_path):
|
||
|
if filename.endswith('.jpg') or filename.endswith('.jpeg'):
|
||
|
old_full_path = os.path.join(dir_path, filename)
|
||
|
new_filename = make_new_filename()
|
||
|
new_file_path = os.path.join(dir_path, new_filename)
|
||
|
|
||
|
os.rename(old_full_path, new_file_path)
|
||
|
|
||
|
print '{:s} - renaming - {:s}'.format(filename, new_filename)
|
||
|
else:
|
||
|
print '{:s} - skipping'.format(filename)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
sys.exit(main())
|
||
| software/renamer/renamer.py | ||
|---|---|---|
|
import os
|
||
|
import re
|
||
|
import sys
|
||
|
|
||
|
def main():
|
||
|
|
||
|
if len(sys.argv) < 3:
|
||
|
print 'Not enough arguments specified!'
|
||
|
return
|
||
|
|
||
|
show_name = sys.argv[1]
|
||
|
directory = sys.argv[2]
|
||
|
|
||
|
show_name = show_name.replace(' ', '\.')
|
||
|
|
||
|
for filename in os.listdir(directory):
|
||
|
m = re.match("^(%s)\.S(\d+)E(\d+)\.(.*)\.(\w{3})$" % show_name, filename, re.IGNORECASE)
|
||
|
if m:
|
||
|
new_name = '%s - S%sE%s.%s' % (show_name.replace('\.', ' '),
|
||
|
m.group(2), m.group(3), m.group(5).lower())
|
||
|
|
||
|
print '%s --- MATCH: %s' % (filename, new_name)
|
||
|
os.rename(os.path.join(directory, filename),
|
||
|
os.path.join(directory, new_name))
|
||
|
else:
|
||
|
print filename
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
sys.exit(main())
|
||
| software/renamer/show_renamer.py | ||
|---|---|---|
|
import os
|
||
|
import re
|
||
|
import sys
|
||
|
|
||
|
def main():
|
||
|
|
||
|
if len(sys.argv) < 3:
|
||
|
print 'Not enough arguments specified!'
|
||
|
return
|
||
|
|
||
|
show_name = sys.argv[1]
|
||
|
directory = sys.argv[2]
|
||
|
|
||
|
show_name = show_name.replace(' ', '\.')
|
||
|
|
||
|
for filename in os.listdir(directory):
|
||
|
m = re.match("^(%s)\.S(\d+)E(\d+)\.(.*)\.(\w{3})$" % show_name, filename, re.IGNORECASE)
|
||
|
if m:
|
||
|
new_name = '%s - S%sE%s.%s' % (show_name.replace('\.', ' '),
|
||
|
m.group(2), m.group(3), m.group(5).lower())
|
||
|
|
||
|
print '%s --- MATCH: %s' % (filename, new_name)
|
||
|
os.rename(os.path.join(directory, filename),
|
||
|
os.path.join(directory, new_name))
|
||
|
else:
|
||
|
print filename
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
sys.exit(main())
|
||
Adding a picture renaming script. It's somewhat crude right now I should make it somewhat better at some point.