From 1235e8625117e81ace997cbcf090d3530549396e Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 8 Aug 2012 15:19:25 -0400 Subject: [PATCH] cc-4105: removed event packing from RequestSync thread --- .../media-monitor2/media/monitor/metadata.py | 6 +-- .../media/monitor/watchersyncer.py | 38 ++++++++++--------- .../media-monitor2/media/update/replaygain.py | 6 +-- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/metadata.py b/python_apps/media-monitor2/media/monitor/metadata.py index 1e591ced7..e4dcc7541 100644 --- a/python_apps/media-monitor2/media/monitor/metadata.py +++ b/python_apps/media-monitor2/media/monitor/metadata.py @@ -160,9 +160,9 @@ class Metadata(Loggable): # Finally, we "normalize" all the metadata here: self.__metadata = mmp.normalized_metadata(self.__metadata, fpath) # Now we must load the md5: - self.__metadata['MDATA_KEY_MD5'] = mmp.file_md5(fpath,max_length=-1) - self.__metadata['MDATA_KEY_REPLAYGAIN'] = \ - gain.calculate_replay_gain(fpath) + self.__metadata['MDATA_KEY_MD5'] = mmp.file_md5(fpath,max_length=100) + #self.__metadata['MDATA_KEY_REPLAYGAIN'] = \ + #gain.calculate_replay_gain(fpath) def is_recorded(self): return mmp.is_airtime_recorded( self.__metadata ) diff --git a/python_apps/media-monitor2/media/monitor/watchersyncer.py b/python_apps/media-monitor2/media/monitor/watchersyncer.py index 4c46d382b..5178a3ca2 100644 --- a/python_apps/media-monitor2/media/monitor/watchersyncer.py +++ b/python_apps/media-monitor2/media/monitor/watchersyncer.py @@ -30,22 +30,9 @@ class RequestSync(threading.Thread,Loggable): # Not forget to attach the 'is_record' to any requests that are related # to recorded shows # TODO : recorded shows aren't flagged right - packed_requests = [] - for request_event in self.requests: - try: - for request in request_event.safe_pack(): - if isinstance(request, BadSongFile): - self.logger.info("Bad song file: '%s'" % request.path) - else: packed_requests.append(request) - except BadSongFile as e: - self.logger.info("This should never occur anymore!!!") - self.logger.info("Bad song file: '%s'" % e.path) - except Exception as e: - self.logger.info("An evil exception occured") - self.logger.error( traceback.format_exc() ) - def make_req(): - self.apiclient.send_media_monitor_requests( packed_requests ) # Is this retry shit even necessary? Consider getting rid of this. + def make_req(): + self.apiclient.send_media_monitor_requests( self.requests ) for try_index in range(0,self.retries): try: make_req() # most likely we did not get json response as we expected @@ -147,8 +134,10 @@ class WatchSyncer(ReportHandler,Loggable): self.request_do() def events_in_queue(self): - """returns true if there are events in the queue that haven't been - processed yet""" + """ + returns true if there are events in the queue that haven't been + processed yet + """ return len(self.__queue) > 0 def requests_in_queue(self): @@ -172,9 +161,22 @@ class WatchSyncer(ReportHandler,Loggable): self.logger.info("'%s' : Unleashing request" % self.target_path) # want to do request asyncly and empty the queue requests = copy.copy(self.__queue) + packed_requests = [] + for request_event in requests: + try: + for request in request_event.safe_pack(): + if isinstance(request, BadSongFile): + self.logger.info("Bad song file: '%s'" % request.path) + else: packed_requests.append(request) + except BadSongFile as e: + self.logger.info("This should never occur anymore!!!") + self.logger.info("Bad song file: '%s'" % e.path) + except Exception as e: + self.logger.info("An evil exception occured") + self.logger.error( traceback.format_exc() ) def launch_request(): # Need shallow copy here - t = RequestSync(watcher=self, requests=requests) + t = RequestSync(watcher=self, requests=packed_requests) t.start() self.__current_thread = t self.__requests.append(launch_request) diff --git a/python_apps/media-monitor2/media/update/replaygain.py b/python_apps/media-monitor2/media/update/replaygain.py index e10b7a3f2..bec818b2b 100644 --- a/python_apps/media-monitor2/media/update/replaygain.py +++ b/python_apps/media-monitor2/media/update/replaygain.py @@ -66,14 +66,14 @@ def calculate_replay_gain(file_path): search = None temp_file_path = duplicate_file(file_path) - if re.search(r'mp3$', file_path, re.IGNORECASE) or get_mime_type(temp_file_path) == "audio/mpeg": + if re.search(r'mp3$', file_path, re.IGNORECASE) or get_mime_type(file_path) == "audio/mpeg": if run_process("which mp3gain > /dev/null") == 0: out = get_process_output('mp3gain -q "%s" 2> /dev/null' % temp_file_path) search = re.search(r'Recommended "Track" dB change: (.*)', out) else: print "mp3gain not found" #Log warning - elif re.search(r'og(g|a)$', file_path, re.IGNORECASE) or get_mime_type(temp_file_path) == "application/ogg": + elif re.search(r'og(g|a)$', file_path, re.IGNORECASE) or get_mime_type(file_path) == "application/ogg": if run_process("which vorbisgain > /dev/null && which ogginfo > /dev/null") == 0: run_process('vorbisgain -q -f "%s" 2>/dev/null >/dev/null' % temp_file_path) out = get_process_output('ogginfo "%s"' % temp_file_path) @@ -81,7 +81,7 @@ def calculate_replay_gain(file_path): else: print "vorbisgain/ogginfo not found" #Log warning - elif re.search(r'flac$', file_path, re.IGNORECASE) or get_mime_type(temp_file_path) == "audio/x-flac": + elif re.search(r'flac$', file_path, re.IGNORECASE) or get_mime_type(file_path) == "audio/x-flac": if run_process("which metaflac > /dev/null") == 0: out = get_process_output('metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "%s"' % temp_file_path) search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out)