def check(args): # will print a warning if there is a problem print('Checking "songs" sections...') collectionsmanager.feed(force=True) for alias, collection in collectionsmanager.c.items(): if "mpd_playlist" not in collection: print("Checking collection [{}]...".format(alias)) parser.parse('"' + esc_quotes(alias) + '"')
def check(args): # will print a warning if there's a problem print('Checking "songs" sections...') collectionsmanager.feed(force=True) for alias in collections: if 'mpd_playlist' not in collections[alias]: print('Checking collection [%s]...' % alias) parser.parse('"' + esc_quotes(alias) + '"')
def replacep(args): songs = list(parser.parse(args.collection)) if songs: mpd.replace(songs) mpd.play() else: mpd.clear()
def check(args): songs = [] song_tags_dict = mpd.get_all_songs_tags() for song in parser.parse(' '.join(args.collection)): tags = song_tags_dict[song] missing_tags = [tag for tag, value in tags.items() if not value] if missing_tags: warning(colorize(song, colors[0])) print('missing tag(s): ' + colorize(', '.join(missing_tags), colors[1 % len(colors)])) else: songs.append(tuple(sorted(tags.items()))) duplicates = [dict(tags) for tags, nb in Counter(songs).items() if nb > 1] if duplicates: print('\nConflict(s) found:') print('------------------') for tags in duplicates: warning('Conflict with tags ' + colorize(repr_tags([tags['artist'], tags['album'], tags['title'], tags['track']]), colors[1 % len(colors)])) # necessary because MPDHelper's get_all_songs_tags falls back # to artist if albumartist is empty, while it's find_multiple # (mpdclient.find in fact) does not # not a solution really, so FIXME tags.pop('albumartist') files_matched = mpd.find_multiple(**tags) print('files matched:\n' + colorize('\n'.join(files_matched), colors[0]))
def ls(args): if args.collection is None: for alias in collectionsmanager.c: print(format_alias(alias)) else: songs = parser.parse(args.collection) display_songs(songs, args.f, (enable_pager or args.p) and not args.np)
def play(args): songs = parser.parse(args.collection) if songs: positions = mpd.get_playlist_positions() try: first_matched_song = next(s for s in positions if s in songs) except StopIteration: pass else: mpd.play(positions[first_matched_song][0])
def find(args): # assuming it's a file if args.pattern in mpd.get_all_songs(): print('File found in:') print('--------------') for alias in collections: songs_c = parser.parse('"' + esc_quotes(alias) + '"') if args.pattern in songs_c: print(format_alias(alias)) # assuming it's a collection else: songs = parser.parse(args.pattern) print('Collection is a subset of:') print('--------------------------') if songs: for alias in collections: songs_c = parser.parse('"' + esc_quotes(alias) + '"') if args.pattern != alias and songs.issubset(songs_c): print(format_alias(alias))
def find(args): # assuming it's a file if args.pattern in mpd.get_all_songs(): print("File found in:") print("--------------") for alias in collectionsmanager.c: songs = parser.parse('"' + esc_quotes(alias) + '"') if args.pattern in songs: print(format_alias(alias)) # assuming it's a collection else: songs = parser.parse(args.pattern) print("Collection is a subset of:") print("--------------------------") if songs: for alias in collectionsmanager.c: s = parser.parse('"' + esc_quotes(alias) + '"') if args.pattern.strip(" '\"") != alias and songs.issubset(s): print(format_alias(alias))
def lastfm_get_album_tags(args): tracks = parser.parse(' '.join(args.collection)) albums_albumartists = set() for track in tracks: album, albumartist = mpd.get_tags(track, tags_list=['album','albumartist']) if album and albumartist: albums_albumartists.add((album, albumartist)) for item in albums_albumartists: if item in lastfm.albums_tags and lastfm.albums_tags[item]: album, albumartist = item print(':: %s — %s:' % (albumartist, album)) print(', '.join(lastfm.albums_tags[item]))
def lastfm_get_artist_tags(args): tracks = parser.parse(' '.join(args.collection)) artists = set() for track in tracks: albumartist, artist = mpd.get_tags(track, tags_list=['albumartist','artist']) if artist: artists.add(artist) if albumartist: artists.add(albumartist) for artist in artists: if artist in lastfm.artists_tags and lastfm.artists_tags[artist]: print(':: %s:' % artist) print(', '.join(lastfm.artists_tags[artist]))
def lastfm_get_track_tags(args): tracks = parser.parse(' '.join(args.collection)) tracks_artists = set() for trackfile in tracks: trackname, artist, albumartist = mpd.get_tags(trackfile, tags_list=['title','artist','albumartist']) if trackname and albumartist: tracks_artists.add((trackname, albumartist)) if trackname and artist: tracks_artists.add((trackname, artist)) for item in tracks_artists: if item in lastfm.tracks_tags and lastfm.tracks_tags[item]: track, artist = item print(':: %s — %s:' % (artist, track)) print(', '.join(lastfm.tracks_tags[item]))
def keep(args): songs = parser.parse(args.collection) remove_songs = [s for s in mpd.get_playlist_songs() if s not in songs] if remove_songs: mpd.remove(remove_songs)
def remove(args): songs = list(parser.parse(args.collection)) if songs: mpd.remove(songs)
def remove_songs(args): songs = list(parser.parse(args.collection)) if songs: collectionsmanager.remove_songs(args.alias, songs)
def add(args): songs = list(parser.parse(args.collection)) if songs: mpd.add(songs)
def replace(args): songs = list(parser.parse(args.collection)) mpd.clear() if songs: mpd.add(songs)
def add_songs(args): songs = list(parser.parse(args.collection)) if songs: collectionsmanager.add_songs(args.alias, songs)
def addp(args): songs = list(parser.parse(args.collection)) if songs: mpd.add(songs) mpd.play_file(mpd.first_lately_added_song)
def insert(args): songs = list(parser.parse(args.collection)) if songs: mpd.insert(songs)
def ls(args): if args.collection is None: for alias in collections: print(format_alias(alias)) else: display_songs(parser.parse(args.collection), args.m, args.p)