Ejemplo n.º 1
0
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]))
Ejemplo n.º 2
0
def format_alias(alias):
    if 'mpd_playlist' in collections[alias]:
        return colorize('(playlist) ', colors[1]) + alias
    if 'sort' in collections[alias]:
        return colorize('@', colors[2]) + alias
    else:
        return alias
Ejemplo n.º 3
0
def format_alias(alias):
    if "mpd_playlist" in collectionsmanager.c[alias]:
        return colorize("(playlist) ", colors[0]) + alias
    elif "sort" in collectionsmanager.c[alias]:
        return colorize("@ ", colors[0]) + alias
    elif "special" in collectionsmanager.c[alias]:
        return colorize("# ", colors[0]) + alias
    return alias
Ejemplo n.º 4
0
def format_alias(alias):
    if 'mpd_playlist' in collectionsmanager.c[alias]:
        return colorize('(playlist) ', colors[0]) + alias
    elif 'sort' in collectionsmanager.c[alias]:
        return colorize('@ ', colors[0]) + alias
    elif 'special' in collectionsmanager.c[alias]:
        return colorize('# ', colors[0]) + alias
    return alias
Ejemplo n.º 5
0
def display_songs(filenames, metadata=False, prefix=None):
    for song in filenames:
        if metadata:
            tags = ('artist', 'album', 'title')
            artist, album, title = mpd.get_tags(song, tags)
            print('%s - %s - %s' % (colorize(artist, colors[0]),
                                    colorize(album, colors[1]),
                                    colorize(title, colors[2])))
        elif prefix is not None:
            print(prefix + song)
        else:
            print(song)
Ejemplo n.º 6
0
def display_songs(filenames, path=None, enable_pager=False):
    lines = []
    if path is None:
        c_w, t_w = columns_width(columns)
        header = ''
        for i, column in enumerate(columns):
            header += colorize(column.title().ljust(c_w[column]),
                               colors[i % len(colors)], True)
        if enable_pager:
            lines.append(header)
            lines.append('-' * t_w)
        else:
            print(header)
            print('—' * t_w)
        current_song = mpd.get_current_song()
    for song in filenames:
        if path is None:
            bold = True if song == current_song else False
            row = ''
            for i, column in enumerate(columns):
                if column == 'filename':
                    tag = song
                else:
                    tag = mpd.get_tag(song, column, empty='<empty>')
                    if column == 'time':
                        m, s = divmod(int(tag), 60)
                        tag = '{}:{:02}'.format(m, s)
                if len(tag) > c_w[column] - 1:
                    tag = tag[:c_w[column] - 2] + '…'
                row += colorize(tag.ljust(c_w[column]),
                                colors[i % len(colors)], bold)
            if enable_pager:
                lines.append(row)
            else:
                print(row)
        else:
            if enable_pager:
                lines.append(os.path.join(path, song))
            else:
                print(os.path.join(path, song))
    if enable_pager:
        pager_p = subprocess.Popen(shlex.split(pager), stdin=subprocess.PIPE)
        pager_p.stdin.write(bytes('\n'.join(lines), 'utf-8'))
        pager_p.stdin.close()
        pager_p.communicate()
Ejemplo n.º 7
0
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]))