You are not logged in.

#1 2008-11-14 10:16:22

pseb
Member
From: Marburg, Germany
Registered: 2007-09-27
Posts: 85

Headless MPD-Jukebox ... need some help/ideas...

Hello Archers,

i got an old IBM ThinkCentre at ebay and turned it into a music box. it's running arch linux (suprise!) and uses mpd for playing music. it is supposed to run without monitor, but i have an IR remote to control the box. (and i can ssh to it with my other pc.) works really fine so far.

now my problem: how to handle the music library with only an IR remote?
ok, playlists are one thing, but how to handle big playlists? i don't want to press the "next"-button 50 times, just to advance to a certain album.
so - does anyboy know a script for mpd that allows to advance to the next album in playlist? unfortunately, my scripting skills tend towards zero, otherwise i would have made a little script myself. can't be that difficult. just go to the next item in playlist with different "album"-tag - my collection is properly tagged wink
(note to self: learn at least shell scripting^^)

and maybe you have more ideas for controlling mpd via IR?

thx and greets,
pseb

Offline

#2 2008-11-14 13:08:46

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Headless MPD-Jukebox ... need some help/ideas...

It shouldn't be so hard...

#!/bin/bash
album="$(mpc --format %album% | head -n 1)"
if [ -z "$album" ]; then
        next_trackno=$(mpc playlist --format %album% | grep -A200 '^>' | grep -m1 -v -E '^( |>)[0-9]+\) *$' | cut -d')' -f1)
else
        next_trackno=$(mpc playlist --format %album% | grep -A200 '^>' | grep -m1 -v -F "$album" | cut -d')' -f1)
fi
if [ -z "$next_trackno" ]; then
        mpc next
else
        mpc play $next_trackno
fi

I think I covered the edge cases I can think of with that... Give it a shot. Let me know if (and how) it breaks.

EDIT: So many typos sad

Also, the case for missing album tag is still a bit funky.. I'll keep working on it.

Last edited by Daenyth (2008-11-14 13:38:13)

Offline

#3 2008-11-14 13:16:17

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Headless MPD-Jukebox ... need some help/ideas...

To skip to the next album:

mpc playlist --format %album% | perl -e'$album = ""; while(<>) {/^>\d+\) (.*)/ and $album = $1 and last;} while(<>) {/^.\d+\) $album/ and next; / (\d+)\)/ and exec("mpc play $1");}'

You need mpc and perl.
This will skip to the beginning of the current album; if you're on the first track already, it will skip to the first track of the previous album:

mpc playlist --format %album% | perl -e'$prev_album = ""; $prev_album_no = 0; $album = ""; $album_no = 0; while(<>) {if(/^ (\d+)\) (.*)/) {$prev_album eq $2 and next; $prev_album = $album; $prev_album_no = $album_no; $album = $2; $album_no = $1;} elsif(/^>/) {exec("mpc play $prev_album_no");}}'

If it doesn't find a previous album, nothing happens.

Last edited by peets (2008-11-14 13:45:20)

Offline

#4 2008-11-14 13:52:37

pseb
Member
From: Marburg, Germany
Registered: 2007-09-27
Posts: 85

Re: Headless MPD-Jukebox ... need some help/ideas...

oh, great! thank you very much peets & daenyth! you just made me happy wink
both work, but i think i'll stick to peets' solution.
ciao,
pseb

Offline

#5 2008-11-14 15:36:01

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Headless MPD-Jukebox ... need some help/ideas...

Just be careful when using his if you have anything missing an album tag.

Offline

Board footer

Powered by FluxBB