-
Notifications
You must be signed in to change notification settings - Fork 1
/
irank-android-sync
executable file
·80 lines (67 loc) · 2.08 KB
/
irank-android-sync
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
79
80
#!/bin/bash
irank_base="$HOME/Music/irank"
function overwrite_android_db {
cp "$irank_base/irank.sqlite" "$dest/"
}
function do_sync {
irank export -d "$dest" `cat ~/.config/irank/android-playlists`
overwrite_android_db
echo '-------- DISK USAGE: -----------'
du -h "$dest"
size=$(du -hs "$dest" | cut -f1)
remaining=$(df -h "$dest" | tail -n1 | awk '{print $4}')
notify-send "Android music sync finished" "$size used, $remaining free for $dest"
}
function num_remote_rating_changes {
if [ -r "$dest/irank.sqlite" ]; then
irank rating-sync --count
else
echo 0
fi
}
function apply_remote_rating_changes {
echo "updating ratings from device"
if [ ! -r "$dest/irank.sqlite" ]; then
return 0
fi
num_updates="$(num_remote_rating_changes)"
if [ "$num_updates" -eq 0 ]; then
return 0
fi
echo "applying $num_updates updates..."
irank rating-sync --no "$dest/irank.sqlite" || ( \
zenity --question --text='Rating update FAILED. Do you want to continue, ERASING all failed ratings?' --cancel-label='Cancel' --ok-label='ERASE' && \
zenity --question --text='SERIOUSLY?' --cancel-label='No!' --ok-label='Yes, ERASE ratings')
echo "updating playlists after rating update"
irank db
echo "copying new irank DB to device"
overwrite_android_db
}
if [ -z "$irank_test" ]; then
set -e
ask=0
do_update_ratings=1
do_update_playlists=1
if [ "$1" = "--ask" ]; then
ask=1
shift
fi
dest="$1"
echo $dest
if [ -z "$dest" ]; then
echo "Error: no destination given"
dest=$(grep '^android:' ~/.config/irank/paths | cut -c10-)
echo "using: $dest"
fi
set -x
[ -d "$dest" ]
if [ "$ask" = 1 ]; then
resp=$(echo -e "ALL\nSync all\nRATINGS\nUpdate ratings only ($(num_remote_rating_changes))" | zenity --list --title="iRank android" --column="action" --column=foo --text="iRank android sync:\nSelect action to perform" --hide-header --hide-column=1) || exit 0
[ "$resp" = 'ALL' ] || do_update_playlists=0
fi
if [ "$do_update_ratings" -eq 1 ]; then apply_remote_rating_changes; fi
if [ "$do_update_playlists" -eq 1 ]; then do_sync; fi
else
echo "# (sourced)"
dest="$HOME/.tmp/android"
fi