def process_files(path, stats): """ Recurse down directory path and process each audio file. """ counter = 0 for root, dirs, files in os.walk(path): for f in files: # We maintain a counter to keep file names unique counter += 1 stats.files_read += 1 filename = os.path.join(root, f) try: audio = File(filename, easy=True) except Exception, e: stats.add_type_failure(filename) continue if not audio: stats.add_parse_failure(filename) continue test_tags = ['artist', 'album', 'title'] missing_tags = [] for tag in test_tags: if not audio.has_key(tag): missing_tags.append(tag) tracknumber = audio.get('tracknumber', [None])[0] artist = sanitize_path(audio.get('artist', ['No Artist'])[0]) album = sanitize_path(audio.get('album', ['No Album'])[0]) title = sanitize_path( audio.get('title', ["%d_%s" % (counter, f)])[0]) if tracknumber: try: tracknumber = int(re.sub(r'.*?(\d+).*', r'\1', tracknumber)) except ValueError, e: tracknumber = None pass (_, extension) = os.path.splitext(filename) if not tracknumber: newname = os.path.join(artist, album, title + extension) else: newname = os.path.join( artist, album, "%02d - %s%s" % (tracknumber, title, extension)) if len(missing_tags) > 0: pretty_missing_tags = str.join(", ", missing_tags) stats.add_missing_tag_failure( filename + ": " + pretty_missing_tags, newname) stats.add_track(filename, newname, artist, album, tracknumber, title)
def process_files(path, stats): """ Recurse down directory path and process each audio file. """ counter = 0 for root, dirs, files in os.walk(path): for f in files: # We maintain a counter to keep file names unique counter += 1 stats.files_read += 1 filename = os.path.join(root, f) try: audio = File(filename, easy=True) except Exception, e: stats.add_type_failure(filename) continue if not audio: stats.add_parse_failure(filename) continue test_tags = ['artist', 'album', 'title'] missing_tags = [] for tag in test_tags: if not audio.has_key(tag): missing_tags.append(tag) tracknumber = audio.get('tracknumber', [None])[0] artist = sanitize_path(audio.get('artist', ['No Artist'])[0]) album = sanitize_path(audio.get('album', ['No Album'])[0]) title = sanitize_path(audio.get('title', ["%d_%s" % (counter, f)])[0]) if tracknumber: try: tracknumber = int(re.sub(r'.*?(\d+).*', r'\1', tracknumber)) except ValueError, e: tracknumber = None pass (_, extension) = os.path.splitext(filename) if not tracknumber: newname = os.path.join(artist, album, title + extension) else: newname = os.path.join( artist, album, "%02d - %s%s" % (tracknumber, title, extension)) if len(missing_tags) > 0: pretty_missing_tags = str.join(", ", missing_tags) stats.add_missing_tag_failure( filename + ": " + pretty_missing_tags, newname) stats.add_track(filename, newname, artist, album, tracknumber, title)
image.write('htdocs/images/'+uuid+'.jpg') unlink(f.name) if len(sys.argv) > 1: fname = sys.argv[1] uuid = sys.argv[2] else: exit(0) data = {} audio = File(fname, easy=True) if hasattr(audio, 'mime') == False: exit(0) for f in set(['title','artist','album']): if audio.has_key(f): data[f] = escape(audio[f][0]) data['length'] = int(floor(audio.info.length*1000)) # now try to extract the cover. audio = File(fname, easy=False) # each filetype has a different method if 'audio/vorbis' in audio.mime or 'audio/x-flac' in audio.mime: for f in set(['title','artist','album']): if audio.has_key(f): data[f] = escape(audio[f][0]) if audio.has_key('pictures'): data['cover'] = uuid+'.jpg'; extractCover(uuid, audio['pictures'][0]) if 'audio/aac' in audio.mime: if audio.has_key('covr'):