hey every1, im a noob pythoneer.. i wanted to change the names of all music files using their metadata obtained from mminfo utility. I came up with the following hideous looking code..
import os
os.chdir(raw_input('plz enter directory name: '))
lst=os.listdir(os.getcwd())
class process():
def getmetadata(self,filename):
command='mminfo %s|grep artist>temp.txt'%filename;#print command
os.system(command)
q=file('temp.txt');self.artist=self.get(q.read());q.close()
command='mminfo %s|grep title>temp.txt'%filename
os.system(command)
q=file('temp.txt');self.title=self.get(q.read());q.close()
def __init__(self,filename):
self.getmetadata(filename)
os.rename(filename,self.artist+'_'+self.title+'.mp3')
def get(self,s):#this returns the string after ':' in s
num=s.find(':')
return s[num+1:]
#print lst
for i in lst:
#print i
instance=process(str(i))
#os.remove('temp.txt')
yea.. u guessed right.. it doesn't work.. i checked the temp.txt.. it's not retrieving the proper data using the 'command'.. its always a blank file..
i think there has to be a better way to code the getmetadata() func. The reason im using the intermeditate temp.txt file is because i cant just write
t=os.system('mminfo file.mp3')
this just assigns either 0 or 1 to t and not the actual output from the command.
Plz tell me what is rong with this code.. also if you can tell me an alternate way to code getmetadata() plz do.. it seems ive probably coded the least efficient func of all time.. it takes a good 6 seconds to work on a dir with just 10 files!!:(