aboutsummaryrefslogtreecommitdiff
path: root/playlist-wget
blob: 247d450c5ec3b49916eac010dde315eff410901e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/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

# Dispatch
if [ "$BASENAME" == "playlist-wget" ]; then
  # Download the playlist
  wget -c $PLAYLIST

  cat `basename $PLAYLIST` | while read file; do
    dirname="`dirname "$file"`"

    # Download playlist and all it's files preseving the folder structure
    mkdir -p "$dirname"
    wget -c "$PLAYLIST_BASE/$file" -O "$file"
  done
elif [ "$BASENAME" == "playlist-mpv" ]; then
  # Play using mpv
  # We could call mpv directly with the playlist URL, but then the file locations would be wrong
  curl -s $PLAYLIST | sed -e "s|^|\"$PLAYLIST_BASE/|" -e 's|$|"|' -e 's|\n|\x0|' | xargs mpv
elif [ "$BASENAME" == "playlist-mplayer" ]; then
  # Play using mplayer
  curl -s $PLAYLIST | sed -e "s|^|\"$PLAYLIST_BASE/|" -e 's|$|"|' -e 's|\n|\x0|' | xargs mplayer
fi