From 7185e822a83b127f2853a300d97d5d71430c9765 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Mon, 7 Apr 2014 13:17:45 -0300 Subject: Destination folder support for playlist-copy --- playlist-get | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/playlist-get b/playlist-get index d43e296..67bd704 100755 --- a/playlist-get +++ b/playlist-get @@ -1,6 +1,6 @@ #!/bin/bash # -# Get files for playlist using git-annex and mpd +# Get playlist files using git-annex. # # Parameters @@ -9,6 +9,7 @@ PLAYLIST="$1" DEST="$2" MEDIA="/var/cache/media/noise" PLAYLISTS="$MEDIA/playlists" +APP="git annex" if [ -z "$PLAYLIST" ]; then echo "Usage: $BASENAME [dest]" @@ -31,10 +32,16 @@ elif [ "$BASENAME" == "playlist-copy" ]; then 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 @@ -45,6 +52,14 @@ 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 + # 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 -- cgit v1.2.3