#!/bin/bash # # Get files for playlist using git-annex and mpd # # Parameters BASENAME="`basename $0`" PLAYLIST="$1" DEST="$2" MEDIA="/var/cache/media/noise" PLAYLISTS="$MEDIA/playlists" if [ -z "$PLAYLIST" ]; then echo "Usage: $BASENAME [dest]" if [ -d "$PLAYLISTS" ]; then echo "" echo "Available playlists: " ls $PLAYLISTS fi exit 1 elif [ ! -f "$PLAYLISTS/$PLAYLIST.m3u" ]; then echo "No such playlist $PLAYLISTS/$PLAYLIST.m3u" exit 1 fi if [ "$BASENAME" == "playlist-drop" ]; then command="drop" elif [ "$BASENAME" == "playlist-copy" ]; then if [ -z "$DEST" ]; then echo "No destination specified" exit 1 fi DEST="--to $DEST" command="copy" else command="get" fi echo "Getting files from $PLAYLISTS/$PLAYLIST.m3u..." cat $PLAYLISTS/$PLAYLIST.m3u | while read file; do dir="$(dirname "$file")" base="$(basename "$file")" mkdir -p "$MEDIA/$dir" ( cd "$MEDIA/$dir" && git annex $command "$base" $DEST ) done