aboutsummaryrefslogtreecommitdiff
path: root/playlist-get
blob: 6c4dd51bed183585ddaaf3505c6d9656fef757c8 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
#
# Get playlist files using git-annex.
#

# Parameters
BASENAME="`basename $0`"
PLAYLIST="$1"
DEST="$2"
MEDIA="/var/cache/media/noise"
PLAYLISTS="$MEDIA/playlists"
APP="git annex"

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

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

  echo "Examples:"
  echo ""
  echo "$BASENAME ambient adb"
  echo "$BASENAME groove  /media/usb"
  echo "$BASENAME funk    remote-repository"

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

# Set action
if [ "$BASENAME" == "playlist-drop" ]; then
  action="drop"
elif [ "$BASENAME" == "playlist-copy" ]; then
  if [ -z "$DEST" ]; then
    echo "No destination specified"
    exit 1
  elif [ -d "$DEST" ]; then
    APP="cp -Lv"
    action=""

    # Force absolute path
    DEST="`cd $DEST && pwd`"
  elif [ "$DEST" == "adb" ]; then
    APP="adb"
    action="adb"
    DEST="/storage/emulated/0/Music"
  else
    DEST="--to $DEST"
    action="copy"
  fi
else
  action="get"
fi

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

# Process
cat $PLAYLISTS/$PLAYLIST.m3u | while read file; do
  if [ -z "$action" ] && [ "$APP" == "cp -Lv" ]; then
    prefix="/$(dirname "$file")"
    mkdir -p "$DEST$prefix"
    $APP $action "$file" "$DEST$prefix"
  elif [ "$action" == "get" ]; then
    $APP $action "$file"
  elif [ "$action" == "adb" ]; then
    prefix="/$(dirname "$file")"
    $APP push "$file" "$DEST$prefix"
  else
    $APP $action "$file" $DEST
  fi
done