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 d3d176e commit fd2f2c9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ run:
REPLEX_ENABLE_CONSOLE=0 \
REPLEX_CACHE_TTL=0 \
REPLEX_NTF_WATCHLIST_FORCE=1 \
RUST_LOG="info,replex=debug" \
RUST_LOG="info,replex=info" \
RUSTFLAGS=-Awarnings \
cargo watch -x run

Expand Down
4 changes: 3 additions & 1 deletion src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub struct PlexContext {
#[serde(default="default_platform")]
#[salvo(extract(rename = "X-Plex-Platform"))]
pub platform: Platform,
#[salvo(extract(rename = "X-Plex-Username"))]
pub username: Option<String>,
#[serde(default, deserialize_with = "deserialize_screen_resolution")]
#[salvo(extract(rename = "X-Plex-Device-Screen-Resolution"))]
pub screen_resolution: Vec<Resolution>,
Expand Down Expand Up @@ -1180,7 +1182,7 @@ pub struct MetaData {
#[serde(rename = "Guid", default, skip_serializing_if = "Vec::is_empty")]
#[yaserde(rename = "Guid", default, child)]
pub guids: Vec<Guid>,
#[yaserde(attribute, rename = "userState")]
#[yaserde(attribute, rename = "State")]
#[serde(skip_serializing_if = "Option::is_none")]
pub user_state: Option<SpecialBool>,
#[serde(rename = "Image", default, skip_serializing_if = "Vec::is_empty")]
Expand Down
36 changes: 21 additions & 15 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,22 +323,28 @@ async fn ntf_watchlist_force(
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());
});
let params: PlexContext = req.extract().await.unwrap();
if params.clone().client_identifier.is_some() && params.clone().token.is_some() {
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!("Set watchlist for user: {} platform: {}",
params.clone().username.unwrap_or_default(),
params.clone().platform
);
});
}
}

#[handler]
Expand Down

0 comments on commit fd2f2c9

Please sign in to comment.