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())
# 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) from mpdc.libs.collectionsmanager import CollectionsManager collectionsmanager = CollectionsManager(config['mpdc']['collections']) update_collections = False if (not is_cached('playlists') or read_cache('playlists') != mpd.get_stored_playlists_info()): write_cache('playlists', mpd.get_stored_playlists_info()) update_collections = True if (update_collections or not is_cached('collections') or cache_last_modified('collections') < os.path.getmtime(config['mpdc']['collections'])): collectionsmanager.feed(force=True) collectionsmanager.update_cache() else: collectionsmanager.feed() collections = collectionsmanager.collections