cc-4105: removed event packing from RequestSync thread

This commit is contained in:
Rudi Grinberg 2012-08-08 15:19:25 -04:00
parent cff9a5cb71
commit 1235e86251
3 changed files with 26 additions and 24 deletions

View File

@ -160,9 +160,9 @@ class Metadata(Loggable):
# Finally, we "normalize" all the metadata here: # Finally, we "normalize" all the metadata here:
self.__metadata = mmp.normalized_metadata(self.__metadata, fpath) self.__metadata = mmp.normalized_metadata(self.__metadata, fpath)
# Now we must load the md5: # Now we must load the md5:
self.__metadata['MDATA_KEY_MD5'] = mmp.file_md5(fpath,max_length=-1) self.__metadata['MDATA_KEY_MD5'] = mmp.file_md5(fpath,max_length=100)
self.__metadata['MDATA_KEY_REPLAYGAIN'] = \ #self.__metadata['MDATA_KEY_REPLAYGAIN'] = \
gain.calculate_replay_gain(fpath) #gain.calculate_replay_gain(fpath)
def is_recorded(self): def is_recorded(self):
return mmp.is_airtime_recorded( self.__metadata ) return mmp.is_airtime_recorded( self.__metadata )

View File

@ -30,22 +30,9 @@ class RequestSync(threading.Thread,Loggable):
# Not forget to attach the 'is_record' to any requests that are related # Not forget to attach the 'is_record' to any requests that are related
# to recorded shows # to recorded shows
# TODO : recorded shows aren't flagged right # 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. # 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): for try_index in range(0,self.retries):
try: make_req() try: make_req()
# most likely we did not get json response as we expected # most likely we did not get json response as we expected
@ -147,8 +134,10 @@ class WatchSyncer(ReportHandler,Loggable):
self.request_do() self.request_do()
def events_in_queue(self): 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 return len(self.__queue) > 0
def requests_in_queue(self): def requests_in_queue(self):
@ -172,9 +161,22 @@ class WatchSyncer(ReportHandler,Loggable):
self.logger.info("'%s' : Unleashing request" % self.target_path) self.logger.info("'%s' : Unleashing request" % self.target_path)
# want to do request asyncly and empty the queue # want to do request asyncly and empty the queue
requests = copy.copy(self.__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(): def launch_request():
# Need shallow copy here # Need shallow copy here
t = RequestSync(watcher=self, requests=requests) t = RequestSync(watcher=self, requests=packed_requests)
t.start() t.start()
self.__current_thread = t self.__current_thread = t
self.__requests.append(launch_request) self.__requests.append(launch_request)

View File

@ -66,14 +66,14 @@ def calculate_replay_gain(file_path):
search = None search = None
temp_file_path = duplicate_file(file_path) 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: if run_process("which mp3gain > /dev/null") == 0:
out = get_process_output('mp3gain -q "%s" 2> /dev/null' % temp_file_path) out = get_process_output('mp3gain -q "%s" 2> /dev/null' % temp_file_path)
search = re.search(r'Recommended "Track" dB change: (.*)', out) search = re.search(r'Recommended "Track" dB change: (.*)', out)
else: else:
print "mp3gain not found" print "mp3gain not found"
#Log warning #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: 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) run_process('vorbisgain -q -f "%s" 2>/dev/null >/dev/null' % temp_file_path)
out = get_process_output('ogginfo "%s"' % temp_file_path) out = get_process_output('ogginfo "%s"' % temp_file_path)
@ -81,7 +81,7 @@ def calculate_replay_gain(file_path):
else: else:
print "vorbisgain/ogginfo not found" print "vorbisgain/ogginfo not found"
#Log warning #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: if run_process("which metaflac > /dev/null") == 0:
out = get_process_output('metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "%s"' % temp_file_path) out = get_process_output('metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "%s"' % temp_file_path)
search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out) search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out)