Created
August 16, 2011 18:28
-
-
Save leonardehrenfried/1149789 to your computer and use it in GitHub Desktop.
Cleaning the Amazon MP3 download folder
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/env python3 | |
import getpass,os,subprocess | |
def find_amazon_dir(): | |
username = getpass.getuser() | |
possible_dirs=["/Users/%s/Music/Amazon MP3"%username,] | |
for dir in possible_dirs: | |
if os.path.exists(dir): | |
return dir | |
#raise Exception("Amazon MP3 folder could not be found") | |
def get_subfolders(amazon_dir): | |
dirs=[] | |
for subdir in os.listdir(amazon_dir): | |
path="%s/%s" % (amazon_dir,subdir) | |
if os.path.isdir(path): | |
dirs.append(path) | |
return dirs | |
def process_folder(artist_folder): | |
artist_name=os.path.basename(artist_folder) | |
album_folders=get_subfolders(artist_folder) | |
for subfolder in album_folders: | |
album_name = os.path.basename(subfolder) | |
mp3_folder=(os.path.dirname(os.path.dirname(artist_folder))) | |
new_name="%s/%s - %s" % (mp3_folder, artist_name, album_name) | |
print("%s -> %s" % (subfolder, new_name)) | |
os.rename(subfolder, new_name) | |
print("Looking for Amazon MP3 directory...") | |
amazon_dir = find_amazon_dir() | |
print("...found it at %s"%amazon_dir) | |
for artist_folder in get_subfolders(amazon_dir): | |
process_folder(artist_folder) | |
subprocess.call(["rsync", "-av", "--progress", | |
"--ignore-existing", "--exclude=iTunes", '--exclude="Amazon MP3"', '--exclude=House', | |
"/Users/lenni/Music/","[email protected]:/volume1/public/Music/Albums/"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment