-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbspot-create-gpb-lists
executable file
·44 lines (39 loc) · 1.13 KB
/
bspot-create-gpb-lists
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
#!/usr/bin/env bash
#
# Take pub list1 and create public gpb lists.
token=${1:?}
file=${2:-${XDG_VAR_HOME:?}/lib/bspot/bspot_create_gpb_lists.bash}
# wants:
# -A dates[%s|playlist-id]
# -a dates_sorted (newest first)
# list1
. "$file" ||
exit 1
while read -r time uri; do
for d in "${dates_sorted[@]}"; do
((time >= ${d%|*})) &&
dates[$d]+=$uri, &&
break
done
done < <(
exec -- bspot getTracksObjects "$list1" "$token" |
exec -- jq -r '
.items[] |
"date --date=\(.added_at) +%s_\(([.track.artists[].uri]|join("/")))_\(.track.uri)"
' |
exec -- xargs -I {} -P 4 -- sh -c {} |
LC_ALL=C exec -- sort -t _ -k 1nr,1nr -k 2d,2d |
exec -- sed 's/^\([^_]*\)_\([^_]*\)_\([^_]*\)$/\1 \3/'
)
for k in "${!dates[@]}"; do
list2=${k#*|}
[[ $list2 == END ]] &&
continue
mapfile -t -d , <<<"${dates[$k]}"
command -- bspot clearList "$list2" "$token"
for ((i = ${#MAPFILE[@]} - 2; i >= 0; i--)); do
printf '%s\n' "${MAPFILE[$i]}"
done |
command -- bspot addTracks "$list2" "$token"
done
# vim: set ft=zsh :