Created
October 18, 2012 03:01
-
-
Save frewsxcv/3909641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
import os | |
import mutagen | |
def getinfo(song): | |
artist = "Unknown" | |
if song.has_key("ALBUMARTIST"): | |
artist = song.get("ALBUMARTIST").pop() | |
elif song.has_key("WM/AlbumArtist"): | |
artist = song.get("WM/AlbumArtist").pop().value | |
elif song.has_key("TPE2"): | |
artist = song.get("TPE2").text.pop() | |
elif song.has_key("ARTIST"): | |
artist = song.get("ARTIST").pop() | |
album = "Unknown" | |
if song.has_key("ALBUM"): | |
album = song.get("ALBUM").pop() | |
elif song.has_key("WM/AlbumTitle"): | |
album = song.get("WM/AlbumTitle").pop().value | |
elif song.has_key("TALB"): | |
album = song.get("TALB").text.pop() | |
title = "Unknown" | |
if song.has_key("TITLE"): | |
title = song.get("TITLE").pop() | |
elif song.has_key("Title"): | |
title = song.get("Title").pop() | |
elif song.has_key("TIT2"): | |
title = song.get("TIT2").text.pop() | |
return artist, album, title | |
for file in os.listdir("inbound"): | |
inbound = os.path.join("inbound", file) | |
song = mutagen.File(inbound) | |
artist, album, title = getinfo(song) | |
artist_dir = os.path.join("music", artist) | |
if not os.path.isdir(artist_dir): | |
os.mkdir(artist_dir) | |
album_dir = os.path.join(artist_dir, album) | |
if not os.path.isdir(album_dir): | |
os.mkdir(album_dir) | |
ext = os.path.splitext(file)[-1] | |
os.rename(inbound, os.path.join(album_dir, title, ext)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment