Skip to content

Commit

Permalink
Merge pull request #17 from tcheronneau/alpha
Browse files Browse the repository at this point in the history
Adding Jellyseerr
  • Loading branch information
tcheronneau authored Dec 6, 2024
2 parents 729c490 + 7dbf25c commit 434bf5f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 93 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "homers"
version = "0.5.1"
version = "0.5.2"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
outputs = { self, nixpkgs, flake-utils }:
let
name = "homers";
version = "0.4.2";
version = "0.5.2";
in
flake-utils.lib.eachDefaultSystem (system:
with nixpkgs.legacyPackages.${system}; {
Expand Down
15 changes: 15 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct Config {
pub sonarr: Option<HashMap<String, Sonarr>>,
pub radarr: Option<HashMap<String, Radarr>>,
pub overseerr: Option<Overseerr>,
pub jellyseerr: Option<Overseerr>,
pub plex: Option<HashMap<String, Plex>>,
pub jellyfin: Option<HashMap<String, Jellyfin>>,
pub http: rocket::Config,
Expand All @@ -33,6 +34,7 @@ impl Default for Config {
sonarr: None,
radarr: None,
overseerr: None,
jellyseerr: None,
plex: None,
jellyfin: None,
http: rocket::Config::default(),
Expand All @@ -46,6 +48,7 @@ pub enum Task {
SonarrMissing(Sonarr),
Radarr(Radarr),
Overseerr(Overseerr),
Jellyseerr(Overseerr),
TautulliSession(Tautulli),
TautulliLibrary(Tautulli),
PlexSession(Plex),
Expand Down Expand Up @@ -118,6 +121,18 @@ pub fn get_tasks(config: Config) -> anyhow::Result<Vec<Task>> {
)?;
tasks.push(Task::Overseerr(overseerr));
}
if let Some(jellyseerr) = config.jellyseerr {
let mut reqs = 20;
if let Some(requests) = jellyseerr.requests {
reqs = requests;
}
let jellyseerr = Overseerr::new(
remove_trailing_slash(&jellyseerr.address),
&jellyseerr.api_key,
reqs,
)?;
tasks.push(Task::Jellyseerr(jellyseerr));
}
if let Some(plex) = config.plex {
for (name, p) in plex {
let client = Plex::new(&name, remove_trailing_slash(&p.address), &p.token)?;
Expand Down
4 changes: 4 additions & 0 deletions src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ async fn process_tasks(tasks: Vec<Task>) -> Result<Vec<TaskResult>, JoinError> {
let result = overseerr.get_overseerr_requests().await;
Ok(TaskResult::Overseerr(result))
}
Task::Jellyseerr(overseerr) => {
let result = overseerr.get_overseerr_requests().await;
Ok(TaskResult::Jellyseerr(result))
}
Task::PlexSession(plex) => {
let name = &plex.name;
let result = plex.get_current_sessions().await;
Expand Down
14 changes: 10 additions & 4 deletions src/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub enum TaskResult {
TautulliLibrary(Vec<Library>),
Radarr(HashMap<String, Vec<RadarrMovie>>),
Overseerr(Vec<OverseerrRequest>),
Jellyseerr(Vec<OverseerrRequest>),
PlexSession(HashMap<String, Vec<Session>>, Vec<User>),
PlexLibrary(HashMap<String, Vec<LibraryCount>>),
JellyfinSession(HashMap<String, Vec<Session>>, Vec<User>),
Expand Down Expand Up @@ -170,7 +171,12 @@ pub fn format_metrics(task_result: Vec<TaskResult>) -> anyhow::Result<String> {
format_tautulli_library_metrics(libraries, &mut registry)
}
TaskResult::Radarr(movies) => format_radarr_metrics(movies, &mut registry),
TaskResult::Overseerr(overseerr) => format_overseerr_metrics(overseerr, &mut registry),
TaskResult::Overseerr(overseerr) => {
format_overseerr_metrics("overseerr", overseerr, &mut registry)
}
TaskResult::Jellyseerr(overseerr) => {
format_overseerr_metrics("jellyseerr", overseerr, &mut registry)
}
TaskResult::PlexSession(sessions, users) => {
format_session_metrics("plex", sessions, users, &mut registry)
}
Expand Down Expand Up @@ -338,12 +344,12 @@ fn format_radarr_metrics(radarr_hash: HashMap<String, Vec<RadarrMovie>>, registr
});
}

fn format_overseerr_metrics(requests: Vec<OverseerrRequest>, registry: &mut Registry) {
fn format_overseerr_metrics(kind: &str, requests: Vec<OverseerrRequest>, registry: &mut Registry) {
debug!("Formatting {requests:?} as Prometheus");
let overseerr_request = Family::<OverseerrLabels, Gauge<f64, AtomicU64>>::default();
registry.register(
"overseerr_requests",
format!("overseerr requests status"),
format!("{}_requests", kind),
format!("{} requests status", kind),
overseerr_request.clone(),
);

Expand Down
2 changes: 2 additions & 0 deletions src/providers/plex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ impl Plex {
pub fn new(name: &str, address: &str, token: &str) -> anyhow::Result<Plex> {
let mut headers = header::HeaderMap::new();
let mut header_token = header::HeaderValue::from_str(&token)?;
let header_container_size = header::HeaderValue::from_static("1000");
header_token.set_sensitive(true);
headers.insert("X-Plex-Token", header_token);
headers.insert("X-Plex-Container-Size", header_container_size);
headers.insert(
header::ACCEPT,
header::HeaderValue::from_static("application/json"),
Expand Down
86 changes: 0 additions & 86 deletions src/providers/structs/overseerr.rs
Original file line number Diff line number Diff line change
@@ -1,126 +1,40 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Request {
pub page_info: Value,
pub results: Vec<Result>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PageInfo {
pub pages: i64,
pub page_size: i64,
pub results: i64,
pub page: i64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Result {
pub id: i64,
pub status: i64,
pub created_at: String,
pub updated_at: String,
#[serde(rename = "type")]
pub type_field: String,
pub is4k: bool,
pub server_id: i64,
pub profile_id: i64,
pub root_folder: String,
pub language_profile_id: Option<i64>,
pub tags: Vec<Value>,
pub is_auto_request: bool,
pub media: Media,
pub seasons: Vec<Season>,
pub modified_by: ModifiedBy,
pub requested_by: RequestedBy,
pub season_count: i64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Media {
pub download_status: Vec<Value>,
pub download_status4k: Vec<Value>,
pub id: i64,
pub media_type: String,
pub tmdb_id: i64,
pub tvdb_id: Option<i64>,
pub imdb_id: Value,
pub status: i64,
pub status4k: i64,
pub created_at: String,
pub updated_at: String,
pub last_season_change: String,
pub media_added_at: Value,
pub service_id: i64,
pub service_id4k: Value,
pub external_service_id: i64,
pub external_service_id4k: Value,
pub external_service_slug: String,
pub external_service_slug4k: Value,
pub rating_key: Value,
pub rating_key4k: Value,
pub service_url: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Season {
pub id: i64,
pub season_number: i64,
pub status: i64,
pub created_at: String,
pub updated_at: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModifiedBy {
pub permissions: i64,
pub id: i64,
pub email: String,
pub plex_username: String,
pub username: Value,
pub recovery_link_expiration_date: Value,
pub user_type: i64,
pub plex_id: i64,
pub avatar: String,
pub movie_quota_limit: Value,
pub movie_quota_days: Value,
pub tv_quota_limit: Value,
pub tv_quota_days: Value,
pub created_at: String,
pub updated_at: String,
pub request_count: i64,
pub display_name: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RequestedBy {
pub permissions: i64,
pub id: i64,
pub email: String,
#[serde(default)]
pub plex_username: Option<String>,
#[serde(default)]
pub username: Option<String>,
pub recovery_link_expiration_date: Value,
pub user_type: i64,
pub plex_id: i64,
pub avatar: String,
pub movie_quota_limit: Value,
pub movie_quota_days: Value,
pub tv_quota_limit: Value,
pub tv_quota_days: Value,
pub created_at: String,
pub updated_at: String,
pub request_count: i64,
pub display_name: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down

0 comments on commit 434bf5f

Please sign in to comment.