|
23 | 23 | from mutagen.easyid3 import EasyID3 |
24 | 24 |
|
25 | 25 | parser = argparse.ArgumentParser( |
26 | | - description='''Organizes a music collection using tag information. |
| 26 | + description='''Organizes a music collection using tag information. |
27 | 27 | The directory format is that the music collection consists of |
28 | 28 | artist subdirectories, and there are 2 modes to operate on |
29 | 29 | the entire collection or a single artist. |
30 | 30 | All names are made lowercase and separated by dashes for easier |
31 | 31 | navigation in a Linux filesystem.''' |
32 | | -) |
| 32 | + ) |
33 | 33 | 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, |
36 | 36 | delete them. Note this might always be best in case an |
37 | 37 | artist has multiple versions. To keep multiple versions, |
38 | 38 | fix the tag information.''') |
39 | 39 | 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 |
42 | 42 | directory has songs with more than 2 different tags. |
43 | 43 | This flag disables the confirmation and won't perform |
44 | 44 | this check.''') |
45 | 45 | 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 |
47 | 47 | on every subdirectory.''') |
48 | 48 | 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 |
50 | 50 | root of the directory and cleanly format the names to |
51 | 51 | be easily typed and navigated in a shell.''') |
52 | 52 | 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''') |
54 | 58 | args = parser.parse_args() |
55 | 59 |
|
56 | 60 | if args.collection and args.artist: |
@@ -182,22 +186,29 @@ def song(filename): |
182 | 186 | album = audio['album'][0].encode('ascii', 'ignore') |
183 | 187 | print(" artist: " + artist) |
184 | 188 | print(" title: " + title) |
185 | | - print(" album: " + album) |
| 189 | + if args.album: |
| 190 | + print(" album: " + album) |
186 | 191 | except: |
187 | 192 | artist = None |
188 | 193 | title = None |
189 | | - album = None |
| 194 | + if args.album: |
| 195 | + album = None |
190 | 196 | neatArtist = toNeat(artist) |
191 | 197 | neatTitle = toNeat(title) |
192 | | - neatAlbum = toNeat(album) |
| 198 | + if args.album: |
| 199 | + neatAlbum = toNeat(album) |
193 | 200 | print(" neatArtist: " + neatArtist) |
194 | 201 | print(" neatTitle: " + neatTitle) |
195 | | - print(" neatAlbum: " + neatAlbum) |
| 202 | + if args.album: |
| 203 | + print(" neatAlbum: " + neatAlbum) |
196 | 204 | if not os.path.isdir(neatArtist): |
197 | 205 | 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) |
201 | 212 | os.rename(filename, newFullPath) |
202 | 213 |
|
203 | 214 |
|
|
0 commit comments