Nicolás Brailovsky


A modern blog

mocp rand

author Posted by: nico on date Jul 23rd, 2009 | filed Filed under: Console, Programming
music-score I’m quite sure everyone reading this must have a respectable, if not massive, music collection. In this days and age is difficult finding someone who doesn’t. It’s also difficult to choose one, and only one, disk to listen at any given moment. Until we’re upgraded to support concurrent music listening we’re better of with a random disk selector, which is exactly what this little script does:
  1. #!/bin/bash
  2.  
  3. SEARCH_DIR=‘/home/nico/Música’
  4. START_RANDOM=1
  5. RAND_MAX=32767
  6.  
  7. while (( 1 )); do
  8. NUM_DISCS=$(find $SEARCH_DIR -type d|wc -l)
  9. RAND=$(($NUM_DISCS * $RANDOM / $RAND_MAX))
  10. RAND_DISC=$(find $SEARCH_DIR -type d | head -n $RAND | tail -n 1)
  11.  
  12. # Wake up moc
  13. mocp -FS 2>/dev/null >/dev/null &
  14. mocp -pca "$RAND_DISC" &
  15. echo "Playing $RAND_DISC"
  16.  
  17. # Start from a random file?
  18. if (( $START_RANDOM )); then
  19. mocp –on shuffle &
  20. mocp -f &
  21. mocp –off shuffle &
  22. fi
  23.  
  24. read
  25. done
Of course, it requires mocp, my favorite music (on console) player. And obviously, you’ll have to configure SEARCH_DIR but I’m sure some bash hacking is not that hard.
Beware though, using this + cron may have the undesired effect of awakening to the pleasant music of Cannibal Corpse.
0601_ozzy_osbourne_c


tagOne Response to “mocp rand”

  1. Nicolás Brailovsky » Blog Archive » Sorting by random in bash and mocp random updated Said,

    [...] And now you can sort by random your output using sort -R. Why would this be useful? Well, I updated my mocp random script with a [...]

     Add A Comment

trackback Trackback URI | rsscomment Comments RSS