LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Random song constrained by keyword on MPC

Posted 08-12-2010 at 12:17 AM by the dsc
Updated 08-12-2010 at 12:21 AM by the dsc
Tags mpc, music

Save it as a script, perhaps even as an alias:

Code:
mpc play `shuf -e $(mpc playlist -f "[(%position%) %artist% %title% %file%]" |egrep $1 | grep -Eo "\(.*\)"| sed 's:).*::g' | sed 's:(::g') -n 1`
Then type at some terminal:

mpcr[andom] <artist/keyword>

(or however you chose to name/alias it)

And mpc will play a random song from the pool resulting from the keyword filter.

I guess the whole chain of pipes could probably be elegantly replaced by some awesome sed parameter, but that will do it as it is, anyway.
Posted in Uncategorized
Views 1983 Comments 1
« Prev     Main     Next »
Total Comments 1

Comments

  1. Old Comment
    Newer, improved version:

    Code:
    #!/bin/sh
    
    for i in $* ; do # search term parsing loop
    
    a="$a grep -i $i |" # makes a chain of greps from the search terms 
    
    done
    
    a="mpc playlist -f \"[(@(%position%)@) %artist% %title% %file%]\" | $a"    # adds a start to the grep chain - a start which is the generation of  playist with special character markings for easier later extraction of the music number
    
    mpc play `shuf -e $(eval $(echo $a| sed 's/.\{2\}$//') | sed 's:)@).*::g' | sed 's:(@(::g') -n 1 ` # evals the search, then extract the number via sed, plays it
    
    obmpc.sh osd &
    Now the search parameters aren't restricted by a single word, so it can work both as a randomizer when the parameters are broad, "mpcr band X", or a quick way to get a specific song, "mpcr bandx part of the song tittle"


    "obmpc.sh osd" is just a function of a different MPD-related script I have, would only show the selected song with aosd_cat at the bottom of the screen for a second.
    Posted 10-16-2011 at 07:42 PM by the dsc the dsc is offline
    Updated 10-16-2011 at 09:31 PM by the dsc
 

  



All times are GMT -5. The time now is 06:30 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration