Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def indexer(folder):
- for idx,itm in enumerate(folder):
- print("{}: {}".format(idx, itm)) # print contents plus indices
- inp = int(input("Choice [0-{}]: ".format(len(folder)))) # choose index
- return inp
- def songindex(folder): # index chooser for MP3/M4A files
- files = [os.path.abspath(x) for x in os.listdir(folder) if x.endswith((".m4a", ".mp3"))] # only music files, return absolute paths
- names = [os.path.basename(x) for x in files] # get just filenames from absolute paths
- idx = indexer(names) # get selected index
- return files[idx]
- def dirindex(folder): # index chooser for directories
- folders = [os.path.abspath(x) for x in os.listdir(folder) if os.path.isdir(x)] # only folders, return absolute paths
- names = [os.path.basename(x) for x in folders] # get last component of folder name (i.e. artist/album)
- idx = indexer(names) # get selected index
- return folders[idx]
- music_dir = os.path.join(os.path.expanduser("~"), "Music") # C:\users\<yournamehere>\Music
- # Alternatively:
- # music_dir = os.path.join(os.path.expanduser("~"), "Music", "iTunes", "iTunes Media", "Music")
- os.chdir(music_dir)
- print("Please choose an artist")
- artist = dirindex(music_dir)
- os.chdir(artist)
- print("\nPlease choose an album")
- album = dirindex(artist)
- os.chdir(album)
- print("\nPlease choose a song")
- song = songindex(album)
- print("\nNow playing: {}".format(os.path.basename(song)))
- os.startfile(song)
Add Comment
Please, Sign In to add comment