From d3d176e3e333ceeec94ac0a420d91dd478176246 Mon Sep 17 00:00:00 2001 From: lostb1t Date: Tue, 9 Jul 2024 13:52:44 +0000 Subject: [PATCH] feat: watchlist --- Makefile | 6 ++++-- src/config.rs | 5 +++++ src/logging.rs | 1 + src/routes.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index c4a1c93..d62d852 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ run: REPLEX_FORCE_MAXIMUM_QUALITY=1 \ REPLEX_CACHE_ROWS=0 \ REPLEX_HERO_ROWS="home.movies.recent,movies.recent,movie.recentlyadded,movie.topunwatched,movie.recentlyviewed,hub.movie.recentlyreleased,home.television.recent,tv.inprogress,tv.recentlyaired" \ - REPLEX_PORT=8089 \ + REPLEX_PORT=8000 \ REPLEX_INCLUDE_WATCHED=0 \ REPLEX_REDIRECT_STREAMS=0 \ REPLEX_DISABLE_RELATED=0 \ @@ -32,8 +32,10 @@ run: REPLEX_DISABLE_USER_STATE=0 \ REPLEX_ENABLE_CONSOLE=0 \ REPLEX_CACHE_TTL=0 \ + REPLEX_NTF_WATCHLIST_FORCE=1 \ RUST_LOG="info,replex=debug" \ - cargo run + RUSTFLAGS=-Awarnings \ + cargo watch -x run fix: cargo fix diff --git a/src/config.rs b/src/config.rs index 1387b48..c2ddddb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -89,6 +89,11 @@ pub struct Config { #[serde(default, deserialize_with = "deserialize_comma_seperated_string")] pub force_direct_play_for: Option>, pub test_script: Option, + #[serde( + default = "default_as_false", + deserialize_with = "figment::util::bool_from_str_or_int" + )] + pub ntf_watchlist_force: bool, } fn default_cache_ttl() -> u64 { diff --git a/src/logging.rs b/src/logging.rs index 253bd4b..d578e1b 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -43,6 +43,7 @@ impl Handler for Logger { let status = res.status_code.unwrap_or(StatusCode::OK); tracing::debug!( status = %status, + //path = %req.uri(), duration = ?duration, "Response" ); diff --git a/src/routes.rs b/src/routes.rs index d5e48e6..f6f7c82 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -133,6 +133,16 @@ pub fn route() -> Router { .get(empty_handler), ); } + + if config.ntf_watchlist_force { + router = router.push( + Router::new() + .hoop(ntf_watchlist_force) + //.get(ping) + .goal(proxy_request) + .path("/media/providers"), + ); + } router = router .push( @@ -147,15 +157,14 @@ pub fn route() -> Router { .hoop(auto_refresh_cache()) .get(get_hubs_sections), ) - //.push( - // Router::new() - // .path(format!("{}/", PLEX_LIBRARY_METADATA)) - // .get(get_library_item_metadata), - //) + .push( + Router::new() + .path("/webhooks/plex") + .post(webhook_plex), + ) .push( Router::new() .path("/ping") - .hoop(force_maximum_quality) .get(ping), ) .push( @@ -307,6 +316,31 @@ async fn disable_related_query( add_query_param_salvo(req, "includeRelated".to_string(), "0".to_string()); } +#[handler] +async fn ntf_watchlist_force( + req: &mut Request, + depot: &mut Depot, + res: &mut Response, + ctrl: &mut FlowCtrl, +) { + let params: PlexContext = req.extract().await.unwrap(); + tokio::spawn(async move { + let url = format!("https://notifications.plex.tv/api/v1/notifications/settings?X-Plex-Client-Identifier={}&X-Plex-Token={}", params.clone().client_identifier.unwrap(),params.clone().token.unwrap()); + let json_data = r#"{"enabled": true,"libraries": [],"identifier": "tv.plex.notification.library.new"}"#; + let client = reqwest::Client::new(); + + let response = client + .post(url) + .header("Content-Type", "application/json") + .body(json_data.to_owned()) + .send() + .await + .unwrap(); + + //println!("Status: {}", response.status()); + }); +} + #[handler] pub async fn empty_handler( req: &mut Request, @@ -323,6 +357,17 @@ pub async fn empty_handler( return Ok(()); } +#[handler] +pub async fn webhook_plex( + req: &mut Request, + res: &mut Response, +) -> Result<(), anyhow::Error> { + let payload = req.form::("payload").await; + dbg!(payload); + res.render(()); + return Ok(()); +} + // if directplay fails we remove it. #[handler] pub async fn direct_stream_fallback(