From a21c70a4c0ea4b3ee29f4e45678fe83d9955e0ca Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 11 Apr 2014 01:30:28 -0300 Subject: Cleaning up playlist-get --- playlist-get | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/playlist-get b/playlist-get index 67bd704..5aea297 100755 --- a/playlist-get +++ b/playlist-get @@ -11,6 +11,7 @@ MEDIA="/var/cache/media/noise" PLAYLISTS="$MEDIA/playlists" APP="git annex" +# Basic syntax if [ -z "$PLAYLIST" ]; then echo "Usage: $BASENAME [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 -- cgit v1.2.3