Created
May 16, 2015 05:11
-
-
Save jesvs/87364f128148359a62ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# MPD recent songs playlist creator | |
# Usage: mpd_recent_playlist.sh [days] | |
# Config starts here | |
MPC_CONF=/etc/mpd.conf | |
PLAYLIST_TITLE="Recently Added" | |
FILETYPES="mp3|m4a|flac|ogg" | |
# Config ends here | |
DAYS_OLD=$1 | |
if [ -e $DAYS_OLD ]; then | |
DAYS_OLD=30 | |
fi | |
PLAYLIST_FILE=$(gawk 'match($0, /playlist_directory.*"(.*)"/, arr) { print arr[1] }' $MPC_CONF)/${PLAYLIST_TITLE}.m3u | |
MUSIC_DIR=$(gawk 'match($0, /music_directory.*"(.*)"/, arr) { print arr[1] }' $MPC_CONF) | |
MUSIC_DIR_ESCAPED=$(echo $MUSIC_DIR | sed -e 's/[]\/$*.^|[]/\\&/g') | |
find -L $MUSIC_DIR -type f -mtime -${DAYS_OLD} -regex ".*\.(${FILETYPES})$" | awk "{ sub(/^${MUSIC_DIR_ESCAPED}(\/)?/, \"\"); print }" > "$PLAYLIST_FILE" | |
TOTAL_FILES=$(cat "$PLAYLIST_FILE" | wc -l) | |
echo Created the $PLAYLIST_TITLE playlist with $TOTAL_FILES songs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you explain how this works?