mirror of
https://github.com/kiranshila/Doplarr.git
synced 2026-08-01 17:58:37 -04:00
Working on Readarr
This commit is contained in:
@@ -35,15 +35,15 @@
|
||||
[result ::bs/result]
|
||||
(a/go
|
||||
(let [quality-profiles (a/<! (impl/quality-profiles))
|
||||
{:keys [default-quality-profile]} env]
|
||||
{:keys [default-radarr-quality-profile]} env]
|
||||
{:quality-profile-id (cond
|
||||
(= 1 (count quality-profiles)) (->> quality-profiles
|
||||
first
|
||||
:id)
|
||||
default-quality-profile (->> quality-profiles
|
||||
(filter #(= default-quality-profile (:name %)))
|
||||
first
|
||||
:id)
|
||||
default-radarr-quality-profile (->> quality-profiles
|
||||
(filter #(= default-radarr-quality-profile (:name %)))
|
||||
first
|
||||
:id)
|
||||
:else quality-profiles)})))
|
||||
|
||||
(defn-spec request-embed any?
|
||||
|
||||
37
src/doplarr/backends/readarr.clj
Normal file
37
src/doplarr/backends/readarr.clj
Normal file
@@ -0,0 +1,37 @@
|
||||
(ns doplarr.backends.readarr
|
||||
(:require
|
||||
[config.core :refer [env]]
|
||||
[clojure.core.async :as a]
|
||||
[orchestra.core :refer [defn-spec]]
|
||||
[doplarr.utils :as utils]
|
||||
[doplarr.backends.specs :as bs]
|
||||
[doplarr.backends.readarr.impl :as impl]))
|
||||
|
||||
(defn-spec search any?
|
||||
[term string?]
|
||||
(utils/request-and-process-body
|
||||
impl/GET
|
||||
#(->> (utils/from-camel %)
|
||||
impl/filter-books)
|
||||
"/book/lookup"
|
||||
{:query-params {:term term}}))
|
||||
|
||||
(defn-spec additional-options any?
|
||||
[result ::bs/result]
|
||||
(a/go
|
||||
(let [quality-profiles (a/<! (impl/quality-profiles))
|
||||
{:keys [default-readarr-quality-profile]} env]
|
||||
{:quality-profile-id (if (= 1 (count quality-profiles))
|
||||
(->> quality-profiles
|
||||
first
|
||||
:id)
|
||||
(->> quality-profiles
|
||||
(filter #(= default-readarr-quality-profile (:name %)))
|
||||
first
|
||||
:id))})))
|
||||
|
||||
(defn request [])
|
||||
|
||||
#_(defn request-embed [{:keys [title]}]
|
||||
(a/go
|
||||
(let [details (a/! (impl/get-from-id))])))
|
||||
37
src/doplarr/backends/readarr/impl.clj
Normal file
37
src/doplarr/backends/readarr/impl.clj
Normal file
@@ -0,0 +1,37 @@
|
||||
(ns doplarr.backends.readarr.impl
|
||||
(:require
|
||||
[orchestra.core :refer [defn-spec]]
|
||||
[config.core :refer [env]]
|
||||
[doplarr.utils :as utils]
|
||||
[clojure.core.async :as a]
|
||||
[doplarr.backends.specs :as bs]))
|
||||
|
||||
(def base-url (delay (str (:readarr-url env) "/api/v1")))
|
||||
(def api-key (delay (:readarr-api env)))
|
||||
|
||||
(defn GET [endpoint & [params]]
|
||||
(utils/http-request :get (str @base-url endpoint) @api-key params))
|
||||
|
||||
(defn POST [endpoint & [params]]
|
||||
(utils/http-request :post (str @base-url endpoint) @api-key params))
|
||||
|
||||
(def rootfolder (delay (a/<!! (utils/request-and-process-body GET #(get (first %) "path") "/rootfolder"))))
|
||||
|
||||
(defn filter-books [search-results]
|
||||
(->> search-results
|
||||
(map #(select-keys % [:title :foreign-book-id :author]))
|
||||
(map #(assoc % :author (get-in % [:author :author-name])))))
|
||||
|
||||
(defn quality-profiles []
|
||||
(utils/request-and-process-body
|
||||
GET
|
||||
#(map utils/process-profile %)
|
||||
"/qualityprofile"))
|
||||
|
||||
(defn metadata-profiles []
|
||||
(utils/request-and-process-body
|
||||
GET
|
||||
#(map utils/process-profile %)
|
||||
"/metadataprofile"))
|
||||
|
||||
(defn get-from-id [id])
|
||||
@@ -46,7 +46,7 @@
|
||||
(map #(let [ssn (:season-number %)]
|
||||
(hash-map :id ssn :name (str ssn)))))
|
||||
{:keys [default-language-profile
|
||||
default-quality-profile
|
||||
default-sonarr-quality-profile
|
||||
partial-seasons]} env]
|
||||
{:season (cond
|
||||
(= 1 (count seasons)) (->> seasons
|
||||
@@ -58,10 +58,10 @@
|
||||
(= 1 (count quality-profiles)) (->> quality-profiles
|
||||
first
|
||||
:id)
|
||||
default-quality-profile (->> quality-profiles
|
||||
(filter #(= default-quality-profile (:name %)))
|
||||
first
|
||||
:id)
|
||||
default-sonarr-quality-profile (->> quality-profiles
|
||||
(filter #(= default-sonarr-quality-profile (:name %)))
|
||||
first
|
||||
:id)
|
||||
:else quality-profiles)
|
||||
:language-profile-id (cond
|
||||
(= 1 (count language-profiles)) (->> language-profiles
|
||||
|
||||
@@ -26,9 +26,14 @@
|
||||
(spec/def ::ignore-episodes-with-files boolean?)
|
||||
(spec/def ::search-for-missing-episodes boolean?)
|
||||
|
||||
; Books
|
||||
(spec/def ::foreign-book-id pos-int?)
|
||||
(spec/def ::author string?)
|
||||
|
||||
; Searching
|
||||
(spec/def ::result (spec/keys :req-un [::title ::year
|
||||
(or ::id ::tvdb-id ::tmdb-id)]))
|
||||
(spec/def ::result (spec/keys :req-un [::title
|
||||
(or ::year ::author)
|
||||
(or ::id ::tvdb-id ::tmdb-id ::foreign-book-id)]))
|
||||
|
||||
; Doplarr Internals
|
||||
(spec/def ::status (or #{:unauthorized :unknown :pending :processing :partially-available :available}
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
(spec/explain-data ::specs/config env))
|
||||
|
||||
(defn available-backends []
|
||||
(let [{:keys [sonarr-url radarr-url overseerr-url]} env]
|
||||
(let [{:keys [sonarr-url radarr-url overseerr-url readarr-url]} env]
|
||||
(cond-> #{}
|
||||
readarr-url (conj :readarr)
|
||||
sonarr-url (conj :sonarr)
|
||||
radarr-url (conj :radarr)
|
||||
overseerr-url (conj :overseerr))))
|
||||
|
||||
@@ -5,18 +5,25 @@
|
||||
(spec/def ::sonarr-url string?)
|
||||
(spec/def ::radarr-url string?)
|
||||
(spec/def ::overseerr-url string?)
|
||||
(spec/def ::readarr-url string?)
|
||||
|
||||
; Backend API keys
|
||||
(spec/def ::sonarr-api string?)
|
||||
(spec/def ::radarr-api string?)
|
||||
(spec/def ::overseerr-api string?)
|
||||
(spec/def ::readarr-api string?)
|
||||
|
||||
; Discord bot token
|
||||
(spec/def ::bot-token string?)
|
||||
|
||||
; Additional required keys
|
||||
(spec/def ::readarr-quality-profile string?)
|
||||
(spec/def ::readarr-metadata-profile string?)
|
||||
|
||||
; Optional settings
|
||||
(spec/def ::partial-seasons boolean?)
|
||||
(spec/def ::default-quality-profile string?)
|
||||
(spec/def ::default-radarr-quality-profile string?)
|
||||
(spec/def ::default-sonarr-quality-profile string?)
|
||||
(spec/def ::default-language-profile string?)
|
||||
(spec/def ::role-id string?)
|
||||
(spec/def ::max-results pos-int?)
|
||||
@@ -24,10 +31,12 @@
|
||||
; Complete Config
|
||||
(spec/def ::config (spec/keys :req-un [(or (and ::sonarr-url ::sonarr-api)
|
||||
(and ::radarr-url ::radarr-api)
|
||||
(and ::overseerr-url ::overseerr-api))
|
||||
(and ::overseerr-url ::overseerr-api)
|
||||
(and ::readarr-url ::readarr-api ::readarr-quality-profile ::readarr-metadata-profile))
|
||||
::bot-token]
|
||||
:opt-un [::partial-seasons
|
||||
::default-quality-profile
|
||||
::default-radarr-quality-profile
|
||||
::default-sonarr-quality-profile
|
||||
::default-language-profile
|
||||
::role-id
|
||||
::max-results]))
|
||||
|
||||
@@ -13,11 +13,12 @@
|
||||
(:gen-class))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;; Backend public interfaces
|
||||
(def backends [:radarr :sonarr :overseerr])
|
||||
(def backends [:radarr :sonarr :overseerr :readarr])
|
||||
(def backend-fns [:search :request :additional-options :request-embed])
|
||||
|
||||
(def media-backends {:movie [:overseerr :radarr]
|
||||
:series [:overseerr :sonarr]})
|
||||
:series [:overseerr :sonarr]
|
||||
:book [:readarr]})
|
||||
|
||||
(defn derive-backend! [backend]
|
||||
(derive (keyword "backend" (name backend)) :doplarr/backend))
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
:options
|
||||
(into [] (for [media media-types]
|
||||
{:type 1
|
||||
:name media
|
||||
:description (str "Request " media)
|
||||
:name (name media)
|
||||
:description (str "Request " (name media))
|
||||
:options [{:type 3
|
||||
:name "query"
|
||||
:description "Query"
|
||||
@@ -75,7 +75,7 @@
|
||||
|
||||
(defn select-menu-option [index result]
|
||||
{:label (or (:title result) (:name result))
|
||||
:description (:year result)
|
||||
:description (or (:year result) (:author result))
|
||||
:value index})
|
||||
|
||||
(defn dropdown [content id options]
|
||||
|
||||
Reference in New Issue
Block a user