cc-4105: fixed bug where program would crash on non integer track numbers
This commit is contained in:
parent
a576af2482
commit
bcb65c4269
|
@ -3,7 +3,6 @@ import abc
|
||||||
import traceback
|
import traceback
|
||||||
from media.monitor.pure import LazyProperty
|
from media.monitor.pure import LazyProperty
|
||||||
|
|
||||||
logfile = '/home/rudi/throwaway/mm2.log'
|
|
||||||
#logger = None
|
#logger = None
|
||||||
|
|
||||||
def setup_logging(log_path):
|
def setup_logging(log_path):
|
||||||
|
|
|
@ -123,8 +123,10 @@ class Metadata(Loggable):
|
||||||
for k,v in full_mutagen.iteritems():
|
for k,v in full_mutagen.iteritems():
|
||||||
# Special handling of attributes here
|
# Special handling of attributes here
|
||||||
if isinstance(v, list):
|
if isinstance(v, list):
|
||||||
if len(v) == 1: metadata[k] = v[0]
|
# TODO : some files have multiple fields for the same metadata.
|
||||||
else: raise Exception("Unknown mutagen %s:%s" % (k,str(v)))
|
# genre is one example. In that case mutagen will return a list
|
||||||
|
# of values
|
||||||
|
metadata[k] = v[0]
|
||||||
else: metadata[k] = v
|
else: metadata[k] = v
|
||||||
self.__metadata = {}
|
self.__metadata = {}
|
||||||
# Start populating a dictionary of airtime metadata in __metadata
|
# Start populating a dictionary of airtime metadata in __metadata
|
||||||
|
|
|
@ -3,6 +3,7 @@ import copy
|
||||||
import os
|
import os
|
||||||
from os.path import normpath
|
from os.path import normpath
|
||||||
import shutil
|
import shutil
|
||||||
|
from itertools import takewhile
|
||||||
import sys
|
import sys
|
||||||
import hashlib
|
import hashlib
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
|
@ -156,6 +157,13 @@ def remove_whitespace(dictionary):
|
||||||
for bad_key in bad_keys: del nd[bad_key]
|
for bad_key in bad_keys: del nd[bad_key]
|
||||||
return nd
|
return nd
|
||||||
|
|
||||||
|
def parse_int(s):
|
||||||
|
if s.isdigit(): return s
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
return reduce(lambda x,y: x + y,
|
||||||
|
takewhile(lambda x: x.isdigit(), s))
|
||||||
|
except: return 0
|
||||||
|
|
||||||
def normalized_metadata(md, original_path):
|
def normalized_metadata(md, original_path):
|
||||||
""" consumes a dictionary of metadata and returns a new dictionary with the
|
""" consumes a dictionary of metadata and returns a new dictionary with the
|
||||||
|
@ -170,7 +178,7 @@ def normalized_metadata(md, original_path):
|
||||||
# It's very likely that the following isn't strictly necessary. But the old
|
# It's very likely that the following isn't strictly necessary. But the old
|
||||||
# code would cast MDATA_KEY_TRACKNUMBER to an integer as a byproduct of
|
# code would cast MDATA_KEY_TRACKNUMBER to an integer as a byproduct of
|
||||||
# formatting the track number to 2 digits.
|
# formatting the track number to 2 digits.
|
||||||
'MDATA_KEY_TRACKNUMBER' : lambda x: int(x),
|
'MDATA_KEY_TRACKNUMBER' : parse_int,
|
||||||
'MDATA_KEY_BITRATE' : lambda x: str(int(x) / 1000) + "kbps",
|
'MDATA_KEY_BITRATE' : lambda x: str(int(x) / 1000) + "kbps",
|
||||||
# note: you don't actually need the lambda here. It's only used for clarity
|
# note: you don't actually need the lambda here. It's only used for clarity
|
||||||
'MDATA_KEY_FILEPATH' : lambda x: os.path.normpath(x),
|
'MDATA_KEY_FILEPATH' : lambda x: os.path.normpath(x),
|
||||||
|
|
|
@ -6,7 +6,7 @@ import traceback
|
||||||
|
|
||||||
from media.monitor.handler import ReportHandler
|
from media.monitor.handler import ReportHandler
|
||||||
from media.monitor.log import Loggable
|
from media.monitor.log import Loggable
|
||||||
from media.monitor.listeners import FileMediator
|
#from media.monitor.listeners import FileMediator
|
||||||
from media.monitor.exceptions import BadSongFile
|
from media.monitor.exceptions import BadSongFile
|
||||||
from media.monitor.pure import LazyProperty
|
from media.monitor.pure import LazyProperty
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class RequestSync(threading.Thread,Loggable):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.watcher = watcher
|
self.watcher = watcher
|
||||||
self.requests = requests
|
self.requests = requests
|
||||||
self.retries = 3
|
self.retries = 1
|
||||||
self.request_wait = 0.3
|
self.request_wait = 0.3
|
||||||
|
|
||||||
@LazyProperty
|
@LazyProperty
|
||||||
|
@ -42,8 +42,8 @@ class RequestSync(threading.Thread,Loggable):
|
||||||
self.logger.info("Bad song file: '%s'" % e.path)
|
self.logger.info("Bad song file: '%s'" % e.path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.info("An evil exception occured")
|
self.logger.info("An evil exception occured")
|
||||||
import ipdb; ipdb.set_trace()
|
|
||||||
self.logger.error( traceback.format_exc() )
|
self.logger.error( traceback.format_exc() )
|
||||||
|
import ipdb; ipdb.set_trace()
|
||||||
def make_req():
|
def make_req():
|
||||||
self.apiclient.send_media_monitor_requests( packed_requests )
|
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.
|
||||||
|
@ -55,6 +55,10 @@ class RequestSync(threading.Thread,Loggable):
|
||||||
it's not returning json when it should\n \
|
it's not returning json when it should\n \
|
||||||
... will fix once I setup the damn debugger")
|
... will fix once I setup the damn debugger")
|
||||||
self.logger.info("Trying again after %f seconds" % self.request_wait)
|
self.logger.info("Trying again after %f seconds" % self.request_wait)
|
||||||
|
self.logger.info("==== choked on '%s' ====" % packed_requests)
|
||||||
|
print("==== choked on '%s' ====" % packed_requests)
|
||||||
|
#self.logger.info( traceback.format_exc() )
|
||||||
|
#import ipdb; ipdb.set_trace()
|
||||||
time.sleep( self.request_wait )
|
time.sleep( self.request_wait )
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.unexpected_exception(e)
|
self.unexpected_exception(e)
|
||||||
|
@ -62,7 +66,7 @@ class RequestSync(threading.Thread,Loggable):
|
||||||
self.logger.info("Request worked on the '%d' try" % (try_index + 1))
|
self.logger.info("Request worked on the '%d' try" % (try_index + 1))
|
||||||
break
|
break
|
||||||
else: self.logger.info("Failed to send request after '%d' tries..." % self.retries)
|
else: self.logger.info("Failed to send request after '%d' tries..." % self.retries)
|
||||||
self.logger.info("Now ignoring: %d files" % len(FileMediator.ignored_set))
|
#self.logger.info("Now ignoring: %d files" % len(FileMediator.ignored_set))
|
||||||
self.watcher.flag_done()
|
self.watcher.flag_done()
|
||||||
|
|
||||||
class TimeoutWatcher(threading.Thread,Loggable):
|
class TimeoutWatcher(threading.Thread,Loggable):
|
||||||
|
@ -94,7 +98,7 @@ class WatchSyncer(ReportHandler,Loggable):
|
||||||
self.path = '' # TODO : get rid of this attribute everywhere
|
self.path = '' # TODO : get rid of this attribute everywhere
|
||||||
#self.signal = signal
|
#self.signal = signal
|
||||||
self.timeout = float(timeout)
|
self.timeout = float(timeout)
|
||||||
self.chunking_number = chunking_number
|
self.chunking_number = int(chunking_number)
|
||||||
self.__queue = []
|
self.__queue = []
|
||||||
# Even though we are not blocking on the http requests, we are still
|
# Even though we are not blocking on the http requests, we are still
|
||||||
# trying to send the http requests in order
|
# trying to send the http requests in order
|
||||||
|
@ -135,7 +139,7 @@ class WatchSyncer(ReportHandler,Loggable):
|
||||||
|
|
||||||
def push_queue(self, elem):
|
def push_queue(self, elem):
|
||||||
self.logger.info("Added event into queue")
|
self.logger.info("Added event into queue")
|
||||||
if self.events_left_count() == self.chunking_number:
|
if self.events_left_count() >= self.chunking_number:
|
||||||
self.push_request()
|
self.push_request()
|
||||||
self.request_do() # Launch the request if nothing is running
|
self.request_do() # Launch the request if nothing is running
|
||||||
self.__queue.append(elem)
|
self.__queue.append(elem)
|
||||||
|
|
|
@ -23,7 +23,6 @@ api_client_config = u'/home/rudi/Airtime/python_apps/media-monitor2/tests/live_c
|
||||||
# users of MMConfig instances to modify any config options directly through the
|
# users of MMConfig instances to modify any config options directly through the
|
||||||
# dictionary. Users of this object muse use the correct methods designated for
|
# dictionary. Users of this object muse use the correct methods designated for
|
||||||
# modification
|
# modification
|
||||||
config = None
|
|
||||||
try: config = MMConfig(global_config)
|
try: config = MMConfig(global_config)
|
||||||
except NoConfigFile as e:
|
except NoConfigFile as e:
|
||||||
print("Cannot run mediamonitor2 without configuration file.")
|
print("Cannot run mediamonitor2 without configuration file.")
|
||||||
|
@ -34,7 +33,6 @@ except Exception as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
|
||||||
logfile = unicode( config['logpath'] )
|
logfile = unicode( config['logpath'] )
|
||||||
|
|
||||||
setup_logging(logfile)
|
setup_logging(logfile)
|
||||||
log = get_logger()
|
log = get_logger()
|
||||||
log.info("Attempting to set the locale...")
|
log.info("Attempting to set the locale...")
|
||||||
|
|
|
@ -15,7 +15,7 @@ check_filesystem_events = 5 #how long to queue up events performed on the files
|
||||||
check_airtime_events = 30 #how long to queue metadata input from airtime.
|
check_airtime_events = 30 #how long to queue metadata input from airtime.
|
||||||
|
|
||||||
touch_interval = 5
|
touch_interval = 5
|
||||||
chunking_number = 150
|
chunking_number = 1
|
||||||
request_max_wait = 3.0
|
request_max_wait = 3.0
|
||||||
rmq_event_wait = 0.5
|
rmq_event_wait = 0.5
|
||||||
logpath = '/home/rudi/throwaway/mm2.log'
|
logpath = '/home/rudi/throwaway/mm2.log'
|
||||||
|
|
Loading…
Reference in New Issue