]> gitweb.fluxo.info Git - scripts.git/commitdiff
Destination folder support for playlist-copy
authorSilvio Rhatto <rhatto@riseup.net>
Mon, 7 Apr 2014 16:17:45 +0000 (13:17 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Mon, 7 Apr 2014 16:17:45 +0000 (13:17 -0300)
playlist-get

index d43e296b44943c1da84569b2895df88ac02842be..67bd70448478da5ec26b810d4042c85ef701feb9 100755 (executable)
@@ -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