Skip to content

Commit 117df85

Browse files
committed
Move songs from the top level of the collection to new artist directories.
1 parent 8e5d35c commit 117df85

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

python2.7/music-organizer.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def toNeat(s):
5959
return s
6060

6161
def artist(artistDir):
62-
print("Organizing '" + artistDir + "'.")
62+
print("Organizing artist '" + artistDir + "'.")
6363
if not args.ignore_multiple_artists:
6464
artists = set()
6565
for dirname, dirnames, filenames in os.walk(artistDir):
@@ -106,7 +106,7 @@ def artist(artistDir):
106106
sys.exit(-42)
107107

108108
neatTitle = toNeat(title)
109-
print(" neat-title: " + neatTitle)
109+
print(" neatTitle: " + neatTitle)
110110

111111
newFullPath = os.path.join(artistDir, neatTitle + ext)
112112
print(" newFullPath: " + newFullPath)
@@ -136,10 +136,35 @@ def artist(artistDir):
136136
for d in delete_dirs:
137137
shutil.rmtree(os.path.join(artistDir,d),ignore_errors=True)
138138

139-
def collection():
140-
for d in os.listdir("."):
141-
artist(d)
139+
def song(filename):
140+
print("Organizing song '" + filename + "'.")
141+
ext = os.path.splitext(filename)[1]
142+
try:
143+
audio = EasyID3(filename)
144+
artist = audio['artist'][0].encode('ascii', 'ignore')
145+
title = audio['title'][0].encode('ascii', 'ignore')
146+
print(" artist: " + artist)
147+
print(" title: " + title)
148+
except:
149+
artist = None
150+
title = None
151+
neatArtist = toNeat(artist)
152+
neatTitle = toNeat(title)
153+
print(" neatArtist: " + neatArtist)
154+
print(" neatTitle: " + neatTitle)
155+
if not os.path.isdir(neatArtist):
156+
os.mkdir(neatArtist)
157+
newFullPath = os.path.join(neatArtist,neatTitle+ext)
158+
os.rename(filename, newFullPath)
159+
os.chmod(newFullPath, 0644)
142160

143-
if args.artist: artist('.')
144-
else: collection()
161+
def collection():
162+
for f in os.listdir("."):
163+
if os.path.isdir(f): artist(f)
164+
elif os.path.isfile(f): song(f)
165+
166+
if args.artist:
167+
artist('.')
168+
else:
169+
collection()
145170
print("\nComplete!")

0 commit comments

Comments
 (0)