aboutsummaryrefslogtreecommitdiff
path: root/playlist-get
blob: 8895ae5f5cbefbf720b19bd99a99fc4112d43d22 (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
#!/bin/bash
#
# Get files for playlist using git-annex and mpd
#

# Parameters
BASENAME="`basename $0`"
PLAYLIST="$1"
MEDIA="/var/cache/media/noise"
PLAYLISTS="$MEDIA/playlists"

if [ -z "$PLAYLIST" ]; then
  echo "Usage: $BASENAME <playlist>"

  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

if [ "$BASENAME" == "playlist-drop" ]; then
  command="drop"
else
  command="get"
fi

echo "Getting files from $PLAYLISTS/$PLAYLIST.m3u..."

cat $PLAYLISTS/$PLAYLIST.m3u | while read file; do
  dir="$(dirname "$file")"
  base="$(basename "$file")"
  mkdir -p "$MEDIA/$dir"
  ( cd "$MEDIA/$dir" && git annex $command "$base" )
done