Skip to content

Commit 8557086

Browse files
committed
dont suffix rename if new name is same as old
1 parent 00efdf3 commit 8557086

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

idntag

+15-14
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,25 @@ def identify_and_update_file(path, keep_name, uselib):
100100
song.tags["TITLE"] = [title]
101101
song.save()
102102

103-
newpath = path
103+
olddir, oldfile = os.path.split(path)
104+
oldfile, oldext = os.path.splitext(path)
105+
newbase = olddir + "/" + cleanstr(artist, 100) + "-" + cleanstr(title, 100)
104106
if not keep_name:
105-
olddir, oldfile = os.path.split(path)
106-
oldfile, oldext = os.path.splitext(path)
107-
newbase = olddir + "/" + cleanstr(artist, 100) + "-" + cleanstr(title, 100)
108107
newpath = newbase + oldext
109-
cnt = 0
110-
while os.path.isfile(newpath):
111-
if cnt > 1000:
112-
print("FAIL : max number of conflicting file names reached")
113-
return False
108+
if newpath != path:
109+
cnt = 0
110+
while os.path.isfile(newpath):
111+
if cnt > 1000:
112+
print("FAIL : max number of conflicting file names reached")
113+
return False
114114

115-
cnt = cnt + 1
116-
newpath = newbase + "_" + str(cnt) + oldext
115+
cnt = cnt + 1
116+
newpath = newbase + "_" + str(cnt) + oldext
117117

118-
os.rename(path, newpath)
118+
os.rename(path, newpath)
119+
path = newpath
119120

120-
print("OK : " + newpath)
121+
print("OK : " + path)
121122
return True
122123

123124

@@ -142,7 +143,7 @@ def main():
142143
"Artist_Name-Track_Name.")
143144
parser.add_argument("-k", "--keepname", action="store_true", help="keep original filename")
144145
parser.add_argument("-l", "--uselib", action="store_true", help="use chromaprint lib instead of tools")
145-
parser.add_argument("-v", "--version", action='version', version='%(prog)s v1.10')
146+
parser.add_argument("-v", "--version", action='version', version='%(prog)s v1.11')
146147
parser.add_argument('path', nargs='+', help='path of a file or directory')
147148
args = parser.parse_args()
148149

idntag.1

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
2-
.TH IDNTAG "1" "November 2022" "idntag v1.10" "User Commands"
2+
.TH IDNTAG "1" "December 2022" "idntag v1.11" "User Commands"
33
.SH NAME
44
idntag \- automatically identify, tag and rename audio files
55
.SH DESCRIPTION
@@ -12,7 +12,7 @@ Artist_Name\-Track_Name.
1212
.TP
1313
path
1414
path of a file or directory
15-
.SS "optional arguments:"
15+
.SS "options:"
1616
.TP
1717
\fB\-h\fR, \fB\-\-help\fR
1818
show this help message and exit

0 commit comments

Comments
 (0)