diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2014-04-11 01:30:28 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2014-04-11 01:30:28 -0300 |
commit | a21c70a4c0ea4b3ee29f4e45678fe83d9955e0ca (patch) | |
tree | fd2bf885416707a5d932148ee52c4f353036a418 | |
parent | 7185e822a83b127f2853a300d97d5d71430c9765 (diff) | |
download | scripts-a21c70a4c0ea4b3ee29f4e45678fe83d9955e0ca.tar.gz scripts-a21c70a4c0ea4b3ee29f4e45678fe83d9955e0ca.tar.bz2 |
Cleaning up playlist-get
-rwxr-xr-x | playlist-get | 26 |
1 files 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 <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 |