aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2014-04-07 13:17:45 -0300
committerSilvio Rhatto <rhatto@riseup.net>2014-04-07 13:17:45 -0300
commit7185e822a83b127f2853a300d97d5d71430c9765 (patch)
treeb1b2bfead03580feb141ae4d42475c8b3373a9a7
parent9c61dcd74f8acc1694b89f34fd3aea4781263a19 (diff)
downloadscripts-7185e822a83b127f2853a300d97d5d71430c9765.tar.gz
scripts-7185e822a83b127f2853a300d97d5d71430c9765.tar.bz2
Destination folder support for playlist-copy
-rwxr-xr-xplaylist-get27
1 files 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 <playlist> [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