 
       (node/md5-hex buffer))))
 
+(defn subdb-query
+  ([action] (subdb-query action {}))
+  ([action options]
+   (let [query (map->query (merge {:action action} options))
+         uri (str *subdb-endpoint* "?" query)]
+     {:uri     uri
+      :headers {"User-Agent" subdb-ua}})))
+
 (defn subdb-search-languages [hash]
   (go-catch
-    (let [uri (str *subdb-endpoint* "?action=search&hash=" hash "&versions")
-          params {:uri     uri
-                  :headers {"User-Agent" subdb-ua}}
+    (let [params (subdb-query "search" {:hash hash :versions ""})
           response (<? (http params))
           status (.-statusCode response)
           parse-language (fn [l] (let [[lang count] (.split l ":")]

  (:require [wilkerdev.util.nodejs :refer [lstat fopen fread http] :as node]))

(def ^:dynamic *subdb-endpoint* "http://api.thesubdb.com/")

(def subdb-ua "SubDB/1.0 (Subtitle Master/2.0.1; http://subtitlemaster.com)")



(defn subdb-upload [hash stream]
  (go-catch
    (let [params (subdb-query "upload")
          build-form (fn [f]
                       (.append f "hash" hash)
                       (.append f "file" stream #js {:contentType "application/octet-stream"}))
