]> gitweb.fluxo.info Git - scripts.git/commitdiff
Cleaning up playlist-get
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 11 Apr 2014 04:30:28 +0000 (01:30 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 11 Apr 2014 04:30:28 +0000 (01:30 -0300)
playlist-get

index 67bd70448478da5ec26b810d4042c85ef701feb9..5aea297cc3ff5344604f7f928b9427f348b4397d 100755 (executable)
@@ -11,6 +11,7 @@ MEDIA="/var/cache/media/noise"
 PLAYLISTS="$MEDIA/playlists"
 APP="git annex"
 
+# Basic syntax
 if [ -z "$PLAYLIST" ]; then
   echo "Usage: $BASENAME <playlist> [dest]"
 
@@ -26,40 +27,37 @@ elif [ ! -f "$PLAYLISTS/$PLAYLIST.m3u" ]; then
   exit 1
 fi
 
+# Set action
 if [ "$BASENAME" == "playlist-drop" ]; then
-  command="drop"
+  action="drop"
 elif [ "$BASENAME" == "playlist-copy" ]; then
   if [ -z "$DEST" ]; then
     echo "No destination specified"
     exit 1
   elif [ -d "$DEST" ]; then
     APP="cp -Lv"
-    command=""
+    action=""
 
     # Force absolute path
     DEST="`cd $DEST && pwd`"
   else
     DEST="--to $DEST"
-    command="copy"
+    action="copy"
   fi
 else
-  command="get"
+  action="get"
 fi
 
 echo "Getting files from $PLAYLISTS/$PLAYLIST.m3u..."
+cd $MEDIA
 
+# Process
 cat $PLAYLISTS/$PLAYLIST.m3u | while read file; do
-  dir="$(dirname "$file")"
-  base="$(basename "$file")"
-  mkdir -p "$MEDIA/$dir"
-
-  # Preserve folder structure
-  if [ -z "$command" ] && [ "$APP" == "cp -Lv" ]; then
-    prefix="/$dir"
+  if [ -z "$action" ] && [ "$APP" == "cp -Lv" ]; then
+    prefix="/$(dirname "$file")"
     mkdir -p "$DEST$prefix"
+    $APP $action "$file" "$DEST$prefix"
   else
-    prefix=""
+    $APP $action "$file"
   fi
-
-  ( cd "$MEDIA/$dir" && $APP $command "$base" "$DEST$prefix" )
 done