def main(): config = ConfigParser() config.add_section('mpd') config['mpd']['host'] = input('>> MPD host [localhost]: ') or 'localhost' config['mpd']['port'] = input('>> MPD port [6600]: ') or '6600' config['mpd']['password'] = input('>> MPD password []: ') or '' print('\n') config.add_section('mpdc') print('Later, you will propably need to store and edit your collections/' 'playlists in a specific file. Please create an empty file ' '(e.g. collections.mpdc) where you want and write its path below.') while True: path = input('>> Full path of the collections file: ') if not os.path.isfile(path): warning('Can\'t find the file: ' + path) else: break print('\n') config['mpdc']['collections'] = path colors = input('>> Enable colors [Y/n]: ').lower() or 'y' if colors == 'y': config['mpdc']['colors'] = 'red, green, blue' print('\n') filepath = os.path.expanduser('~/.mpdc') try: with open(filepath, 'w') as configfile: config.write(configfile) info('Writing configuration file in: ' + filepath) except IOError: warning('Can\'t write configuration file in: ' + filepath)
def change_default_profile(profile): config = ConfigParser() filepath = os.path.expanduser('~/.mpdc') if not config.read(filepath): warning('Cannot read the configuration file, run mpdc-configure') return config['profiles']['default'] = str(profile) try: with open(filepath, 'w') as configfile: config.write(configfile) info('Writing configuration file in: ' + filepath) except IOError: warning('Cannot write configuration file in: ' + filepath)
def lastfm_update_albums(args): albums_tags = lastfm.albums_tags missing_albums = sorted(mpd.list_albums(), key=itemgetter(1)) if albums_tags: missing_albums = [album for album in missing_albums if album not in albums_tags] info('Will fetch datas for %s missing album(s)' % len(missing_albums)) for album, artist in missing_albums: print('Fetching %s / %s' % (artist, album)) tags = lastfm.get_album_tags(album, artist, update=True) if tags is not None: albums_tags[(album, artist)] = tags write_cache('albums_tags', albums_tags)
def lastfm_update_artists(args): artists_tags = lastfm.artists_tags missing_artists = sorted(mpd.list_artists()) if artists_tags: missing_artists = [artist for artist in missing_artists if artist not in artists_tags] info('Will fetch datas for %s missing artist(s)' % len(missing_artists)) for artist in missing_artists: print('Fetching %s' % artist) tags = lastfm.get_artist_tags(artist, update=True) if tags is not None: artists_tags[artist] = tags write_cache('artists_tags', artists_tags)
def lastfm_update_tracks(args): known_tracks = set(lastfm.tracks_tags) all_tracks = set(mpd.list_tracks()) #unneeded_tracks = known_tracks - all_tracks #for track in unneeded_tracks: #del lastfm.tracks_tags[album] missing_tracks = all_tracks - known_tracks info('{} missing track(s)'.format(len(missing_tracks))) for track, artist in missing_tracks: print('Fetching {} / {}'.format(artist, track)) lastfm.tracks_tags[(track, artist)] = lastfm.get_track_tags(track, artist, update=True) cache.write('lastfm_tracks_tags', lastfm.tracks_tags)
def lastfm_update_artists(args): tags = lastfm.artists_tags artists = sorted(mpd.list_artists()) extra_artists = [artist for artist in tags if artist not in artists] info('{} extra artist(s)'.format(len(extra_artists))) for artist in extra_artists: del tags[artist] if tags: missing_artists = [artist for artist in artists if artist not in tags] else: missing_artists = artists info('{} missing artist(s)'.format(len(missing_artists))) for artist in missing_artists: print('Fetching {}'.format(artist)) tags[artist] = lastfm.get_artist_tags(artist, update=True) cache.write('artists_tags', tags)
def lastfm_update_albums(args): tags = lastfm.albums_tags albums = sorted(mpd.list_albums(), key=operator.itemgetter(1)) extra_albums = [album for album in tags if album not in albums] info('{} extra album(s)'.format(len(extra_albums))) for album in extra_albums: del tags[album] if tags: missing_albums = [album for album in albums if album not in tags] else: missing_albums = albums info('{} missing album(s)'.format(len(missing_albums))) for album, artist in missing_albums: print('Fetching {} / {}'.format(artist, album)) tags[(album, artist)] = lastfm.get_album_tags(album, artist, update=True) cache.write('albums_tags', tags)
def show(args): if args.alias in collections: if 'mpd_playlist' in collections[args.alias]: info('This collection is stored as a MPD playlist\n') if 'sort' in collections[args.alias]: info('This collection is sorted automatically\n') if 'expression' in collections[args.alias]: print(collections[args.alias]['expression']) if 'command' in collections[args.alias]: print('command: ' + collections[args.alias]['command']) print('--------\n') if 'songs' in collections[args.alias]: print('songs:') print('------') display_songs(collections[args.alias]['songs'], args.m) else: warning('Stored collection [%s] doesn\'t exist' % args.alias)
def add_songs(self, alias, songs_files): if not alias in self.c or not 'mpd_playlist' in self.c[alias]: for song in songs_files[:]: if not all(mpd.get_tags(song)): warning('[{}] was not added (missing tags)'.format(song)) songs_files.remove(song) if alias in self.c: if 'songs' in self.c[alias]: self.collections[alias]['songs'].extend(songs_files) else: self.collections[alias]['songs'] = songs_files if 'mpd_playlist' in self.c[alias]: mpd.add_songs_stored_playlist(alias, songs_files) else: info('Collection [{}] will be created'.format(alias)) self.collections[alias] = {} self.collections[alias]['songs'] = songs_files self.need_update = True
def add_songs(self, alias, songs_files): if (not alias in self.collections or not 'mpd_playlist' in self.collections[alias]): for song in songs_files[:]: if not all(mpd.get_tags(song)): warning('File not added, missing tag(s): [%s]' % song) songs_files.remove(song) if alias in self.collections: if 'songs' in self.collections[alias]: self.collections[alias]['songs'].extend(songs_files) else: self.collections[alias]['songs'] = songs_files if 'mpd_playlist' in self.collections[alias]: mpd.add_songs_stored_playlist(alias, songs_files) else: info('Collection [%s] will be created' % alias) self.collections[alias] = {} self.collections[alias]['songs'] = songs_files self.need_update = True
def configure(args): if args.switch: change_default_profile(args.switch) return config = ConfigParser() config.add_section('profiles') config['profiles']['host[1]'] = input('>> MPD host [localhost]: ') or \ 'localhost' config['profiles']['port[1]'] = input('>> MPD port [6600]: ') or '6600' config['profiles']['password[1]'] = input('>> MPD password []: ') or '' print('\n') config.add_section('mpdc') print('Later, you will propably need to store and edit your collections/' 'playlists in a specific file. Please create an empty file ' '(e.g. collections.mpdc) where you want and write its path below.') while True: path = input('>> Full path of the collections file: ') if os.path.isfile(path): break warning('Cannot find the file: ' + path) print('\n') config['mpdc']['collections'] = path colors = input('>> Enable colors [Y/n]: ').lower() or 'y' if colors == 'y': config['mpdc']['colors'] = 'green, red, blue' print('\n') config['mpdc']['columns'] = 'artist, title, album' filepath = os.path.expanduser('~/.mpdc') try: with open(filepath, 'w') as configfile: config.write(configfile) info('Writing configuration file in: ' + filepath) except IOError: warning('Cannot write configuration file in: ' + filepath)
def show(args): if args.alias in collectionsmanager.c: collection = collectionsmanager.c[args.alias] if "mpd_playlist" in collection: info("This collection is stored as a MPD playlist\n") elif "sort" in collection: info("This collection is sorted automatically\n") elif "special" in collection: info("This is a special collection\n") if "expression" in collection: print(collection["expression"]) if "command" in collection: print("command: " + collection["command"]) print("--------\n") if "songs" in collection: print("songs:") print("------") display_songs(collection["songs"], args.f) else: warning("Stored collection [{}] does not exist".format(args.alias))
def show(args): if args.alias in collectionsmanager.c: collection = collectionsmanager.c[args.alias] if 'mpd_playlist' in collection: info('This collection is stored as a MPD playlist\n') elif 'sort' in collection: info('This collection is sorted automatically\n') elif 'special' in collection: info('This is a special collection\n') if 'expression' in collection: print(collection['expression']) if 'command' in collection: print('command: ' + collection['command']) print('--------\n') if 'songs' in collection: print('songs:') print('------') display_songs(collection['songs'], args.f) else: warning('Stored collection [{}] does not exist'.format(args.alias))