Skip to content

Commit

Permalink
feat: some more bootatrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t committed Jul 12, 2024
1 parent 83d9600 commit c8b00a3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,3 +1770,13 @@ impl MediaContainerWrapper<MediaContainer> {
self.is_hub() && self.media_container.library_section_id.is_some()
}
}


#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PlexUser {
pub id: i64,
pub uuid: String,
pub username: String,
pub email: String,
}
58 changes: 51 additions & 7 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,32 @@ async fn ntf_watchlist_force(
let params: PlexContext = req.extract().await.unwrap();
if params.clone().token.is_some() {
tokio::spawn(async move {
let url = format!("https://notifications.plex.tv/api/v1/notifications/settings?X-Plex-Token={}", params.clone().token.unwrap());
let token = params.clone().token.unwrap();
let client_id = params.clone().client_identifier.unwrap();
let mut url = format!("https://notifications.plex.tv/api/v1/notifications/settings?X-Plex-Token={}", &token);
let json_data = r#"{"enabled": true,"libraries": [],"identifier": "tv.plex.notification.library.new"}"#;
let client = reqwest::Client::new();

println!("Bootstrao for request: {} platform: {} product: {} device name: {}",
params.clone().username.unwrap_or_default(),
params.clone().platform,
params.clone().product.unwrap_or_default(),
params.clone().device_name.unwrap_or_default()
);

let client_base = "https://clients.plex.tv";
let user: PlexUser = client
.get(format!("{}/api/v2/user", client_base))
.header("Accept", "application/json")
.header("X-Plex-Token", &token)
.header("X-Plex-Client-Identifier", &client_id)
.send()
.await
.unwrap()
.json()
.await
.unwrap();
dbg!(&user);
let response = client
.post(url)
.header("Content-Type", "application/json")
Expand All @@ -349,14 +371,36 @@ async fn ntf_watchlist_force(
.await
.unwrap();

println!("Set watchlist for user: {} platform: {} product: {} device name: {} status: {}",
params.clone().username.unwrap_or_default(),
params.clone().platform,
params.clone().product.unwrap_or_default(),
params.clone().device_name.unwrap_or_default(),
println!("Set watchlist status: {}",
&response.status()
);
//dbg!(params.clone())

let opts = vec![
"tv.plex.provider.vod",
"tv.plex.provider.music",
];


;
//let
//return;
let u = format!("{}/api/v2/user/{}/settings/opt_outs", client_base, &user.uuid);
for key in opts {
let response = client
.post(format!("{}?key={}&value=opt_out", u.clone(), key))
.header("Accept", "application/json")
.header("X-Plex-Token", &token)
.header("X-Plex-Client-Identifier", &client_id)
.send()
.await
.unwrap();

println!("Set opt out status: {}",
&response.status()
);

}

});
}
}
Expand Down

0 comments on commit c8b00a3

Please sign in to comment.