(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?))))