def scan_dir_mt( self , dir_name , thread_cnt ):
     
     if not os.path.isdir(dir_name) :
         return 0
     
     dir_list = sorted( os.listdir( dir_name ) )
     
     self.dir_name = dir_name 
     self.dr14 = 0
     
     ad = AudioDecoder()
     
     jobs = []
     for file_name in dir_list:
         ( fn , ext ) = os.path.splitext( file_name )
         if ext in ad.formats:
             jobs.append( file_name )
     
     empty_res = { 'file_name': '' , 'dr14': dr14.min_dr() , 'dB_peak': -100 , 'dB_rms': -100 , 'duration':"0:0" }
     self.res_list = [empty_res for i in range( len(jobs) )]
     
     lock_j = threading.Lock()
     lock_res_list = threading.Lock()
     
     threads = [1 for i in range(thread_cnt)]
     job_free = [0]
     
     for t in range( thread_cnt ):
         threads[t] = ScanDirMt( dir_name, jobs , job_free , lock_j , self.res_list , lock_res_list )
         
     for t in range( thread_cnt ):
         threads[t].start() 
     
     for t in range( thread_cnt ):
         threads[t].join()
         
     succ = 0 
     for d in self.res_list:
         if d['dr14'] > dr14.min_dr():
             self.dr14 = self.dr14 + d['dr14']
             succ = succ + 1 
         
      
     #print( str(self.res_list ) )
     self.meta_data.scan_dir( dir_name )
     if len( self.res_list ) > 0 and succ > 0 :
         self.dr14 = int( round( self.dr14 / succ ) )
         return succ
     else:
         return 0
 def __init__(self):
     self.track_nr = -1
     self.file_name = ""
     self.dr14 = dr14.min_dr()
     self.dB_peak = 0.0
     self.dB_rms = 0.0 
     self.duration = ""
     self.sha1 = ""
     self.fail = False
     self.dir_name = ""
Beispiel #3
0
 def __init__(self):
     self.track_nr = -1
     self.file_name = ""
     self.dr14 = dr14.min_dr()
     self.dB_peak = 0.0
     self.dB_rms = 0.0
     self.duration = ""
     self.sha1 = ""
     self.fail = False
     self.dir_name = ""
Beispiel #4
0
    def write_dr( self , drm , tm ):
        txt = ""
        
        ( head , album_dir ) = os.path.split( drm.dir_name )
        
        txt = tm.new_table(txt)
        
        txt = tm.new_head( txt )
        
        txt = tm.append_separator_line( txt )
        txt = tm.add_title( txt , " Analyzed folder:  " + album_dir )
        
        txt = tm.end_head( txt )
        
        txt = tm.new_tbody( txt )
        
        txt = tm.append_separator_line( txt )
        txt = tm.append_row( txt , [ " DR", "Peak", "RMS", "Duration" , "File name" ] , 'h' )
        txt = tm.append_separator_line( txt )
        
        for i in range( len( drm.res_list ) ) :
            
            if drm.res_list[i]['dr14'] > dr14.min_dr() :
                row = []
                row.append( " DR%d" % drm.res_list[i]['dr14'] )
                row.append( " %.2f" % drm.res_list[i]['dB_peak'] + ' dB' )
                row.append( " %.2f" % drm.res_list[i]['dB_rms'] + ' dB' )
                row.append( " %s" % drm.res_list[i]['duration'] )
                row.append( " %s" % drm.res_list[i]['file_name'] )
            
                txt = tm.append_row( txt , row )

        txt = tm.end_tbody( txt )
        
        txt = tm.new_foot( txt )
        txt = tm.append_separator_line( txt )
               
        txt = tm.add_title( txt , "Number of files:    " + str(len( drm.res_list )) )
        txt = tm.add_title( txt , "Official DR value:  DR%d" % int(drm.dr14) )
        
        txt = tm.append_empty_line( txt )
        txt = tm.add_title( txt , "Dr14 T.meter %s " % dr14.dr14_version() )
        
        txt = tm.append_closing_line( txt )
        txt = tm.end_foot( txt )
        
        txt = tm.end_table(txt)
        
        return txt 
Beispiel #5
0
    def write_dr(self, drm, tm):

        (head, album_dir) = os.path.split(drm.dir_name)

        tm.new_table()

        tm.new_head()

        tm.append_separator_line()
        tm.add_title(" Analyzed folder:  " + album_dir)

        tm.end_head()

        tm.new_tbody()

        tm.append_separator_line()
        tm.append_row([" DR", "Peak", "RMS", "Duration", "File name"], 'h')
        tm.append_separator_line()

        for i in range(len(drm.res_list)):

            if drm.res_list[i]['dr14'] > dr14.min_dr():
                row = []
                row.append(" DR%d" % drm.res_list[i]['dr14'])
                row.append(" %.2f" % drm.res_list[i]['dB_peak'] + ' dB')
                row.append(" %.2f" % drm.res_list[i]['dB_rms'] + ' dB')
                row.append(" %s" % drm.res_list[i]['duration'])
                row.append(" %s" % drm.res_list[i]['file_name'])

                tm.append_row(row)

        tm.end_tbody()

        tm.new_foot()
        tm.append_separator_line()

        tm.add_title("Number of files:    " + str(len(drm.res_list)))
        tm.add_title("Official DR value:  DR%d" % int(drm.dr14))

        tm.append_empty_line()
        tm.add_title("Dr14 T.meter %s " % dr14.dr14_version())

        tm.append_closing_line()
        tm.end_foot()

        tm.end_table()

        return tm.write_table()
Beispiel #6
0
 def write_dr( self , drm , tm ):
      
     ( head , album_dir ) = os.path.split( drm.dir_name )
     
     tm.new_table()
     
     tm.new_head()
     tm.append_separator_line()
     
     album_t = drm.meta_data.get_album_title()
     artist = drm.meta_data.get_album_artist()[0]
     
     if not isinstance( tm , table.TextTable ) :
         self.set_loudness_war_db_compatible( False )
     
     if self.get_loudness_war_db_compatible() :
     
         title = "" 
         
         if album_t == None :
             title = " Analyzed folder:  " + album_dir 
         else:
             title = " Analyzed: " + album_t 
             if artist != None :
                 title = title + " /  Artist: " + artist
         tm.add_title( title )
     
     else:
     
         if album_t == None :
             tm.add_title( " Analyzed folder:  " + album_dir )
         else:
             tm.add_title( " Album: " + album_t )
             if artist != None :
                 tm.add_title( " Artist: " + artist )
         
     
     tm.end_head()
     
     tm.new_tbody()
     
     tm.append_separator_line()
     tm.append_row( [ "DR", "Peak", "RMS", "Duration" , "Title [codec]" ] , 'h' )
     tm.append_separator_line()
     
     list_bit = []
     
     sum_kbs = 0
     cnt = 0
     
     sampl_rate = []
     
     d_nr = 0 ;        
     
     
     for i in range( len( drm.res_list ) ) :
         
         if drm.res_list[i]['dr14'] > dr14.min_dr() :
             row = []
             row.append( " DR%d" % drm.res_list[i]['dr14'] )
             row.append( " %.2f" % drm.res_list[i]['dB_peak'] + ' dB' )
             row.append( " %.2f" % drm.res_list[i]['dB_rms'] + ' dB' )
             row.append( drm.res_list[i]['duration'] )
             
             #print( "> " + drm.res_list[i]['file_name'] )
             
             curr_file_name = drm.res_list[i]['file_name']
             
             tr_title = drm.meta_data.get_value( curr_file_name , 'title' )
             #print( "> " + tr_title )
             if tr_title == None :
                 row.append( drm.res_list[i]['file_name'] )
             else:
                 nr = drm.meta_data.get_value( curr_file_name , 'track_nr' )
                 codec = drm.meta_data.get_value( curr_file_name , 'codec' )
                 
                 if nr == None :
                     nr = i + 1
                 
                 row.append( "%02d - %s \t [%s]" % ( nr , tr_title , codec ) )
                 
             bitrate = drm.meta_data.get_value( curr_file_name , 'bitrate' )
             bit = drm.meta_data.get_value( curr_file_name , 'bit' )
             s_rate = drm.meta_data.get_value( curr_file_name , 'sampling_rate' )
             
             kbs = drm.meta_data.get_value( curr_file_name , 'bitrate' )
             
             if kbs != None :
                 sum_kbs += int( kbs )
                 cnt = cnt + 1
                 
             if bit not in list_bit :
                 list_bit.append( bit )    
                     
             if s_rate not in sampl_rate :
                 sampl_rate.append( s_rate )
                 
             tm.append_row( row )
     
     tm.end_tbody()
     
     tm.new_foot()
     tm.append_separator_line()
            
     tm.add_title( " Number of files:    " + str(len( drm.res_list )) )
     tm.add_title( " Official DR value:  DR%d" % int(drm.dr14) )
     
     tm.append_empty_line()
     
     tm.add_title( " Sampling rate: \t\t %s Hz" % sampl_rate[0] )
     
     if cnt > 0:
         tm.add_title( " Average bitrate: \t\t %d kbs " % ( ( sum_kbs / 1000 ) / cnt )  )
     
     mf_bit = max( set( list_bit ) , key=list_bit.count )
     tm.add_title( " Bits per sample: \t\t %s bit" % ( mf_bit ) )
     
     tm.append_empty_line()
     tm.add_title( "Dr14 T.meter %s " % dr14.dr14_version() )
     
     tm.append_closing_line()
     tm.end_foot()
     
     tm.end_table()
     
     return tm.write_table()
Beispiel #7
0
    def write_dr(self, drm, tm):

        (head, album_dir) = os.path.split(drm.dir_name)

        tm.new_table()

        tm.new_head()
        tm.append_separator_line()

        album_t = drm.meta_data.get_album_title()
        artist = drm.meta_data.get_album_artist()[0]

        if not isinstance(tm, table.TextTable):
            self.set_loudness_war_db_compatible(False)

        if self.get_loudness_war_db_compatible():

            title = ""

            if album_t == None:
                title = " Analyzed folder:  " + album_dir
            else:
                title = " Analyzed: " + album_t
                if artist != None:
                    title = title + " /  Artist: " + artist
            tm.add_title(title)

        else:

            if album_t == None:
                tm.add_title(" Analyzed folder:  " + album_dir)
            else:
                tm.add_title(" Album: " + album_t)
                if artist != None:
                    tm.add_title(" Artist: " + artist)

        tm.end_head()

        tm.new_tbody()

        tm.append_separator_line()
        tm.append_row(["DR", "Peak", "RMS", "Duration", "Title [codec]"], 'h')
        tm.append_separator_line()

        list_bit = []

        sum_kbs = 0
        cnt = 0

        sampl_rate = []

        d_nr = 0

        for i in range(len(drm.res_list)):

            if drm.res_list[i]['dr14'] > dr14.min_dr():
                row = []
                row.append(" DR%d" % drm.res_list[i]['dr14'])
                row.append(" %.2f" % drm.res_list[i]['dB_peak'] + ' dB')
                row.append(" %.2f" % drm.res_list[i]['dB_rms'] + ' dB')
                row.append(drm.res_list[i]['duration'])

                #print( "> " + drm.res_list[i]['file_name'] )

                curr_file_name = drm.res_list[i]['file_name']

                tr_title = drm.meta_data.get_value(curr_file_name, 'title')
                #print( "> " + tr_title )
                if tr_title == None:
                    row.append(drm.res_list[i]['file_name'])
                else:
                    nr = drm.meta_data.get_value(curr_file_name, 'track_nr')
                    codec = drm.meta_data.get_value(curr_file_name, 'codec')

                    if nr == None:
                        nr = i + 1

                    row.append("%02d - %s \t [%s]" % (nr, tr_title, codec))

                bitrate = drm.meta_data.get_value(curr_file_name, 'bitrate')
                bit = drm.meta_data.get_value(curr_file_name, 'bit')
                s_rate = drm.meta_data.get_value(curr_file_name,
                                                 'sampling_rate')

                kbs = drm.meta_data.get_value(curr_file_name, 'bitrate')

                if kbs != None:
                    sum_kbs += int(kbs)
                    cnt = cnt + 1

                if bit not in list_bit:
                    list_bit.append(bit)

                if s_rate not in sampl_rate:
                    sampl_rate.append(s_rate)

                tm.append_row(row)

        tm.end_tbody()

        tm.new_foot()
        tm.append_separator_line()

        tm.add_title(" Number of files:    " + str(len(drm.res_list)))
        tm.add_title(" Official DR value:  DR%d" % int(drm.dr14))

        tm.append_empty_line()

        tm.add_title(" Sampling rate: \t\t %s Hz" % sampl_rate[0])

        if cnt > 0:
            tm.add_title(" Average bitrate: \t\t %d kbs " %
                         ((sum_kbs / 1000) / cnt))

        mf_bit = max(set(list_bit), key=list_bit.count)
        tm.add_title(" Bits per sample: \t\t %s bit" % (mf_bit))

        tm.append_empty_line()
        tm.add_title("Dr14 T.meter %s " % dr14.dr14_version())

        tm.append_closing_line()
        tm.end_foot()

        tm.end_table()

        return tm.write_table()
 def scan_mp( self , dir_name="" , thread_cnt=2 , files_list=[] ):
     
     if sys.version_info[0] == 2 :
         dir_name = dir_name.decode('utf-8')
     
     self.dr14 = 0
             
     if files_list == [] :
         if not os.path.isdir(dir_name) :
             return 0
         dir_list = sorted( os.listdir( dir_name ) )
         self.dir_name = dir_name
         files_list = None
     else:
         dir_list = sorted( files_list )
         
     ad = AudioDecoder()
     
     jobs = []
     for file_name in dir_list:
         ( fn , ext ) = os.path.splitext( file_name )
         if ext in ad.formats:
             jobs.append( file_name )
     
     
     res_array=[SharedDrResObj() for i in range( len(jobs) )]
     
     for i in range( len(jobs) ) :
         res_array[i].file_name = jobs[i]
         res_array[i].dr14 = dr14.min_dr()
     
     lock_j = mp.Lock()
     lock_res_list = mp.Lock()
     
     threads = [1 for i in range(thread_cnt)]
     
     #job_free = [0]
     job_free = mp.Value( 'i' , 0 )
     res_array_sh = mp.Array( SharedDrResObj , res_array )
     
     for t in range( thread_cnt ):
         threads[t] = mp.Process( target=self.run_mp , args=( dir_name , lock_j , lock_res_list , job_free , res_array_sh ) )
         
     for t in range( thread_cnt ):
         threads[t].start() 
     
     for t in range( thread_cnt ):
         threads[t].join()
         
     succ = 0
     
     #empty_res = { 'file_name': '' , 'dr14': dr14.min_dr() , 'dB_peak': -100 , 'dB_rms': -100 , 'duration':"0:0" }
     self.res_list = [] # [empty_res for i in range( len(jobs) )]
     
     #i = 0
     
     dur = StructDuration()
     
     for res in res_array_sh:
         self.res_list.append( { 'file_name':   res.file_name ,
                              'dr14':        res.dr14 ,
                              'dB_peak':     res.dB_peak ,
                              'dB_rms':      res.dB_rms ,
                              'duration':    dur.float_to_str( res.duration ) } )
         
     #    i = i + 1
     
     for d in self.res_list:
         if d['dr14'] > dr14.min_dr():
             self.dr14 = self.dr14 + d['dr14']
             succ = succ + 1
             
     self.meta_data.scan_dir( dir_name , files_list )
     
     if len( self.res_list ) > 0 and succ > 0 :
         self.dr14 = int( round( self.dr14 / succ ) )
         return succ
     else:
         return 0
   def scan_mp( self , dir_name="" , thread_cnt=2 , files_list=[] ):
       
       if sys.version_info[0] == 2 :
           dir_name = dir_name.decode('utf-8')
       
       self.dr14 = 0
       
       job_queue_sh = mp.JoinableQueue( 2000 )
       res_queue_sh = mp.Queue( 2000 )
               
       if files_list == [] :
           if not os.path.isdir(dir_name) :
               return 0
           dir_list = sorted( os.listdir( dir_name ) )
           self.dir_name = dir_name
           files_list = None
       else:
           dir_list = sorted( files_list )
           
       ad = AudioDecoder()
       
       for file_name in dir_list:
           ( fn , ext ) = os.path.splitext( file_name )
           if ext in ad.formats:
               job = SharedDrResObj()
               job.file_name = file_name
               job.dir_name = dir_name
               job_queue_sh.put( job )
               
       threads = [1 for i in range(thread_cnt)]
       
       job_free = mp.Value( 'i' , 0 )
       
       for t in range( thread_cnt ):
           threads[t] = mp.Process( target=self.run_mp , args=( job_queue_sh , res_queue_sh ) )
           
       for t in range( thread_cnt ):
           threads[t].start() 
 
 
       job_queue_sh.join()
                               
       succ = 0
       
       self.res_list = [] 
       
       #i = 0
       
       dur = StructDuration()
       
       while not res_queue_sh.empty() :
           res = res_queue_sh.get()
           if res.fail :
               continue
           self.res_list.append( { 'file_name':   res.file_name ,
                                   'dr14':        res.dr14 ,
                                   'dB_peak':     res.dB_peak ,
                                   'dB_rms':      res.dB_rms ,
                                   'duration':    dur.float_to_str( res.duration ) , 
                                   'sha1':        res.sha1 } )
           
       self.res_list = sorted( self.res_list , key=lambda res: res['file_name'] )
           
       #    i = i + 1
       
       for d in self.res_list:
           if d['dr14'] > dr14.min_dr():
               self.dr14 = self.dr14 + d['dr14']
               succ = succ + 1
               
       self.meta_data.scan_dir( dir_name , files_list )
       
       if len( self.res_list ) > 0 and succ > 0 :
           self.dr14 = int( round( self.dr14 / succ ) )
           return succ
       else:
           return 0
Beispiel #10
0
    def scan_mp(self, dir_name="", thread_cnt=2, files_list=[]):

        if sys.version_info[0] == 2:
            dir_name = dir_name.decode('utf-8')

        self.dr14 = 0

        job_queue_sh = mp.JoinableQueue(2000)
        res_queue_sh = mp.Queue(2000)

        if files_list == []:
            if not os.path.isdir(dir_name):
                return 0
            dir_list = sorted(os.listdir(dir_name))
            self.dir_name = dir_name
            files_list = None
        else:
            dir_list = sorted(files_list)

        ad = AudioDecoder()

        for file_name in dir_list:
            (fn, ext) = os.path.splitext(file_name)
            if ext in ad.formats:
                job = SharedDrResObj()
                job.file_name = file_name
                job.dir_name = dir_name
                job_queue_sh.put(job)

        threads = [1 for i in range(thread_cnt)]

        job_free = mp.Value('i', 0)

        for t in range(thread_cnt):
            threads[t] = mp.Process(target=self.run_mp,
                                    args=(job_queue_sh, res_queue_sh))

        for t in range(thread_cnt):
            threads[t].start()

        job_queue_sh.join()

        succ = 0

        self.res_list = []

        #i = 0

        dur = StructDuration()

        while not res_queue_sh.empty():
            res = res_queue_sh.get()
            if res.fail:
                continue
            self.res_list.append({
                'file_name': res.file_name,
                'dr14': res.dr14,
                'dB_peak': res.dB_peak,
                'dB_rms': res.dB_rms,
                'duration': dur.float_to_str(res.duration),
                'sha1': res.sha1
            })

        self.res_list = sorted(self.res_list, key=lambda res: res['file_name'])

        #    i = i + 1

        for d in self.res_list:
            if d['dr14'] > dr14.min_dr():
                self.dr14 = self.dr14 + d['dr14']
                succ = succ + 1

        self.meta_data.scan_dir(dir_name, files_list)

        if len(self.res_list) > 0 and succ > 0:
            self.dr14 = int(round(self.dr14 / succ))
            return succ
        else:
            return 0