def process_timeline(item): state_key = TIMELINE_STATES.get(item['state']) if state_key is None: log.warn('Unknown timeline state "%s"', item['state']) return False EventManager.fire('notifications.timeline.%s' % state_key, item) return True
def initialize(cls): cls.thread = threading.Thread(target=cls.run, name="SyncManager") cls.lock = threading.Lock() EventManager.subscribe('notifications.status.scan_complete', cls.scan_complete) EventManager.subscribe('sync.get_cache_id', cls.get_cache_id) cls.handlers = dict([(h.key, h(cls)) for h in HANDLERS]) cls.statistics = SyncStatistics(HANDLERS, cls)
def initialize(cls): cls.thread = threading.Thread(target=cls.run, name="SyncManager") cls.lock = threading.Lock() EventManager.subscribe('notifications.status.scan_complete', cls.scan_complete) EventManager.subscribe('sync.get_cache_id', cls.get_cache_id) cls.handlers = dict([(h.key, h(cls)) for h in HANDLERS]) cls.statistics = SyncStatistics(HANDLERS, cls) cls.initialized = True
def process(self, line): header_match = PLAYING_HEADER_REGEX.match(line) if not header_match: return activity_type = header_match.group('type') # Get a match from the activity entries if activity_type == 'timeline': match = self.timeline() elif activity_type == 'progress': match = self.progress() else: log.warn('Unknown activity type "%s"', activity_type) return if match is None: match = {} # Extend match with query info self.query(match, header_match.group('query')) # Ensure we successfully matched a result if not match: return # Sanitize the activity result info = { 'address': header_match.group('address'), 'port': header_match.group('port') } # - Get required info parameters for key in self.required_info: if key in match and match[key] is not None: info[key] = match[key] else: log.warn('Invalid activity match, missing key %s (%s)', key, match) return # - Add in any extra info parameters for key in self.extra_info: if key in match: info[key] = match[key] else: info[key] = None # Update the scrobbler with the current state EventManager.fire('scrobbler.logging.update', info)
def process_playing(item): session_key = item.get('sessionKey') state = item.get('state') view_offset = try_convert(item.get('viewOffset'), int) valid = all([x is not None for x in [session_key, state, view_offset]]) if valid: EventManager.fire('notifications.playing', str(session_key), str(state), view_offset) return True log.warn("'playing' notification doesn't look valid, ignoring: %s" % item) return False
def process_playing(item): session_key = item.get('sessionKey') state = item.get('state') view_offset = try_convert(item.get('viewOffset'), int) valid = all([ x is not None for x in [session_key, state, view_offset] ]) if valid: EventManager.fire('notifications.playing', str(session_key), str(state), view_offset) return True log.warn("'playing' notification doesn't look valid, ignoring: %s" % item) return False
def update_config(cls, valid=None): preferences = Dict['preferences'] or {} # If no validation provided, use last stored result or assume true if valid is None: valid = preferences.get('valid', True) preferences['valid'] = valid Configuration.process(preferences) # Ensure preferences dictionary is stored Dict['preferences'] = preferences Dict.Save() log.info('Preferences updated %s', preferences) EventManager.fire('preferences.updated', preferences)
def process(self, line): header_match = PLAYING_HEADER_REGEX.match(line) if not header_match: return activity_type = header_match.group('type') # Get a match from the activity entries if activity_type == 'timeline': match = self.timeline() elif activity_type == 'progress': match = self.progress() else: log.warn('Unknown activity type "%s"', activity_type) return # Ensure we successfully matched a result if not match: return # Sanitize the activity result info = {} # - Get required info parameters for key in self.required_info: if key in match and match[key] is not None: info[key] = match[key] else: log.warn('Invalid activity match, missing key %s (%s)', key, match) return # - Add in any extra info parameters for key in self.extra_info: if key in match: info[key] = match[key] else: info[key] = None # Update the scrobbler with the current state EventManager.fire('scrobbler.logging.update', info)
def process_status(item): if item.get('notificationName') != 'LIBRARY_UPDATE': log.debug('Unknown notification name "%s"', item.get('notificationName')) return False title = item.get('title') # Check for scan complete message if REGEX_STATUS_SCAN_COMPLETE.match(title): EventManager.fire('notifications.status.scan_complete') return True # Check for scanning message match = REGEX_STATUS_SCANNING.match(title) if match: section = match.group('section') if section: EventManager.fire('notifications.status.scanning', section) return True log.debug('No matches found for %s', item) return False
def bind(self, task): key = task.get_key() EventManager.subscribe( 'sync.%s.started' % key, lambda start, end: self.started(key, start, end)) EventManager.subscribe('sync.%s.progress' % key, lambda value: self.progress(key, value)) EventManager.subscribe('sync.%s.finished' % key, lambda: self.finished(key)) # Bind child progress events for child in task.children: self.bind(child)
def bind(self, task): key = task.get_key() EventManager.subscribe( 'sync.%s.started' % key, lambda start, end: self.started(key, start, end) ) EventManager.subscribe( 'sync.%s.progress' % key, lambda value: self.progress(key, value) ) EventManager.subscribe( 'sync.%s.finished' % key, lambda: self.finished(key) ) # Bind child progress events for child in task.children: self.bind(child)
def __init__(self): super(LoggingScrobbler, self).__init__() EventManager.subscribe('scrobbler.logging.update', self.update)
def __init__(self): super(WebSocketScrobbler, self).__init__() EventManager.subscribe('notifications.playing', self.update)
def get_cache_id(cls): return EventManager.fire('sync.get_cache_id', single=True)
def start(self, end, start=0): EventManager.fire( 'sync.%s.started' % self.get_key(), start=start, end=end )
def progress(self, value): EventManager.fire( 'sync.%s.progress' % self.get_key(), value=value )
def finish(self): EventManager.fire( 'sync.%s.finished' % self.get_key() )
def finish(self): EventManager.fire('sync.%s.finished' % self.get_key())
def progress(self, value): EventManager.fire('sync.%s.progress' % self.get_key(), value=value)
def start(self, end, start=0): EventManager.fire('sync.%s.started' % self.get_key(), start=start, end=end)