Fandom

Music Player Daemon Community Wiki

Hack:musicplaynow

525pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

music.playnow / music.enqueue

plays or enqueues any file from any location, even outside the music_directory. made for integration with desktop shells (double clicking on files)

the script works by creating temporary symbolic links from outside your music_directory to a directory called 'temp' inside your music_directory. the files will be added to the DB on the fly and played immediately (or enqueued)

Installation:

save the script below as /usr/local/bin/music.playnow. if you're interested in the enqueue functionality also, create a symlink from /usr/local/bin/music.playnow to /usr/local/bin/music.enqueue (really, you can call it anyPrefixYouWant.playnow and anyPrefixYouWant.enqueue if you like.... just maintain the suffix, or modify the script :P)

create a 'temp' directory in your music_directory. it will be used for symlinking files that are outside ypour music directory.

#!/bin/bash
[[ -z "$1" ]] && exit
MUSIC_DIR="`awk '/^music_directory/ {print $2}' /etc/mpd.conf | cut -d'"' -f2`"
# we need a temporary directory in music_directory:
mkdir -p "${MUSIC_DIR}/temp"
BASENAME="`basename "$1"`"
DIRNAME="`dirname "$1"`"
if [[ "$DIRNAME" = "." ]]; then DIRNAME="$PWD"; fi
DOLLAR1="${DIRNAME}/${BASENAME}"
if [[ "$DOLLAR1" = "$MUSIC_DIR"* ]]; then
        # file is under $MUSIC_DIR
        RELATIVE_NAME="`echo "$DOLLAR1" | sed -e "s|^$MUSIC_DIR[/]*||"`"
else
        # file is not under $MUSIC_DIR
        # make a temporary symlink to it
        FILENAME="${MUSIC_DIR}/temp/${BASENAME}"
        rm -f "${FILENAME}"
        ln -s "${DIRNAME}/${BASENAME}" "${FILENAME}"
        RELATIVE_NAME="temp/${BASENAME}"
fi
mpc --no-status update "${RELATIVE_NAME}"
# wait for mpd finishes updating the DB
while mpc | grep -q '^Updating DB '; do sleep "0.1s"; done
ACTION="`basename $0 | sed -e 's/^.*\.//'`"
case $ACTION in
enqueue)
        mpc --no-status add "${RELATIVE_NAME}"
        mpc --no-status play
        ;;
playnow|*)
        mpc --no-status clear
        mpc --no-status add "${RELATIVE_NAME}"
        mpc --no-status play
        ;;
esac

Also on Fandom

Random Wiki