Skip to content

Commit 40536f7

Browse files
committed
Merge branch 'method'
Conflicts: python2.7/music-organizer.py
2 parents 7130ce4 + d2baac0 commit 40536f7

1 file changed

Lines changed: 63 additions & 14 deletions

File tree

python2.7/music-organizer.py

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ def toNeat(s):
102102
return s
103103

104104

105-
def artist(artistDir):
106-
print("Organizing artist '" + artistDir + "'.")
105+
def artist():
106+
print("Organizing artist")
107107
if not args.ignore_multiple_artists:
108108
artists = set()
109-
for dirname, dirnames, filenames in os.walk(artistDir):
109+
for dirname, dirnames, filenames in os.walk("."):
110+
print "Random test"
110111
# Make sure there aren't a lot of different artists
111112
# in case this was called from the wrong directory.
112113
for filename in filenames:
@@ -119,10 +120,8 @@ def artist(artistDir):
119120

120121
if len(artists) > 2:
121122
while True:
122-
print("Warning: More than 2 artists found in '{}'.".format(
123-
artistDir))
124-
print("This will move all songs to the '{}' directory.".format(
125-
artistDir))
123+
print("Warning: More than 2 artists found in '{}'.".format("."))
124+
print("This will move all songs to the '{}' directory.".format("."))
126125
print("Continue? yes/no")
127126
choice = raw_input().lower()
128127
valid = {"yes": True, "y": True, "no": False, "n": False}
@@ -134,13 +133,14 @@ def artist(artistDir):
134133
sys.exit(-1)
135134

136135
delete_dirs = []
137-
for dirname, dirnames, filenames in os.walk(artistDir):
136+
for dirname, dirnames, filenames in os.walk("."):
138137
# Move all the files to the root directory.
139138
for filename in filenames:
139+
fullPath = os.path.join(dirname, filename)
140+
song(fullPath)
140141
ext = os.path.splitext(filename)[1]
141-
#if ext == ".mp3":
142+
'''
142143
if ext in (".mp3" , ".ogg"):
143-
fullPath = os.path.join(dirname, filename)
144144
print("file: " + str(fullPath))
145145
146146
try:
@@ -203,14 +203,14 @@ def artist(artistDir):
203203
print("Error: Unrecognized file extension in '{}'.".format(
204204
filename))
205205
sys.exit(-42)
206+
'''
206207

207208
# Delete all subdirectories.
208209
for subdirname in dirnames:
209210
delete_dirs.append(subdirname)
210211

211212
for d in delete_dirs:
212-
shutil.rmtree(os.path.join(artistDir, d), ignore_errors=True)
213-
213+
shutil.rmtree(os.path.join(".", d), ignore_errors=True)
214214

215215
def song(filename):
216216
if filename[0] == '.':
@@ -266,7 +266,6 @@ def song(filename):
266266
newFullPath = os.path.join(neatArtist, neatTitle + ext)
267267
os.rename(filename, newFullPath)
268268

269-
270269
def collection():
271270
for f in glob.glob('*'):
272271
if os.path.isdir(f):
@@ -275,8 +274,58 @@ def collection():
275274
elif os.path.isfile(f):
276275
song(f)
277276

277+
def song(filename):
278+
# if filename[0] == '.':
279+
# print("Ignoring dotfile: '{}'".format(filename))
280+
# return
281+
print("Organizing song '" + filename + "'.")
282+
ext = os.path.splitext(filename)[1]
283+
if ext in (".mp3" , ".ogg"):
284+
try:
285+
if ext == ".mp3":
286+
audio = EasyID3(filename)
287+
elif ext == ".ogg":
288+
audio = OggVorbis(filename)
289+
print audio
290+
artist = audio['artist'][0].encode('ascii', 'ignore')
291+
title = audio['title'][0].encode('ascii', 'ignore')
292+
album = audio['album'][0].encode('ascii', 'ignore')
293+
if args.numbering:
294+
tracknumber = audio['tracknumber'][0].encode('ascii', 'ignore')
295+
print(" artist: " + artist)
296+
print(" title: " + title)
297+
if args.album:
298+
print(" album: " + album)
299+
except:
300+
artist = None
301+
title = None
302+
if args.album:
303+
album = None
304+
if args.numbering:
305+
tracknumber = None
306+
neatArtist = toNeat(artist)
307+
if args.numbering:
308+
neatTitle = tracknumber + ".-" + toNeat(title)
309+
else:
310+
neatTitle = toNeat(title)
311+
if args.album:
312+
neatAlbum = toNeat(album)
313+
print(" neatArtist: " + neatArtist)
314+
print(" neatTitle: " + neatTitle)
315+
if args.album:
316+
print(" neatAlbum: " + neatAlbum)
317+
if not os.path.isdir(neatArtist):
318+
os.mkdir(neatArtist)
319+
if args.album:
320+
if not os.path.isdir(neatArtist + "/" + neatAlbum):
321+
os.mkdir(neatArtist + "/" + neatAlbum)
322+
newFullPath = os.path.join(neatArtist, neatAlbum, neatTitle + ext)
323+
else:
324+
newFullPath = os.path.join(neatArtist, neatTitle + ext)
325+
os.rename(filename, newFullPath)
326+
278327
if args.artist:
279-
artist('.')
328+
artist()
280329
else:
281330
collection()
282331
print("\nComplete!")

0 commit comments

Comments
 (0)