Skip to content

Commit 566c23b

Browse files
committed
Add padding in case a song's title has no spacing between special characters.
1 parent 9ea3c6d commit 566c23b

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

python2.7/music-organizer.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,21 @@
5151
# Maps a string such as 'The Beatles' to 'the-beatles'.
5252
def toNeat(s):
5353
s = s.lower().replace("&","and")
54-
s = re.sub(r"[()\[\],.'\"\\\?\#/\!\$\:]", "", s)
55-
s = re.sub(r"[ \*\_]", "-", s)
54+
55+
# Put spaces between and remove blank characters.
56+
blankCharsPad = r"()\[\],.\\\?\#/\!\$\:"
57+
blankCharsNoPad = r"'\""
58+
s = re.sub(r"([" + blankCharsPad + r"])([^ ])", "\\1 \\2", s)
59+
s = re.sub("[" + blankCharsPad + blankCharsNoPad + "]", "", s)
60+
61+
# Replace spaces with a single dash.
62+
s = re.sub(r"[ \*\_]+", "-", s)
5663
s = re.sub("-+", "-", s)
57-
search = re.search("[^0-9a-z\-\=]", s)
64+
s = re.sub("^-*", "", s)
65+
s = re.sub("-*$", "", s)
66+
67+
# Ensure the string is only alphanumeric with dashes.
68+
search = re.search("[^0-9a-z\-]", s)
5869
if search:
5970
print("Error: Unrecognized character in '" + s + "'")
6071
sys.exit(-42)

0 commit comments

Comments
 (0)