aboutsummaryrefslogtreecommitdiff
path: root/playlist-check
blob: 57cd8d2b28e33e451b6b2bf522951d957340b329 (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
47
48
49
50
#!/bin/bash
#
# Check for playlist files.
#

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

# Process
function playlist_check {
  local cwd="`pwd`"

  cd $MEDIA

  cat $PLAYLISTS/$PLAYLIST.m3u | while read file; do
    #if [ ! -e "$file" ]; then
    if ! ls "$file" &> /dev/null; then
      echo "$PLAYLIST: missing file: $file"
    fi
  done

  cd $cwd
}

# Basic syntax
if [ "$PLAYLIST" == "--help" ]; then
  echo "Usage: $BASENAME <playlist>"

  if [ -d "$PLAYLISTS" ]; then
    echo ""
    echo "Available playlists: "
    ls $PLAYLISTS
  fi

  exit 1
elif [ -z "$PLAYLIST" ]; then
  for playlist in $PLAYLISTS/*m3u; do
    PLAYLIST="`basename $playlist .m3u`"
    playlist_check
  done

elif [ ! -f "$PLAYLISTS/$PLAYLIST.m3u" ]; then
  echo "No such playlist $PLAYLISTS/$PLAYLIST.m3u"
  exit 1
else
  playlist_check
fi