# Copyright (c) 2004-5 Marek Hnilica. All rights reserved. # Module used for getting time & bitrate info of mp3 files. # Distributed under GPL version 2, or (at your option) later import mp3new,mp3old def halfen(): mp3info['bitrate']=int(mp3info['bitrate']*2) mp3info['vbrrate']=mp3info['bitrate'] mp3info['time']=int(mp3info['time']/2) def detect_mp3(filename): try: global mp3info mp3info=mp3new.detect_mp3(filename) if mp3info==0: raise IOError elif mp3info['layer']==2: try: old=mp3old.detect_mp3(filename) ratio=float(old['time'])/float(mp3info['time']) if old==0 or ((ratio<1.1) and (ratio>0.9)): raise IOError except: return mp3info return old elif mp3info['version']==2.5: # In this case we want to make sure that it really is 2.5 as mp3new have some # problems and sometimes detects files as 2.5 even when they're not. If it # was the case, then do not return result of mp3new, but rather trust mp3old. # Debug point could be fact, that if "if not newmp3['mpeg25']:" returns true, # eg. track isn't mpeg25, than: # mp3info['correct_time']=mp3info['time']/(newmp3['bitrate']/mp3info['bitrate']) newmp3=mp3old.detect_mp3(filename) if not newmp3==0: if not newmp3['mpeg25']: return newmp3 if mp3info['vbr']: halfen() elif mp3info['vbr'] and mp3info['version']!=1: halfen() except: try: mp3info=mp3old.detect_mp3(filename) if mp3info==0: raise IOError except: return 0 return mp3info