fixed hls api

This commit is contained in:
euzu
2025-06-09 13:00:37 +02:00
parent f87e308660
commit d8daefb452
3 changed files with 16 additions and 11 deletions
+9 -5
View File
@@ -3,19 +3,23 @@ use crate::utils::{CONSTANTS, HLS_PREFIX};
use crate::utils::{deobfuscate_text, obfuscate_text};
use std::str;
const TOKEN_SEPARATOR: char = '\x1F';
fn create_hls_session_token_and_url(secret: &[u8], session_token: &str, stream_url: &str) -> Option<String> {
if let Ok(cookie_value) = obfuscate_text(secret, &format!("{session_token}{stream_url}")) {
if let Ok(cookie_value) = obfuscate_text(secret, &format!("{session_token}{TOKEN_SEPARATOR}{stream_url}")) {
return Some(cookie_value);
}
None
}
const TOKEN_LEN: usize = 6;
pub fn get_hls_session_token_and_url_from_token(secret: &[u8], token: &str) -> Option<(Option<String>, String)> {
if let Ok(decrypted) = deobfuscate_text(secret, token) {
let session_token: String = decrypted.chars().take(TOKEN_LEN).collect();
let stream_url: String = decrypted.chars().skip(TOKEN_LEN).collect();
return Some((Some(session_token), stream_url));
let parts: Vec<&str> = decrypted.split(TOKEN_SEPARATOR).collect();
if !parts.is_empty() && parts.len() == 2 {
let session_token: String = parts[0].to_string();
let stream_url: String = parts[1].to_string();
return Some((Some(session_token), stream_url));
}
}
None
}