Skip to content

Commit c8b00a3

Browse files
committed
feat: some more bootatrapping
1 parent 83d9600 commit c8b00a3

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

src/models.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1770,3 +1770,13 @@ impl MediaContainerWrapper<MediaContainer> {
17701770
self.is_hub() && self.media_container.library_section_id.is_some()
17711771
}
17721772
}
1773+
1774+
1775+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
1776+
#[serde(rename_all = "camelCase")]
1777+
pub struct PlexUser {
1778+
pub id: i64,
1779+
pub uuid: String,
1780+
pub username: String,
1781+
pub email: String,
1782+
}

src/routes.rs

+51-7
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,32 @@ async fn ntf_watchlist_force(
337337
let params: PlexContext = req.extract().await.unwrap();
338338
if params.clone().token.is_some() {
339339
tokio::spawn(async move {
340-
let url = format!("https://notifications.plex.tv/api/v1/notifications/settings?X-Plex-Token={}", params.clone().token.unwrap());
340+
let token = params.clone().token.unwrap();
341+
let client_id = params.clone().client_identifier.unwrap();
342+
let mut url = format!("https://notifications.plex.tv/api/v1/notifications/settings?X-Plex-Token={}", &token);
341343
let json_data = r#"{"enabled": true,"libraries": [],"identifier": "tv.plex.notification.library.new"}"#;
342344
let client = reqwest::Client::new();
343345

346+
println!("Bootstrao for request: {} platform: {} product: {} device name: {}",
347+
params.clone().username.unwrap_or_default(),
348+
params.clone().platform,
349+
params.clone().product.unwrap_or_default(),
350+
params.clone().device_name.unwrap_or_default()
351+
);
352+
353+
let client_base = "https://clients.plex.tv";
354+
let user: PlexUser = client
355+
.get(format!("{}/api/v2/user", client_base))
356+
.header("Accept", "application/json")
357+
.header("X-Plex-Token", &token)
358+
.header("X-Plex-Client-Identifier", &client_id)
359+
.send()
360+
.await
361+
.unwrap()
362+
.json()
363+
.await
364+
.unwrap();
365+
dbg!(&user);
344366
let response = client
345367
.post(url)
346368
.header("Content-Type", "application/json")
@@ -349,14 +371,36 @@ async fn ntf_watchlist_force(
349371
.await
350372
.unwrap();
351373

352-
println!("Set watchlist for user: {} platform: {} product: {} device name: {} status: {}",
353-
params.clone().username.unwrap_or_default(),
354-
params.clone().platform,
355-
params.clone().product.unwrap_or_default(),
356-
params.clone().device_name.unwrap_or_default(),
374+
println!("Set watchlist status: {}",
357375
&response.status()
358376
);
359-
//dbg!(params.clone())
377+
378+
let opts = vec![
379+
"tv.plex.provider.vod",
380+
"tv.plex.provider.music",
381+
];
382+
383+
384+
;
385+
//let
386+
//return;
387+
let u = format!("{}/api/v2/user/{}/settings/opt_outs", client_base, &user.uuid);
388+
for key in opts {
389+
let response = client
390+
.post(format!("{}?key={}&value=opt_out", u.clone(), key))
391+
.header("Accept", "application/json")
392+
.header("X-Plex-Token", &token)
393+
.header("X-Plex-Client-Identifier", &client_id)
394+
.send()
395+
.await
396+
.unwrap();
397+
398+
println!("Set opt out status: {}",
399+
&response.status()
400+
);
401+
402+
}
403+
360404
});
361405
}
362406
}

0 commit comments

Comments
 (0)