def __init__(self): self.timeout = 0 if is_cached('artists_tags'): self.artists_tags = read_cache('artists_tags') else: self.artists_tags = {} if is_cached('albums_tags'): self.albums_tags = read_cache('albums_tags') else: self.albums_tags = {}
def get_all_songs_tags(self, update=False): if self.all_songs_tags is not None and not update: pass elif is_cached('songs_tags') and not update: self.all_songs_tags = read_cache('songs_tags') else: self.all_songs_tags = OrderedDict() for song in self.mpdclient.listallinfo(): if 'file' in song: self.all_songs_tags[song['file']] = { 'artist': song.get('artist', ''), 'album': song.get('album', ''), 'title': song.get('title', ''), 'track': song.get('track', '') } write_cache('songs_tags', self.all_songs_tags) return self.all_songs_tags
def feed(self, force=False): if is_cached('collections') and not force: self.collections = read_cache('collections') else: self.collections = raw_to_optimized(self.read())
enable_command = False # -------------------------------- # MPD initialization # -------------------------------- from mpdc.libs.mpdhelper import MPDHelper mpd = MPDHelper(config['mpd']['host'], config['mpd']['password'], config['mpd']['port']) if not mpd.connect(): warning('Unable to connect to the MPD server') sys.exit(0) if (not is_cached('songs_tags') or cache_last_modified('songs_tags') < int(mpd.stats()['db_update'])): mpd.update_cache() # -------------------------------- # Collections initialization # -------------------------------- try: open(config['mpdc']['collections'], 'r') except IOError: warning('The collections file [%s] doesn\'t seem readable' % config['mpdc']['collections']) sys.exit(0)