Simple shell script wrapper for mplayer + last.fm

 
    • xpasky sa...
    • Användare
    • 8 feb 2008, 03:52

    Simple shell script wrapper for mplayer + last.fm

    I use the following simple script (as /usr/local/bin/m so I can write just 'm track.mp3') as mplayer wrapper that reports stuff to Last.fm:

    http://pasky.or.cz/~pasky/dev/mplayer/lastfm

    Hope it will be useful for someone else too. Linewrapped inline version follows ;-) :

    #!/bin/sh
    # Prerequisites:
    # * Get and setup http://www.red-bean.com/~decklin/software/lastfmsubmitd/
    # * perl -MCPAN -e 'install MP3::Info' (check your distro for perl-MP3-Info package first)
    # Install this script with some handy name, e.g. '/usr/local/bin/m'.
    # Known problems:
    # * 'q' interrupts only playback of current file; press and *hold* ctrl-C
    # * even if you skip file immediately with Enter or 'q', it gets scrobbled - see below
    #
    # Song info will be submitted after you finish listening to the song;
    # if you are SKIPPING a track and don't want it to appear, press Ctrl-C
    # in mplayer - it will skip to the next track without scrobbling.

    kill -0 `cat /var/run/lastfm/lastfmsubmitd.pid` 2>&1 || lastfmsubmitd

    for f; do
    mplayer "$f" || continue

    case "$f" in
    *.mp3)
    perl -MMP3::Info -le \
    'my $f = $ARGV[0]; my $i = new MP3::Info $f;
    print $i->time; print $i->artist; print $i->album; print $i->title;' \
    "$f" |
    {
    read time;
    read artist;
    read album;
    read title;
    [ "$album" = "1" ] && album=""
    echo "## Last.FM : -l \"$time\" -a \"$artist\" -b \"$album\" --title \"$title\""
    /usr/local/lib/lastfmsubmitd/lastfmsubmit \
    -l "$time" -a "$artist" -b "$album" --title "$title"
    }
    ;;
    esac
    done

  • wonderful! thanks a lot. simple yet effective.

    • alex_pol sa...
    • Användare
    • 25 jan 2009, 16:59
    i commented out "kill -0 `cat /var/run/lastfm/lastfmsubmitd.pid` 2>&1 || lastfmsubmitd" because lastfmsubmitd writes wrong pid. a bit better can be replacing that line with " ps aux | grep lastfmsubmitd | grep -v grep | cut -d " " -f 6 || lastfmsubmitd"

    • alex_pol sa...
    • Användare
    • 25 jan 2009, 17:00
    btw, thanks for the script!

  • Just to let you know, i added m4a support and hosted your script at github.org:

    http://github.com/sschober/lastfmplayer

    thx :)

    'never whistle while you're pissing!'
  • Thank you for this script.

    To satisfy its dependency, I prepared and submitting a lastfmsubmitd port in FreeBSD.

    I'm also considering to add a port for this script, but "lastfm" seems rather generic (e.g. I've a /home/dereckson/bin/lastfm script to print what a user is listening to or the last 10 titles).

    What would be the ideal name? lastfmplayer is rather obscure too, as the script launch mplayer and scrobble (some could expect from a a lastfmplayer command it allows to play last.fm radios).

    • GioMac sa...
    • Användare
    • 8 maj 2011, 23:45
    aaaaaaaaaaa, you're a great crazy man, you know? might be funny windows guys, but we are high :D

    Last.fm rules!
  • No Ogg Vorbis support?

    It would be helpful if this script could be modified to support free file formats such as Ogg Vorbis and FLAC.

Anonyma användare kan inte skriva inlägg. Vänligen logga in eller skapa ett konto för att göra inlägg i forumen.