#!/bin/bash # # Get playlist files from an URL. # # Parameters BASENAME="`basename $0`" PLAYLIST="$1" # Check if [ -z "$PLAYLIST" ]; then echo "usage: $BASENAME " 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 # Process each file cat `basename $PLAYLIST` | while read file; do dirname="`dirname "$file"`" if [ "$BASENAME" == "playlist-wget" ]; then # Download playlist and all it's files preseving the folder structure mkdir -p "$dirname" wget -c "$PLAYLIST_BASE/$file" -O "$file" elif [ "$BASENAME" == "playlist-mpv" ]; then # Play using mpv mpv "$PLAYLIST_BASE/$file" elif [ "$BASENAME" == "playlist-mplayer" ]; then # Play using mplayer mplayer "$PLAYLIST_BASE/$file" fi done # Remove playlist if on stream mode # This should be implemented as a shell trap #if [ "$BASENAME" == "playlist-mpv" ] || [ "$BASENAME" == "playlist-mplayer" ]; then # rm `basename $PLAYLIST` #fi