def enable_database(prompt=True): f = False if database_exists() and db_is_enabled(): f = True if database_exists() and not db_is_enabled(): db = dr_database_singletone().get() f = db.is_db_valid() if not f: dbp = get_db_path() dest_file = dbp + ".de_save" os.rename(dbp, dest_file) else: f = True if not database_exists(): if prompt: (db_path, coll_dir) = local_dr_database_configure() else: db_path = os.path.split(get_db_path())[0] coll_dir = get_collection_dir() try: os.makedirs(db_path) except: pass db_path += "/dr14_database.db" set_db_path(db_path) set_collection_dir(coll_dir) print_msg("Preparing database .... ") db = dr_database_singletone().get() db.build_database() f = db.is_db_valid() if f: enable_db(True) print_msg( "The local DR database is ready and enabled! It is located in the file: %s " % get_db_path()) else: print_err( "The building procedure of the database has failed ... retry ") return
def enable_database( prompt=True ): f = False if database_exists() and db_is_enabled() : f = True if database_exists() and not db_is_enabled() : db = dr_database_singletone().get() f = db.is_db_valid() if not f : dbp = get_db_path() dest_file = dbp + ".de_save" os.rename( dbp , dest_file ) else : f = True if not database_exists() : if prompt : ( db_path , coll_dir ) = local_dr_database_configure() else : db_path = os.path.split( get_db_path() )[0] coll_dir = get_collection_dir() try: os.makedirs( db_path ) except : pass db_path += "/dr14_database.db" set_db_path( db_path ) set_collection_dir( coll_dir ) print_msg( "Preparing database .... " ) db = dr_database_singletone().get() db.build_database() f = db.is_db_valid() if f : enable_db( True ) print_msg( "The local DR database is ready and enabled! It is located in the file: %s " % get_db_path() ) else : print_err( "The building procedure of the database has failed ... retry " ) return
def write_to_local_dr_database(self, drm): db = dr_database_singletone().get() db.open_insert_session() album_title = drm.meta_data.get_album_title() if album_title == None: (head, album_title) = os.path.split(drm.dir_name) album_sha1 = drm.meta_data.get_album_sha1() album_artist = drm.meta_data.get_album_artist() db.insert_album(album_sha1, album_title, int(drm.dr14), disk_nr=drm.meta_data.get_disk_nr(), artist=album_artist[0]) for i in range(len(drm.res_list)): curr_file_name = drm.res_list[i]['file_name'] if drm.meta_data.track_unreadable_failure(curr_file_name): continue track_sha1 = drm.res_list[i]['sha1'] title = drm.meta_data.get_value(curr_file_name, 'title') dr = drm.res_list[i]['dr14'] rms = drm.res_list[i]['dB_rms'] peak = drm.res_list[i]['dB_peak'] duration = drm.meta_data.get_value(curr_file_name, 'duration') size = drm.meta_data.get_value(curr_file_name, 'size') bit = drm.meta_data.get_value(curr_file_name, 'bit') bitrate = drm.meta_data.get_value(curr_file_name, 'bitrate') sampling_rate = drm.meta_data.get_value(curr_file_name, 'sampling_rate') codec = drm.meta_data.get_value(curr_file_name, 'codec') artist = drm.meta_data.get_value(curr_file_name, 'artist') genre = drm.meta_data.get_value(curr_file_name, 'genre') date = drm.meta_data.get_value(curr_file_name, 'date') track_nr = drm.meta_data.get_value(curr_file_name, 'track_nr') if title == None: title = curr_file_name db.insert_track(track_sha1, title, dr, rms, peak, duration, codec, bit, bitrate, sampling_rate, album_sha1, artist, genre, date, track_nr, size) db.commit_insert_session()
def write_to_local_dr_database( self , drm ): db = dr_database_singletone().get() db.open_insert_session() album_title = drm.meta_data.get_album_title() if album_title == None : ( head , album_title ) = os.path.split( drm.dir_name ) album_sha1 = drm.meta_data.get_album_sha1() album_artist = drm.meta_data.get_album_artist() db.insert_album( album_sha1 , album_title , int(drm.dr14) , disk_nr=drm.meta_data.get_disk_nr() , artist=album_artist[0] ) for i in range( len( drm.res_list ) ) : curr_file_name = drm.res_list[i]['file_name'] if drm.meta_data.track_unreadable_failure( curr_file_name ): continue track_sha1 = drm.res_list[i]['sha1'] title = drm.meta_data.get_value( curr_file_name , 'title' ) dr = drm.res_list[i]['dr14'] rms = drm.res_list[i]['dB_rms'] peak = drm.res_list[i]['dB_peak'] duration = drm.meta_data.get_value( curr_file_name , 'duration') size = drm.meta_data.get_value( curr_file_name , 'size') bit = drm.meta_data.get_value( curr_file_name , 'bit' ) bitrate = drm.meta_data.get_value( curr_file_name , 'bitrate' ) sampling_rate = drm.meta_data.get_value( curr_file_name , 'sampling_rate' ) codec = drm.meta_data.get_value( curr_file_name , 'codec' ) artist = drm.meta_data.get_value( curr_file_name , 'artist' ) genre = drm.meta_data.get_value( curr_file_name , 'genre' ) date = drm.meta_data.get_value( curr_file_name , 'date' ) track_nr = drm.meta_data.get_value( curr_file_name , 'track_nr' ) if title == None : title = curr_file_name db.insert_track( track_sha1 , title , dr , rms , peak , duration , codec , bit , bitrate , sampling_rate , album_sha1 , artist , genre , date , track_nr , size ) db.commit_insert_session()
def exec_query(self): db = dr_database_singletone().get() return db.query(self.get_query(), (self.limit, ), dict_factory_arg=my_dict_factory)
def exec_query(self): db = dr_database_singletone().get() return db.query(self.get_query(), (self.limit,), dict_factory_arg=my_dict_factory)
def main(): options = parse_args() if options.version: print_msg(dr14_version()) return init_log(logging.DEBUG) logging.disable(logging.INFO) numpy.seterr(all='ignore') #print( options ) if options.enable_database: enable_database() return if options.disable_database: enable_db(False) print_msg("The local DR database is disabled! ") return if options.dump_database: db = dr_database_singletone().get() db.dump() return if db_is_enabled(): db = dr_database_singletone().get() f = db.is_db_valid() if not f: print_err("It seems that there is some problem with the db ... ") fix_problematic_database() return if options.query != None: if not database_exists(): print_err("Error: The database does not exists") print_err("Error: type dr14_tmeter -q for more info.") return if len(options.query) == 0: query_helper() return if options.query[0] not in [ "help", "top", "top_alb", "worst", "worst_alb", "top_art", "hist", "evol", "codec" ]: print_err("Error: -q invalid parameter .") print_err("Error: type dr14_tmeter -q for more info.") return table_code = database_exec_query(options) if table_code is not None: print_out(table_code) return if options.path_name != None: path_name = os.path.abspath(options.path_name) else: path_name = os.path.abspath('.') if not (os.path.exists(path_name)): print_msg("Error: The input directory \"%s\" does not exists!" % path_name) return if options.out_dir and not (os.path.exists(options.out_dir)): print_msg( "Error (-o): The target directory \"%s\" does not exists! " % options.out_dir) return if options.quiet: set_quiet_msg() if not options.quiet and not options.skip_version_check: l_ver = TestVer() l_ver.start() print_msg(path_name) print_msg("") if options.recursive: subdirlist = list_rec_dirs(path_name) else: subdirlist = [] subdirlist.append(path_name) if run_analysis_opt(options, path_name): return 1 if options.scan_file: dr = DynamicRangeMeter() dr.write_to_local_db(db_is_enabled()) r = dr.scan_file(path_name) if r == 1: print_out("") print_out(dr.res_list[0]['file_name'] + " :") print_out("DR = %d" % dr.res_list[0]['dr14']) print_out("Peak dB = %.2f" % dr.res_list[0]['dB_peak']) print_out("Rms dB = %.2f" % dr.res_list[0]['dB_rms']) return 1 else: print_msg("Error: invalid audio file") return 0 if options.out_dir == "": out_dir = None else: out_dir = options.out_dir if options.append and out_dir == None: out_dir = path_name if options.files_list: (success, clock, r) = scan_files_list(options.path_name, options, out_dir) else: (success, clock, r) = scan_dir_list(subdirlist, options, out_dir) if success: print_msg("Success! ") print_msg("Elapsed time: %2.2f sec" % clock) else: print_msg("No audio files found\n") print_msg( " Usage: %s [options] path_name \n\nfor more details type \n%s --help\n" % (get_exe_name(), get_exe_name())) if sys.platform.startswith('linux') or sys.platform.startswith('darwin'): subprocess.call("stty sane", shell=True) if test_new_version(): print_msg( "\n----------------------------------------------------------------------" ) print_msg( " A new version of dr14_t.meter [ %s ] is available for download" " \n please visit: %s" % (get_new_version(), get_home_url())) print_msg( "----------------------------------------------------------------------\n" ) if not database_exists(): print_msg(" ") print_msg(" News ... News ... News ... News ... News !!! ") print_msg( " With the version 2.0.0 there is the possibility to store all results in a database" ) print_msg(" If you want to enable this database execute the command:") print_msg(" > %s --enable_database " % get_exe_name()) print_msg("") print_msg( " for more details visit: http://dr14tmeter.sourceforge.net/index.php/DR_Database " ) return r
def main(): options = parse_args() if options.version : print_msg( dr14_version() ) return init_log( logging.DEBUG ) logging.disable( logging.INFO ) numpy.seterr(all='ignore') #print( options ) if options.enable_database : enable_database() return if options.disable_database : enable_db( False ) print_msg( "The local DR database is disabled! " ) return if options.dump_database : db = dr_database_singletone().get() db.dump() return if db_is_enabled() : db = dr_database_singletone().get() f = db.is_db_valid() if not f : print_err( "It seems that there is some problem with the db ... " ) fix_problematic_database() return if options.query != None : if not database_exists() : print_err( "Error: The database does not exists" ) print_err( "Error: type dr14_tmeter -q for more info." ) return if len( options.query ) == 0 : query_helper() return if options.query[0] not in [ "help" , "top" , "top_alb" , "worst" , "worst_alb" , "top_art" , "hist" , "evol" , "codec" ] : print_err( "Error: -q invalid parameter ." ) print_err( "Error: type dr14_tmeter -q for more info." ) return table_code = database_exec_query( options ) if table_code is not None: print_out( table_code ) return if options.path_name != None: path_name = os.path.abspath( options.path_name ) else: path_name = os.path.abspath( '.' ) if not( os.path.exists( path_name ) ) : print_msg( "Error: The input directory \"%s\" does not exists!" % path_name ) return if options.out_dir and not( os.path.exists( options.out_dir ) ) : print_msg( "Error (-o): The target directory \"%s\" does not exists! " % options.out_dir ) return if options.quiet : set_quiet_msg() l_ver = TestVer() l_ver.start() print_msg( path_name ) print_msg( "" ) if options.recursive : subdirlist = list_rec_dirs( path_name ) else : subdirlist = [] subdirlist.append( path_name ) if run_analysis_opt( options , path_name ) : return 1 if options.scan_file: dr = DynamicRangeMeter() dr.write_to_local_db( db_is_enabled() ) r = dr.scan_file( path_name ) if r == 1: print_out( "" ) print_out( dr.res_list[0]['file_name'] + " :" ) print_out( "DR = %d" % dr.res_list[0]['dr14'] ) print_out( "Peak dB = %.2f" % dr.res_list[0]['dB_peak'] ) print_out( "Rms dB = %.2f" % dr.res_list[0]['dB_rms'] ) return 1 else: print_msg( "Error: invalid audio file" ) return 0 if options.out_dir == "" : out_dir = None else : out_dir = options.out_dir if options.append and out_dir == None: out_dir = path_name if options.files_list: (success,clock,r) = scan_files_list(options.path_name,options,out_dir) else: (success,clock,r) = scan_dir_list(subdirlist,options,out_dir) if success : print_msg( "Success! " ) print_msg( "Elapsed time: %2.2f sec" % clock ) else: print_msg("No audio files found\n") print_msg(" Usage: %s [options] path_name \n\nfor more details type \n%s --help\n" % ( get_exe_name() , get_exe_name() ) ) if sys.platform.startswith('linux'): subprocess.call( "stty sane" , shell=True ) if test_new_version() : print_msg( "\n----------------------------------------------------------------------" ) print_msg( " A new version of dr14_t.meter [ %s ] is available for download \n please visit: %s" % ( get_new_version() , get_home_url() ) ) print_msg( "----------------------------------------------------------------------\n" ) if not database_exists() : print_msg( " " ) print_msg( " News ... News ... News ... News ... News !!! " ) print_msg( " With the version 2.0.0 there is the possibility to store all results in a database" ) print_msg( " If you want to enable this database execute the command:" ) print_msg( " > %s --enable_database " % get_exe_name() ) print_msg( "" ) print_msg( " for more details visit: http://dr14tmeter.sourceforge.net/index.php/DR_Database " ) return r