#!/bin/bash
#
-# Get files for playlist using git-annex and mpd
+# Get playlist files using git-annex.
#
# Parameters
DEST="$2"
MEDIA="/var/cache/media/noise"
PLAYLISTS="$MEDIA/playlists"
+APP="git annex"
if [ -z "$PLAYLIST" ]; then
echo "Usage: $BASENAME <playlist> [dest]"
if [ -z "$DEST" ]; then
echo "No destination specified"
exit 1
- fi
+ elif [ -d "$DEST" ]; then
+ APP="cp -Lv"
+ command=""
- DEST="--to $DEST"
- command="copy"
+ # Force absolute path
+ DEST="`cd $DEST && pwd`"
+ else
+ DEST="--to $DEST"
+ command="copy"
+ fi
else
command="get"
fi
dir="$(dirname "$file")"
base="$(basename "$file")"
mkdir -p "$MEDIA/$dir"
- ( cd "$MEDIA/$dir" && git annex $command "$base" $DEST )
-done
+ # Preserve folder structure
+ if [ -z "$command" ] && [ "$APP" == "cp -Lv" ]; then
+ prefix="/$dir"
+ mkdir -p "$DEST$prefix"
+ else
+ prefix=""
+ fi
+
+ ( cd "$MEDIA/$dir" && $APP $command "$base" "$DEST$prefix" )
+done