diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2017-10-04 20:36:49 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2017-10-04 20:36:49 -0300 |
commit | 6295d11dac15034a7acb7a582e9cc8f058d2fac9 (patch) | |
tree | 87b48d7c3d73bb14db0343dc8b6d6f14fd603725 | |
parent | 64c90ec460374c76ba2df16ff12f8329995faa9b (diff) | |
download | playlister-6295d11dac15034a7acb7a582e9cc8f058d2fac9.tar.gz playlister-6295d11dac15034a7acb7a582e9cc8f058d2fac9.tar.bz2 |
Adds playlist-wget
-rwxr-xr-x | playlist-wget | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/playlist-wget b/playlist-wget new file mode 100755 index 0000000..b02fd60 --- /dev/null +++ b/playlist-wget @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Get playlist files from an URL. +# + +# Parameters +BASENAME="`basename $0`" +PLAYLIST="$1" + +# Check +if [ -z "$PLAYLIST" ]; then + echo "usage: $BASENAME <playlist-url>" + exit 1 +elif echo "$PLAYLIST" | grep -q -v '^http'; then + echo "$BASENAME: unsupported URL" + exit 1 +fi + +# Get playlist base from where we can find all the files +# We apply dirname twice because MPD stores playlists in a subfolder +PLAYLIST_BASE="$(dirname $(dirname $PLAYLIST))" + +# Download all playlist files in the current folder +# We use sed to replace new lines by the null character so xargs can detect each file correctly +#curl -s $PLAYLIST | sed -e "s|^|\"$PLAYLIST_BASE/|" -e 's|$|"|' -e 's|\n|\x0|' | xargs wget -c + +# Download the playlist +wget -c $PLAYLIST + +# Download playlist and all it's files preseving the folder structure +cat `basename $PLAYLIST` | while read file; do + dirname="`dirname "$file"`" + + mkdir -p "$dirname" + wget -c "$PLAYLIST_BASE/$file" -O "$file" +done |