   (:require [com.stuartsierra.component :as component]
             [taoensso.timbre :as log]
             [espdig.components.db :as db]
-            [pl.danieljanus.tagsoup :as tagsoup]))
+            [pl.danieljanus.tagsoup :as tagsoup]
+            [clojure.core.async :as async]))
 
 (def tbl-name "yt_videos")
 (def running? (atom false))


(defn start-loop!
  [db feeds]
  (let [ended? (atom false)
        a      (agent nil)]
    (add-watch a :watcher (fn [_ _ _ state]
                            (record-entries! state)
                            (when (zero? (:idx state))
                              (reset! ended? true))))
    (doseq [[feed-idx feed] (reverse (map-indexed vector feeds))]
      (send a check-feed! db feed feed-idx))))

(defn create-schema!
  [db]

  [resp k]
  (some #(when (and (vector? %) (= (first %) k)) %) resp))

(defn fetch-feed-entries!
  [db feed]
  (log/debug "Checking feed:" feed)
  (when-let [resp (tagsoup/parse feed)]
    (hash-map :chan-id (-> resp (find-element :channelId) (last))
              :author  (-> resp (find-element :author) (find-element :name) (last))
              :entries (map #(hash-map :id (-> % (find-element :videoId) (last))
                                       :title (-> % (find-element :title) (last))
