def FindMusic(my_dir, callback, only_artist_str=''): '''Given a directory, will populate a list with all the *.mp3 files found in that directory (recursively) and read their current tag info. Usually the first step in any use case. my_dir -> directory to search for *.mp3 callback -> a function pointer funct(str) used to return status info only_artist_str -> optional tag to only find artists matching this string returns -> mp3_list, a list of MP3File objects ''' mp3_list = [] fileio.MP3Finder(my_dir, mp3_list, callback) new_mp3_list = [] for mp3_file in mp3_list: fn = mp3_file.orig_track.path is_dup = mp3_file.is_dup callback('processing: %s' % fn) # load up the id3 tags from the mp3s in our xml list try: id3_reader = fileio.Id3tool(fn) orig_mp3 = Track(_artist=id3_reader.readTag('artist'), _name=id3_reader.readTag('title'), _album=id3_reader.readTag('album'), _track_num=id3_reader.readTag('tracknumber'), _path=fn) if only_artist_str: srch = strtool.sanitizeTrackStr(only_artist_str) artist = strtool.sanitizeTrackStr(mp3_obj.orig_track.artist) if not re.search(srch, artist, re.IGNORECASE): mylog.DBG1(6,'skipping artist %s for match %s' % (srch, artist)) continue new_mp3_list.append(MP3File(orig_track=orig_mp3.copy(), my_path=fn, is_dup_flag=is_dup)) except: mylog.ERR('ID3 read failed on \'%s\'\n' % fn) new_mp3_list.append(MP3File(my_path=fn, is_dup_flag=is_dup)) del mp3_list return new_mp3_list
def __init__(self, mp3_file_obj): AbsXMLNode.__init__(self) # setup a tiny XML doc of one node that will be appended to bigger one later mp3_node = self.elm.createElement('mp3') for i,node_name in enumerate(MP3File.getFieldLabels()): node_obj = self.elm.createElement(strtool.sanitizeTrackStr(node_name)) txt = unicode(mp3_file_obj.getFieldList()[i]).encode('utf-8').strip() node_val_txt = self.elm.createTextNode(txt) node_obj.appendChild(node_val_txt) mp3_node.appendChild(node_obj) self.elm.appendChild(mp3_node)