Example #1
0
def install_moc(add_lastfm=True):
    '''
    Install the MOC music player (http://moc.daper.net/). It will also install
    lastfmsubmitd (http://www.red-bean.com/decklin/lastfmsubmitd/) and set it
    up to submit your plays
    '''
    apps = ['moc']
    if add_lastfm:
        apps += ['lastfmsubmitd']
    install(*apps)

    if add_lastfm:
        username = prompt('Last.fm username?', validate=lambda v: _validate_not_empty(v, key='username'))
        password = prompt('Last.fm password?', validate=lambda v: _validate_not_empty(v, key='password'))
        # create lastfm config
        append('/etc/lastfmsubmitd.conf',
               '[account]\nuser = %s\npassword = %s' % (username, password, ),
               use_sudo=True)
        # add user to lastfm group so we can submit
        sudo('adduser %s lastfm' % env.user)
        # setup moc to submit to lastfm on song change (use script from
        # http://lukeplant.me.uk/blog/posts/moc-and-last-fm/ to only submit
        # when we're half way through)
        run('mkdir -p ~/.moc')
        with cd('~/.moc'):
            run('wget http://files.lukeplant.fastmail.fm/public/moc_submit_lastfm')
            run('chmod a+x moc_submit_lastfm')
            append('config',
                   'OnSongChange = "/home/%(user)s/.moc/moc_submit_lastfm --artist %%a --title %%t --length %%d --album %%r"' % env)