Skip to main content

shinden_pl_api/
video.rs

1use crate::client::ShindenAPI;
2use anyhow::Result;
3use scraper::{Html, Selector};
4use std::time::Duration;
5use tokio::time::sleep;
6
7
8impl ShindenAPI {
9    pub async fn get_player_iframe(&self, online_id: &str) -> Result<String> {
10        let url1 = format!(
11            "https://api4.shinden.pl/xhr/{}/player_load?auth=X2d1ZXN0XzowLDUsMjEwMDAwMDAsMjU1LDQxNzQyOTM2NDQ%3D",
12            online_id
13        );
14        let url2 = format!(
15            "https://api4.shinden.pl/xhr/{}/player_show?auth=X2d1ZXN0XzowLDUsMjEwMDAwMDAsMjU1LDQxNzQyOTM2NDQ%3D&width=0&height=-1",
16            online_id
17        );
18
19        let _ = self.get_html(&url1).await?;
20        sleep(Duration::from_secs(5)).await;
21        let html = self.get_html(&url2).await?;
22
23        let doc = Html::parse_document(&html);
24        let iframe = doc.select(&Selector::parse("iframe").unwrap()).next();
25
26        Ok(iframe.map(|i| i.html()).unwrap_or_default())
27    }
28}
29