-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiletag.py
More file actions
executable file
·54 lines (43 loc) · 1.5 KB
/
Copy pathfiletag.py
File metadata and controls
executable file
·54 lines (43 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python2.7
import argparse
import re
import os
parser = argparse.ArgumentParser(description='Simple command-line filename tagger')
parser.add_argument('-5', action="store_true", dest="fiveStars", default=False,help="set rating to 5 star")
parser.add_argument('-4', action="store_true", dest="fourStars", default=False,help="set rating to 4 star")
parser.add_argument('-3', action="store_true", dest="threeStars", default=False,help="set rating to 3 star")
parser.add_argument('-0', action="store_true", dest="removeStars", default=False,help="remove rating")
parser.add_argument('-t', action="store", dest="newTitle", default=False,help="change title")
parser.add_argument('file')
params = parser.parse_args()
rating=-1
update=False
if params.fiveStars:
rating="5"
if params.fourStars:
rating="4"
if params.threeStars:
rating="3"
if params.removeStars:
rating=""
else:
rating= "_%ss" %(rating)
if params.newTitle:
newTitle=params.newTitle
update=True
if rating >= 0:
match = re.search("(.*)\.(.*)$", params.file)
oldTitle = match.group(1)
extension = match.group(2)
newTitle=re.sub("[,!\[\]'\(\)]","",oldTitle)
newTitle=re.sub(" ","_",newTitle)
newTitle=re.sub("_[1-5]s$","",newTitle)
newTitle="%s%s.%s" %(newTitle, rating, extension)
update=True
if update:
try:
os.rename(params.file, newTitle)
except:
print "File %s not found" %(params.file)
os.exit(1)
print "Changed from %s to %s" %(params.file, newTitle)