Okay, well I have to say I am completely stumped where to go from here. I am writing a media player and I am currently working on song indexing. I have figured out how to extract the song name and its complete path using os.walk(); however, I have no idea how I would find the artist or album of the song. I have an idea, but let me show you my code first.
#!/usr/bin/python
from os import walk
from os.path import join
from os.path import splitext
class Indexer:
def __init__(self):
self.allFiles = {}
for base, directoryList, fileList in walk("/home/foo/Music"):
if fileList != []: #Make sure the entry isn't empty
for file in fileList:
for acceptedEnding in [".mp3", ".wav"]:
if splitext(file)[1] == acceptedEnding:
fullPath = join(base, file)
self.allFiles[file] = fullPath
def returnFiles(self):
return self.allFiles
myIndexer = Indexer()
fileDict = myIndexer.returnFiles()
So let me give a possible idea if anybody could tell me how to do this. Let's say you have a directory such as so: "/home/foo/Music/". Generally, songs by "The Eagles" in the album "Hell Freezes Over" would be located in the directory "/home/foo/Music/The Eagles/Hell Freezes Over/<songname>". How could I extract the "/The Eagles/Hell Freezes Over" part in order to get the artist and album?
Or if anybody has a better/more efficient method, that would be great!
Thanks in advance.
EDIT: I am of course still learning, and I noticed that my code is not quite easy on the eyes. Any ideas how I could improve its readability?