Example #1
0
def run(music_dir):
    music_dir = os.path.abspath(os.path.expanduser(music_dir))
    if not os.path.isdir(music_dir):
        raise FileNotFoundError(music_dir)

    logger = logging.getLogger('mpd')
    global _mpd_dir
    _mpd_dir = TemporaryDirectory(prefix='e2e-mpd.')
    mpd_dir = _mpd_dir.name
    # create temporary config for mpd
    mpd_db = os.path.join(mpd_dir, 'db')
    os.mknod(mpd_db)

    mpd_socket = os.path.join(mpd_dir, 'socket')
    os.mknod(mpd_socket)

    mpd_conf = os.path.join(mpd_dir, 'mpd.conf')
    with open(mpd_conf, 'w') as f:
        f.write('db_file "{}"\n'.format(mpd_db))
        f.write('log_file "syslog"\n')
        f.write('bind_to_address "{}"\n'.format(mpd_socket))
        f.write('music_directory "{}"\n'.format(music_dir))

    logger.debug('created mpd config in {}'.format(mpd_dir))
    logger.debug('starting on {}...'.format(mpd_socket))

    # run mpd
    global _mpd_proc
    _mpd_proc = Popen(['mpd', '--no-daemon', mpd_conf])
    daemon.set_socket(mpd_socket)

    # wait for mpd to start
    while True:
        try:
            playback.get_status()
            break
        except (ConnectionRefusedError, FileNotFoundError):
            pass
    # wait for music database
    while 'db_update' not in daemon.get_dict("stats"):
        try:
            daemon.get_query("idle database", timeout=0.5)
        except socket.timeout:
            pass

    logger.info('ready')
Example #2
0
def pause_toggle():
    state = get_status().state
    if state == 'play':
        get_query('pause 1')
    elif state == 'pause':
        get_query('pause 0')
    elif state == 'stop':
        get_query('play')
Example #3
0
def single_toggle():
    if get_status().single:
        get_query('single 0')
    else:
        get_query('single 1')
Example #4
0
def random_toggle():
    if get_status().random:
        get_query('random 0')
    else:
        get_query('random 1')
Example #5
0
def repeat_toggle():
    if get_status().repeat:
        get_query('repeat 0')
    else:
        get_query('repeat 1')
Example #6
0
def previous():
    get_query('previous')
Example #7
0
def next():
    get_query('next')
Example #8
0
def stop():
    get_query('stop')
Example #9
0
def play(index=0):
    get_query('play {}'.format(index))
Example #10
0
def move(index, to):
    get_query('move {} {}'.format(index, to))
Example #11
0
def remove(index):
    get_query('delete {}'.format(index))
Example #12
0
def add_album(song):
    query = 'findadd AlbumArtist "{}" Date "{}" Album "{}"'
    get_query(query.format(song.albumartist, song.date, song.album))
Example #13
0
def add(song):
    get_query('add "{}"'.format(song.path))
Example #14
0
def clear():
    get_query('clear')