Skip to content

Commit

Permalink
feat: watchlist
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t committed Jul 9, 2024
1 parent e7e9e81 commit d3d176e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ 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 \
REPLEX_DISABLE_LEAF_COUNT=0 \
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
Expand Down
5 changes: 5 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ pub struct Config {
#[serde(default, deserialize_with = "deserialize_comma_seperated_string")]
pub force_direct_play_for: Option<Vec<String>>,
pub test_script: Option<String>,
#[serde(
default = "default_as_false",
deserialize_with = "figment::util::bool_from_str_or_int"
)]
pub ntf_watchlist_force: bool,
}

fn default_cache_ttl() -> u64 {
Expand Down
1 change: 1 addition & 0 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
Expand Down
57 changes: 51 additions & 6 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -147,15 +157,14 @@ pub fn route() -> Router {
.hoop(auto_refresh_cache())
.get(get_hubs_sections),
)
//.push(
// Router::new()
// .path(format!("{}/<id>", 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(
Expand Down Expand Up @@ -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,
Expand All @@ -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::<String>("payload").await;
dbg!(payload);
res.render(());
return Ok(());
}

// if directplay fails we remove it.
#[handler]
pub async fn direct_stream_fallback(
Expand Down

0 comments on commit d3d176e

Please sign in to comment.