Skip to content

Commit 97cb4aa

Browse files
committed
Added --album flag for album sorting option
1 parent 663beea commit 97cb4aa

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

python2.7/music-organizer.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,38 @@
2323
from mutagen.easyid3 import EasyID3
2424

2525
parser = argparse.ArgumentParser(
26-
description='''Organizes a music collection using tag information.
26+
description='''Organizes a music collection using tag information.
2727
The directory format is that the music collection consists of
2828
artist subdirectories, and there are 2 modes to operate on
2929
the entire collection or a single artist.
3030
All names are made lowercase and separated by dashes for easier
3131
navigation in a Linux filesystem.'''
32-
)
32+
)
3333
parser.add_argument('--delete-conflicts', action='store_true',
34-
dest='delete_conflicts',
35-
help='''If an artist has duplicate tracks with the same name,
34+
dest='delete_conflicts',
35+
help='''If an artist has duplicate tracks with the same name,
3636
delete them. Note this might always be best in case an
3737
artist has multiple versions. To keep multiple versions,
3838
fix the tag information.''')
3939
parser.add_argument('--ignore-multiple-artists', action='store_true',
40-
dest='ignore_multiple_artists',
41-
help='''This script will prompt for confirmation if an artist
40+
dest='ignore_multiple_artists',
41+
help='''This script will prompt for confirmation if an artist
4242
directory has songs with more than 2 different tags.
4343
This flag disables the confirmation and won't perform
4444
this check.''')
4545
parser.add_argument('--collection', action='store_true',
46-
help='''Operate in 'collection' mode and run 'artist' mode
46+
help='''Operate in 'collection' mode and run 'artist' mode
4747
on every subdirectory.''')
4848
parser.add_argument('--artist', action='store_true',
49-
help='''Operate in 'artist' mode and copy all songs to the
49+
help='''Operate in 'artist' mode and copy all songs to the
5050
root of the directory and cleanly format the names to
5151
be easily typed and navigated in a shell.''')
5252
parser.add_argument('--delete-unrecognized-extensions', action='store_true',
53-
dest='delete_unrecognized')
53+
dest='delete_unrecognized')
54+
parser.add_argument('--album', action='store_true',
55+
dest='album',
56+
help='''Adds album folder inside the artist folder to sort out
57+
albums''')
5458
args = parser.parse_args()
5559

5660
if args.collection and args.artist:
@@ -182,22 +186,29 @@ def song(filename):
182186
album = audio['album'][0].encode('ascii', 'ignore')
183187
print(" artist: " + artist)
184188
print(" title: " + title)
185-
print(" album: " + album)
189+
if args.album:
190+
print(" album: " + album)
186191
except:
187192
artist = None
188193
title = None
189-
album = None
194+
if args.album:
195+
album = None
190196
neatArtist = toNeat(artist)
191197
neatTitle = toNeat(title)
192-
neatAlbum = toNeat(album)
198+
if args.album:
199+
neatAlbum = toNeat(album)
193200
print(" neatArtist: " + neatArtist)
194201
print(" neatTitle: " + neatTitle)
195-
print(" neatAlbum: " + neatAlbum)
202+
if args.album:
203+
print(" neatAlbum: " + neatAlbum)
196204
if not os.path.isdir(neatArtist):
197205
os.mkdir(neatArtist)
198-
if not os.path.isdir(neatArtist + "/" + neatAlbum):
199-
os.mkdir(neatArtist + "/" + neatAlbum)
200-
newFullPath = os.path.join(neatArtist, neatAlbum, neatTitle + ext)
206+
if args.album:
207+
if not os.path.isdir(neatArtist + "/" + neatAlbum):
208+
os.mkdir(neatArtist + "/" + neatAlbum)
209+
newFullPath = os.path.join(neatArtist, neatAlbum, neatTitle + ext)
210+
else:
211+
newFullPath = os.path.join(neatArtist, neatTitle + ext)
201212
os.rename(filename, newFullPath)
202213

203214

0 commit comments

Comments
 (0)