def get_current_cmus():
    """
    Get the current song from cmus.
    """
    result = subprocess.run('cmus-remote -Q'.split(' '), check=True,
                            stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
    info = {}
    for line in result.stdout.decode().split('\n'):
        line = line.split(' ')
        if line[0] != 'tag':
            continue
        key = line[1]
        if key in ['album', 'title', 'artist', 'albumartist'] and\
           key not in info:
            info[key] = ' '.join(line[2:])

    if 'albumartist' in info:
        info['artist'] = info['albumartist']
        del info['albumartist']

    return Song(**info)
def get_current_cmus ( ) : result = subprocess . run ( 'cmus-remote -Q' . split ( ' ' ) , check = True , stdout = subprocess . PIPE , stderr = subprocess . DEVNULL ) info = { } for line in result . stdout . decode ( ) . split ( '\n' ) : line = line . split ( ' ' ) if line [ 0 ] != 'tag' : continue key = line [ 1 ] if key in [ 'album' , 'title' , 'artist' , 'albumartist' ] and key not in info : info [ key ] = ' ' . join ( line [ 2 : ] ) if 'albumartist' in info : info [ 'artist' ] = info [ 'albumartist' ] del info [ 'albumartist' ] return Song ( ** info )
Get the current song from cmus.