mirror of
https://github.com/kiranshila/Doplarr.git
synced 2026-03-31 06:23:48 -04:00
Adding rootfolder selection
This commit is contained in:
14
.dropboxignore
Normal file
14
.dropboxignore
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# ----
|
||||||
|
# Automatically Generated .dropboxignore file at Sun Jan 30 22:58:11 PST 2022
|
||||||
|
# ----
|
||||||
|
.DS_Store
|
||||||
|
pom.xml
|
||||||
|
pom.xml.asc
|
||||||
|
*.jar
|
||||||
|
*.class
|
||||||
|
.nrepl-port
|
||||||
|
.cpcache/
|
||||||
|
.lsp/
|
||||||
|
.clj-kondo/
|
||||||
|
target/
|
||||||
|
# ----
|
||||||
@@ -17,30 +17,39 @@
|
|||||||
(defn additional-options [_ _]
|
(defn additional-options [_ _]
|
||||||
(a/go
|
(a/go
|
||||||
(let [quality-profiles (a/<! (impl/quality-profiles))
|
(let [quality-profiles (a/<! (impl/quality-profiles))
|
||||||
|
rootfolders (a/<! (impl/rootfolders))
|
||||||
{:keys [radarr/quality-profile]} @state/config
|
{:keys [radarr/quality-profile]} @state/config
|
||||||
default-profile-id (utils/profile-name-id quality-profiles quality-profile)]
|
default-profile-id (utils/id-from-name quality-profiles quality-profile)]
|
||||||
(when (and quality-profile (nil? default-profile-id))
|
(when (and quality-profile (nil? default-profile-id))
|
||||||
(warn "Default quality profile in config doesn't exist in backend, check spelling"))
|
(warn "Default quality profile in config doesn't exist in backend, check spelling"))
|
||||||
{:quality-profile-id
|
{:quality-profile-id
|
||||||
(cond
|
(cond
|
||||||
default-profile-id default-profile-id
|
default-profile-id default-profile-id
|
||||||
(= 1 (count quality-profiles)) (:id (first quality-profiles))
|
(= 1 (count quality-profiles)) (:id (first quality-profiles))
|
||||||
:else quality-profiles)})))
|
:else quality-profiles)
|
||||||
|
:rootfolder-id
|
||||||
|
(cond
|
||||||
|
(= 1 (count rootfolders)) (:id (first rootfolders))
|
||||||
|
:else rootfolders)})))
|
||||||
|
|
||||||
(defn request-embed [{:keys [title quality-profile-id tmdb-id]} _]
|
(defn request-embed [{:keys [title quality-profile-id tmdb-id rootfolder-id]} _]
|
||||||
(a/go
|
(a/go
|
||||||
(let [quality-profiles (a/<! (impl/quality-profiles))
|
(let [rootfolders (a/<! (impl/rootfolders))
|
||||||
|
quality-profiles (a/<! (impl/quality-profiles))
|
||||||
details (a/<! (impl/get-from-tmdb tmdb-id))]
|
details (a/<! (impl/get-from-tmdb tmdb-id))]
|
||||||
{:title title
|
{:title title
|
||||||
:overview (:overview details)
|
:overview (:overview details)
|
||||||
:poster (:remote-poster details)
|
:poster (:remote-poster details)
|
||||||
:media-type :movie
|
:media-type :movie
|
||||||
:request-formats [""]
|
:request-formats [""]
|
||||||
:quality-profile (utils/profile-id-name quality-profiles quality-profile-id)})))
|
:rootfolder (utils/name-from-id rootfolders rootfolder-id)
|
||||||
|
:quality-profile (utils/name-from-id quality-profiles quality-profile-id)})))
|
||||||
|
|
||||||
(defn request [payload _]
|
(defn request [payload _]
|
||||||
(a/go
|
(a/go
|
||||||
(let [status (impl/status (a/<! (impl/get-from-tmdb (:tmdb-id payload))))]
|
(let [status (impl/status (a/<! (impl/get-from-tmdb (:tmdb-id payload))))
|
||||||
|
rfs (a/<! (impl/rootfolders))
|
||||||
|
payload (assoc payload :root-folder-path (utils/name-from-id rfs (:rootfolder-id payload)))]
|
||||||
(if status
|
(if status
|
||||||
status
|
status
|
||||||
(->> (a/<! (impl/POST "/movie" {:form-params (utils/to-camel (impl/request-payload payload))
|
(->> (a/<! (impl/POST "/movie" {:form-params (utils/to-camel (impl/request-payload payload))
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
(ns doplarr.backends.radarr.impl
|
(ns doplarr.backends.radarr.impl
|
||||||
(:require
|
(:require
|
||||||
[clojure.core.async :as a]
|
|
||||||
[doplarr.state :as state]
|
[doplarr.state :as state]
|
||||||
[doplarr.utils :as utils]))
|
[doplarr.utils :as utils]))
|
||||||
|
|
||||||
@@ -13,14 +12,24 @@
|
|||||||
(defn POST [endpoint & [params]]
|
(defn POST [endpoint & [params]]
|
||||||
(utils/http-request :post (str @base-url endpoint) @api-key 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 quality-profiles []
|
(defn quality-profiles []
|
||||||
(utils/request-and-process-body
|
(utils/request-and-process-body
|
||||||
GET
|
GET
|
||||||
#(map utils/process-profile %)
|
#(map utils/process-profile %)
|
||||||
"/qualityProfile"))
|
"/qualityProfile"))
|
||||||
|
|
||||||
|
(defn rootfolders []
|
||||||
|
(utils/request-and-process-body
|
||||||
|
GET
|
||||||
|
utils/process-rootfolders
|
||||||
|
"/rootfolder"))
|
||||||
|
|
||||||
|
(defn tags []
|
||||||
|
(utils/request-and-process-body
|
||||||
|
GET
|
||||||
|
utils/process-tags
|
||||||
|
"/tag"))
|
||||||
|
|
||||||
(defn get-from-tmdb [tmdb-id]
|
(defn get-from-tmdb [tmdb-id]
|
||||||
(utils/request-and-process-body
|
(utils/request-and-process-body
|
||||||
GET
|
GET
|
||||||
@@ -40,7 +49,6 @@
|
|||||||
|
|
||||||
(defn request-payload [payload]
|
(defn request-payload [payload]
|
||||||
(-> payload
|
(-> payload
|
||||||
(select-keys [:title :tmdb-id :quality-profile-id])
|
(select-keys [:title :tmdb-id :quality-profile-id :root-folder-path])
|
||||||
(assoc :monitored true
|
(assoc :monitored true
|
||||||
:root-folder-path @rootfolder
|
|
||||||
:add-options {:search-for-movie true})))
|
:add-options {:search-for-movie true})))
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
(a/go
|
(a/go
|
||||||
(let [quality-profiles (a/<! (impl/quality-profiles))
|
(let [quality-profiles (a/<! (impl/quality-profiles))
|
||||||
language-profiles (a/<! (impl/language-profiles))
|
language-profiles (a/<! (impl/language-profiles))
|
||||||
|
rootfolders (a/<! (impl/rootfolders))
|
||||||
details (a/<! (impl/get-from-tvdb (:tvdb-id result)))
|
details (a/<! (impl/get-from-tvdb (:tvdb-id result)))
|
||||||
seasons (->> (:seasons details)
|
seasons (->> (:seasons details)
|
||||||
(filter #(pos? (:season-number %)))
|
(filter #(pos? (:season-number %)))
|
||||||
@@ -26,8 +27,8 @@
|
|||||||
{:keys [sonarr/language-profile
|
{:keys [sonarr/language-profile
|
||||||
sonarr/quality-profile
|
sonarr/quality-profile
|
||||||
partial-seasons]} @state/config
|
partial-seasons]} @state/config
|
||||||
default-profile-id (utils/profile-name-id quality-profiles quality-profile)
|
default-profile-id (utils/id-from-name quality-profiles quality-profile)
|
||||||
default-language-id (utils/profile-name-id language-profiles language-profile)]
|
default-language-id (utils/id-from-name language-profiles language-profile)]
|
||||||
(when (and quality-profile (nil? default-profile-id))
|
(when (and quality-profile (nil? default-profile-id))
|
||||||
(warn "Default quality profile in config doesn't exist in backend, check spelling"))
|
(warn "Default quality profile in config doesn't exist in backend, check spelling"))
|
||||||
(when (and language-profile (nil? default-language-id))
|
(when (and language-profile (nil? default-language-id))
|
||||||
@@ -43,11 +44,15 @@
|
|||||||
:language-profile-id (cond
|
:language-profile-id (cond
|
||||||
language-profile default-language-id
|
language-profile default-language-id
|
||||||
(= 1 (count language-profiles)) (:id (first language-profiles))
|
(= 1 (count language-profiles)) (:id (first language-profiles))
|
||||||
:else language-profiles)})))
|
:else language-profiles)
|
||||||
|
:rootfolder-id (cond
|
||||||
|
(= 1 (count rootfolders)) (:id (first rootfolders))
|
||||||
|
:else rootfolders)})))
|
||||||
|
|
||||||
(defn request-embed [{:keys [title quality-profile-id language-profile-id tvdb-id season]} _]
|
(defn request-embed [{:keys [title quality-profile-id language-profile-id tvdb-id season rootfolder-id]} _]
|
||||||
(a/go
|
(a/go
|
||||||
(let [quality-profiles (a/<! (impl/quality-profiles))
|
(let [rootfolders (a/<! (impl/rootfolders))
|
||||||
|
quality-profiles (a/<! (impl/quality-profiles))
|
||||||
language-profiles (a/<! (impl/language-profiles))
|
language-profiles (a/<! (impl/language-profiles))
|
||||||
details (a/<! (impl/get-from-tvdb tvdb-id))]
|
details (a/<! (impl/get-from-tvdb tvdb-id))]
|
||||||
{:title title
|
{:title title
|
||||||
@@ -57,13 +62,16 @@
|
|||||||
:season season
|
:season season
|
||||||
:request-formats [""]
|
:request-formats [""]
|
||||||
:quality-profile (:name (first (filter #(= quality-profile-id (:id %)) quality-profiles)))
|
:quality-profile (:name (first (filter #(= quality-profile-id (:id %)) quality-profiles)))
|
||||||
:language-profile (:name (first (filter #(= language-profile-id (:id %)) language-profiles)))})))
|
:language-profile (:name (first (filter #(= language-profile-id (:id %)) language-profiles)))
|
||||||
|
:rootfolder (utils/name-from-id rootfolders rootfolder-id)})))
|
||||||
|
|
||||||
(defn request [payload _]
|
(defn request [payload _]
|
||||||
(a/go (let [details (a/<! (if-let [id (:id payload)]
|
(a/go (let [details (a/<! (if-let [id (:id payload)]
|
||||||
(impl/get-from-id id)
|
(impl/get-from-id id)
|
||||||
(impl/get-from-tvdb (:tvdb-id payload))))
|
(impl/get-from-tvdb (:tvdb-id payload))))
|
||||||
status (impl/status details (:season payload))
|
status (impl/status details (:season payload))
|
||||||
|
rfs (a/<! (impl/rootfolders))
|
||||||
|
payload (assoc payload :root-folder-path (utils/name-from-id rfs (:rootfolder-id payload)))
|
||||||
request-payload (impl/request-payload payload details)]
|
request-payload (impl/request-payload payload details)]
|
||||||
(if status
|
(if status
|
||||||
status
|
status
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
(defn PUT [endpoint & [params]]
|
(defn PUT [endpoint & [params]]
|
||||||
(utils/http-request :put (str @base-url endpoint) @api-key params))
|
(utils/http-request :put (str @base-url endpoint) @api-key params))
|
||||||
|
|
||||||
(def rootfolder (delay (a/<!! (utils/request-and-process-body GET #(get (first %) "path") "/rootfolder"))))
|
|
||||||
|
|
||||||
(defn quality-profiles []
|
(defn quality-profiles []
|
||||||
(utils/request-and-process-body
|
(utils/request-and-process-body
|
||||||
GET
|
GET
|
||||||
@@ -31,6 +29,12 @@
|
|||||||
#(map utils/process-profile %)
|
#(map utils/process-profile %)
|
||||||
"/languageProfile"))
|
"/languageProfile"))
|
||||||
|
|
||||||
|
(defn rootfolders []
|
||||||
|
(utils/request-and-process-body
|
||||||
|
GET
|
||||||
|
utils/process-rootfolders
|
||||||
|
"/rootfolder"))
|
||||||
|
|
||||||
(defn get-from-tvdb [tvdb-id]
|
(defn get-from-tvdb [tvdb-id]
|
||||||
(utils/request-and-process-body
|
(utils/request-and-process-body
|
||||||
GET
|
GET
|
||||||
@@ -102,7 +106,6 @@
|
|||||||
(-> payload
|
(-> payload
|
||||||
(assoc :monitored true
|
(assoc :monitored true
|
||||||
:seasons seasons
|
:seasons seasons
|
||||||
:root-folder-path @rootfolder
|
|
||||||
:add-options {:ignore-episodes-with-files true
|
:add-options {:ignore-episodes-with-files true
|
||||||
:search-for-missing-episodes true})
|
:search-for-missing-episodes true})
|
||||||
(dissoc :season
|
(dissoc :season
|
||||||
|
|||||||
@@ -68,9 +68,12 @@
|
|||||||
(m/stop-connection! messaging-ch)
|
(m/stop-connection! messaging-ch)
|
||||||
(a/close! event-ch)))))
|
(a/close! event-ch)))))
|
||||||
|
|
||||||
(defn startup! []
|
(defn setup-config! []
|
||||||
(reset! state/config (config/valid-config (load-env)))
|
(reset! state/config (config/valid-config (load-env)))
|
||||||
(timbre/merge-config! {:min-level [[#{"*"} (:log-level @state/config :info)]]})
|
(timbre/merge-config! {:min-level [[#{"*"} (:log-level @state/config :info)]]}))
|
||||||
|
|
||||||
|
(defn startup! []
|
||||||
|
(setup-config!)
|
||||||
(start-bot!))
|
(start-bot!))
|
||||||
|
|
||||||
; Program Entry Point
|
; Program Entry Point
|
||||||
|
|||||||
@@ -113,7 +113,7 @@
|
|||||||
(defn dropdown-result [interaction]
|
(defn dropdown-result [interaction]
|
||||||
(Integer/parseInt (s/select-one [:payload :values 0] interaction)))
|
(Integer/parseInt (s/select-one [:payload :values 0] interaction)))
|
||||||
|
|
||||||
(defn request-embed [{:keys [media-type title overview poster season quality-profile language-profile]}]
|
(defn request-embed [{:keys [media-type title overview poster season quality-profile language-profile rootfolder tag]}]
|
||||||
{:title title
|
{:title title
|
||||||
:description overview
|
:description overview
|
||||||
:image {:url poster}
|
:image {:url poster}
|
||||||
@@ -129,7 +129,10 @@
|
|||||||
:value language-profile})
|
:value language-profile})
|
||||||
(when season
|
(when season
|
||||||
{:name "Season"
|
{:name "Season"
|
||||||
:value (if (= season -1) "All" season)})])})
|
:value (if (= season -1) "All" season)})
|
||||||
|
(when rootfolder
|
||||||
|
{:name "Root Folder"
|
||||||
|
:value rootfolder})])})
|
||||||
|
|
||||||
(defn request [embed-data uuid]
|
(defn request [embed-data uuid]
|
||||||
{:content (str "Request this " (name (:media-type embed-data)) " ?")
|
{:content (str "Request this " (name (:media-type embed-data)) " ?")
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
[doplarr.state :as state]
|
[doplarr.state :as state]
|
||||||
[fmnoise.flow :as flow :refer [else then]]
|
[fmnoise.flow :as flow :refer [else then]]
|
||||||
[hato.client :as hc]
|
[hato.client :as hc]
|
||||||
[taoensso.timbre :refer [fatal trace]]))
|
[taoensso.timbre :refer [fatal trace]]
|
||||||
|
[clojure.set :as set]))
|
||||||
|
|
||||||
(defn deep-merge [a & maps]
|
(defn deep-merge [a & maps]
|
||||||
(if (map? a)
|
(if (map? a)
|
||||||
@@ -47,21 +48,30 @@
|
|||||||
(->> (select-keys profile ["id" "name"])
|
(->> (select-keys profile ["id" "name"])
|
||||||
from-camel))
|
from-camel))
|
||||||
|
|
||||||
(defn profile-name-id [profiles name]
|
(defn id-from-name [profiles name]
|
||||||
(->> profiles
|
(->> profiles
|
||||||
(filter #(= name (:name %)))
|
(filter #(= name (:name %)))
|
||||||
first
|
first
|
||||||
:id))
|
:id))
|
||||||
|
|
||||||
(defn profile-id-name [profiles id]
|
(defn name-from-id [profiles id]
|
||||||
(->> profiles
|
(->> profiles
|
||||||
(filter #(= id (:id %)))
|
(filter #(= id (:id %)))
|
||||||
first
|
first
|
||||||
:name))
|
:name))
|
||||||
|
|
||||||
|
(defmacro log-on-error [expr msg]
|
||||||
|
`(try
|
||||||
|
~expr
|
||||||
|
(catch Exception e#
|
||||||
|
(fatal e# ~msg)
|
||||||
|
(throw e#))))
|
||||||
|
|
||||||
(defn request-and-process-body [request-fn process-fn & request-args]
|
(defn request-and-process-body [request-fn process-fn & request-args]
|
||||||
(a/go
|
(a/go
|
||||||
(->> (a/<! (apply request-fn request-args))
|
(->> (log-on-error
|
||||||
|
(a/<! (apply request-fn request-args))
|
||||||
|
"Exception from HTTP request")
|
||||||
(then #(process-fn (:body %)))
|
(then #(process-fn (:body %)))
|
||||||
(else #(fatal %)))))
|
(else #(fatal %)))))
|
||||||
|
|
||||||
@@ -79,9 +89,12 @@
|
|||||||
(symbol (str "doplarr.backends." (name (config/available-backend-for-media media @state/config)))
|
(symbol (str "doplarr.backends." (name (config/available-backend-for-media media @state/config)))
|
||||||
f)))
|
f)))
|
||||||
|
|
||||||
(defmacro log-on-error [expr msg]
|
(defn process-rootfolders [resp]
|
||||||
`(try
|
(->> (from-camel resp)
|
||||||
~expr
|
(map #(select-keys % #{:path :id}))
|
||||||
(catch Exception e#
|
(map #(set/rename-keys % {:path :name}))))
|
||||||
(fatal e# ~msg)
|
|
||||||
(throw e#))))
|
(defn process-tags [resp]
|
||||||
|
(->> (from-camel resp)
|
||||||
|
(map #(set/rename-keys % {:label :name}))
|
||||||
|
(#(conj % {:name "No Tag" :id -1}))))
|
||||||
|
|||||||
Reference in New Issue
Block a user