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 raw_to_optimized(collections_raw): collections = OrderedDict() alias = '' for line in collections_raw: if line.startswith('--'): alias = (line[2:] if line[2] not in '@#' else line[3:]).strip() collections[alias] = {} if line[2] == '@': collections[alias]['sort'] = True elif line[2] == '#': collections[alias]['special'] = True elif alias: if line.startswith('command:'): collections[alias]['command'] = line[8:].strip() elif line.startswith('songs:'): collections[alias]['songs'] = [] elif line.strip(): if ('songs' in collections[alias] and (line.startswith(' ') or line.startswith('\t'))): tags = ast.literal_eval('({})'.format(line.strip())) artist, album, title, track = tags matched_songs = mpd.find_multiple(artist=artist, album=album, title=title, track=track) if matched_songs: collections[alias]['songs'].append(matched_songs[0]) else: warning('In collection [{}], these tags do not match ' 'any song: {}'.format(alias, repr_tags(tags))) else: if 'expression' not in collections[alias]: collections[alias]['expression'] = line else: collections[alias]['expression'] += line # add MPD native playlists for playlist in mpd.get_stored_playlists(): if playlist not in collections: collections[playlist] = {'mpd_playlist': True, 'songs': mpd.get_stored_playlist_songs(playlist)} else: warning('MPD playlist [{}] was ignored because a collection with ' 'the same name already exists'.format(playlist)) return collections
def optimized_to_raw(collections_optimized): raw = '' for alias, collection in collections_optimized.items(): if 'mpd_playlist' in collection: continue if 'sort' in collection: raw += '--@%s' % alias else: raw += '--%s' % alias if 'expression' in collection: raw += '\n' + collection['expression'].rstrip() if 'command' in collection: raw += '\ncommand: ' + collection['command'] if 'songs' in collection and collection['songs']: raw += '\nsongs:' for song in collection['songs']: song_tags = mpd.get_tags(song) raw += '\n ' + repr_tags(song_tags) raw += '\n\n\n' return raw.strip()
def check(args): songs = [] for song, tags in mpd.get_all_songs_tags().items(): missing_tags = [tag for tag, value in tags.items() if not value] if missing_tags: warning('You should tag [%s]' % colorize(song, colors[0])) print('missing tag(s): %s' % colorize(', '.join(missing_tags), colors[1])) 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])) files_matched = mpd.find_multiple(**tags) print('files matched: \n%s\n' % colorize('\n'.join(files_matched), colors[0]))