blob: 6d94ac31babdcdf4dc74812c53666ed725b477ce (
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
|
(ns dionysus.blacklist
(:require [duratom.core :as duratom]
[dionysus.spotify :as dspotify]))
(def blacklist (duratom/duratom :local-file
:file-path "./blacklist.edn"
:init []))
(defn add [share-url]
(when-let [parsed-url (dspotify/parse-share-url share-url)]
(swap! blacklist conj parsed-url)))
(defn change [index new-share-url]
(when-let [parsed-url (dspotify/parse-share-url new-share-url)]
(swap! blacklist assoc index parsed-url)))
(defn delete [index]
(when (and (not (neg? index))
(< index (.length @blacklist)))
(swap! blacklist (fn [coll]
(->> coll
(keep-indexed #(when (not= %1 index) %2))
vec)))))
(defn on-blacklist? [track-id]
(let [artist-ids (->> (dspotify/get-track! track-id)
:artists
(map :id))]
(or (->> @blacklist
(filter #(and (= (:type %) "track") (= (:id %) track-id)))
seq
some?)
(->> @blacklist
(filter #(and (= (:type %) "artist") (not= -1 (.indexOf artist-ids (:id %)))))
seq
some?))))
|