diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2014-09-18 16:36:30 -0300 |
---|---|---|
committer | Silvio Rhatto <user@example.org> | 2014-09-18 16:36:30 -0300 |
commit | 221e7d6d0de9f58d0d82ba42a9fc55a157706f6d (patch) | |
tree | bf0b0e7ff4502c231cc02834618bbaa80c8e2adb /playlist-get | |
download | playlister-221e7d6d0de9f58d0d82ba42a9fc55a157706f6d.tar.gz playlister-221e7d6d0de9f58d0d82ba42a9fc55a157706f6d.tar.bz2 |
Initial import
Diffstat (limited to 'playlist-get')
-rwxr-xr-x | playlist-get | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/playlist-get b/playlist-get new file mode 100755 index 0000000..170f6be --- /dev/null +++ b/playlist-get @@ -0,0 +1,65 @@ +#!/bin/bash +# +# Get playlist files using git-annex. +# + +# Parameters +BASENAME="`basename $0`" +PLAYLIST="$1" +DEST="$2" +MEDIA="/var/cache/media/noise" +PLAYLISTS="$MEDIA/playlists" +APP="git annex" + +# Basic syntax +if [ -z "$PLAYLIST" ]; then + echo "Usage: $BASENAME <playlist> [dest]" + + if [ -d "$PLAYLISTS" ]; then + echo "" + echo "Available playlists: " + ls $PLAYLISTS + fi + + exit 1 +elif [ ! -f "$PLAYLISTS/$PLAYLIST.m3u" ]; then + echo "No such playlist $PLAYLISTS/$PLAYLIST.m3u" + exit 1 +fi + +# Set action +if [ "$BASENAME" == "playlist-drop" ]; then + action="drop" +elif [ "$BASENAME" == "playlist-copy" ]; then + if [ -z "$DEST" ]; then + echo "No destination specified" + exit 1 + elif [ -d "$DEST" ]; then + APP="cp -Lv" + action="" + + # Force absolute path + DEST="`cd $DEST && pwd`" + else + DEST="--to $DEST" + action="copy" + fi +else + action="get" +fi + +echo "Getting files from $PLAYLISTS/$PLAYLIST.m3u..." +cd $MEDIA + +# Process +cat $PLAYLISTS/$PLAYLIST.m3u | while read file; do + if [ -z "$action" ] && [ "$APP" == "cp -Lv" ]; then + prefix="/$(dirname "$file")" + mkdir -p "$DEST$prefix" + $APP $action "$file" "$DEST$prefix" + elif [ "$action" == "get" ]; then + $APP $action "$file" + else + $APP $action "$file" $DEST + fi +done |