def extract_new(self, direc): """ Iterating function, and inserting id, metadata and features to the collection. param: list of parameter dictionaries """ i = 0 for root, dirs, files in os.walk(direc): for file1 in files: i += 1 if file1[len(file1) - 3:len(file1)] == "wav": w = wopen(direc + file1, "r") # Exracting the file length with closing(w) as f: frame = f.getnframes() rate = f.getframerate() # Split the file name in order to use all the metadata meta = file1.split("-*-") # Launch the actual extraction features_dict = {} ii = 0 for x in self.parameters_list: features_dict.update( {ii: self.extract_features(direc + file1, x)}) ii += 1 dbfeat = self.parameter_name(features_dict) try: yea = meta[4][0:len(meta[4]) - 4] gen = meta[3] except: yea = None gen = meta[3][0:len(meta[3]) - 4] try: tit = meta[0] except: tit = None try: art = meta[1] except: art = None try: alb = meta[2] except: alb = None self.so.insert({ 'id': i, 'metadata': { 'title': tit, 'artist': art, 'album': alb, 'genre': gen, 'year': yea, 'length': frame / float(rate) }, 'features': dbfeat, }) w.close() print "Extraction successfully completed!"
def extract_new(self,direc): """ Iterating function, and inserting id, metadata and features to the collection. param: list of parameter dictionaries """ i = 0 for root,dirs,files in os.walk(direc): for file1 in files: i += 1 if file1[len(file1)-3:len(file1)] == "wav": w = wopen(direc+file1,"r") # Exracting the file length with closing(w) as f: frame = f.getnframes() rate = f.getframerate() # Split the file name in order to use all the metadata meta = file1.split("-*-") # Launch the actual extraction features_dict = {} ii = 0 for x in self.parameters_list: features_dict.update({ii:self.extract_features(direc+file1,x)}) ii += 1 dbfeat = self.parameter_name(features_dict) try: yea = meta[4][0:len(meta[4])-4] gen = meta[3] except: yea = None gen = meta[3][0:len(meta[3])-4] try: tit = meta[0] except: tit = None try: art = meta[1] except: art = None try: alb = meta[2] except: alb = None self.so.insert({ 'id':i, 'metadata': { 'title':tit, 'artist':art, 'album':alb, 'genre':gen, 'year':yea, 'length':frame/float(rate) }, 'features': dbfeat, }) w.close() print "Extraction successfully completed!"
def extract(self, direc): """ Iterating function, and inserting id, metadata and features to the collection. param: list of parameter dictionaries """ i = 0 for root, dirs, files in os.walk(direc): for file1 in files: if file1[len(file1)-3:] == "wav": i += 1 w = wopen(direc+file1, "r") # Exracting the file length with closing(w) as f: frame = f.getnframes() rate = f.getframerate() # Launch the actual extraction dbfeat = self.parameter_name(self.extract_features(direc+file1)) # Split the file name in order to use all the metadata meta = file1.split("-*-") # Assign the metadata informations if len(meta) == 5: tit = meta[0] art = meta[1] alb = meta[2] gen = meta[3] yea = meta[4][:len(meta[4])-4] elif len(meta) == 4: tit = meta[0] art = meta[1] alb = meta[2] gen = meta[3][:len(meta[3])-4] yea = '' if self.so.find({"metadata.title": tit}).count() == 0: # If this particular song's collection does not # exist, insert the dictionary song_dictionary_insert = { 'song_id': i, 'metadata': { 'title': tit, 'artist': art, 'album': alb, 'genre': gen, 'year': yea, 'length': frame/float(rate)}, 'features': dbfeat} self.so.insert(song_dictionary_insert) else: # If this particular song's collection already exists, # then only update the feature dictionary for k in dbfeat: for par in dbfeat[k][0]: a = "features."+k self.so.update({"metadata.title": tit, "metadata.artist": art, "metadata.album": alb}, {"$addToSet": {a: {par: dbfeat[k][0][par]}}}) w.close() print i print "Extraction successfully completed!"
def extract(self, direc): """ Iterating function, and inserting id, metadata and features to the collection. param: list of parameter dictionaries """ i = 0 for root, dirs, files in os.walk(direc): for file1 in files: if file1[len(file1)-3:] == "wav": i += 1 w = wopen(direc+file1, "r") # Exracting the file length with closing(w) as f: frame = f.getnframes() rate = f.getframerate() # Split the file name in order to use all the metadata meta = file1.split("-*-") # Launch the actual extraction dbfeat = self.parameter_name(self.extract_features(direc+file1)) if len(meta) == 5: tit = meta[0] art = meta[1] alb = meta[2] gen = meta[3] yea = meta[4][:len(meta[4])-4] elif len(meta) == 4: tit = meta[0] art = meta[1] alb = meta[2] gen = meta[3][:len(meta[3])-4] yea = '' # elif len(meta) == 1: # tit = meta[0][:len(meta[0])-4] # art, alb, gen, yea = '', '', '', '' # elif len(meta) == 2: # tit = meta[0] # art = meta[1][:len(meta[1])-4] # alb, gen, yea = '', '', '' # elif len(meta) == 3: # tit = meta[0] # art = meta[1] # alb = meta[2][:len(meta[2])-4] # gen, yea = '', '' if self.so.find({"metadata.title": tit}).count() == 0: song_dictionary_insert = { 'song_id': i, 'metadata': { 'title': tit, 'artist': art, 'album': alb, 'genre': gen, 'year': yea, 'length': frame/float(rate)}, 'features': dbfeat} self.so.insert(song_dictionary_insert) else: for k in dbfeat: for par in dbfeat[k][0]: a = "features."+k self.so.update({"metadata.title": tit, "metadata.artist": art, "metadata.album": alb}, {"$addToSet": {a: {par: dbfeat[k][0][par]}}}) w.close() print i print "Extraction successfully completed!"