mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-10 09:52:18 +02:00
A lot of changes to add hls support.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
use crate::model::api_proxy::ProxyUserCredentials;
|
||||
use std::str;
|
||||
use crate::model::config::TargetType;
|
||||
|
||||
// /hlsr/{token}/{username}/{password}/{channel}/{hash}/{chunk}
|
||||
#[derive(Debug)]
|
||||
pub struct HlsrPath {
|
||||
token: String,
|
||||
// username: String,
|
||||
// password: String,
|
||||
// channel: String,
|
||||
hash: String,
|
||||
chunk: String,
|
||||
}
|
||||
fn parse_hlsr_path(input: &str) -> Option<HlsrPath> {
|
||||
let parts: Vec<&str> = input.split('/').collect();
|
||||
|
||||
if parts.len() != 8 || !parts[0].is_empty() || parts[1] != "hlsr" {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(HlsrPath {
|
||||
token: parts[2].to_string(),
|
||||
// username: parts[3].to_string(),
|
||||
// password: parts[4].to_string(),
|
||||
// channel: parts[5].to_string(),
|
||||
hash: parts[6].to_string(),
|
||||
chunk: parts[7].to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
pub const M3U_HLSR_PREFIX: &str = "mhlsr";
|
||||
|
||||
pub fn rewrite_hls_url(stream_id: u32, username: &str, password: &str, hlsr: &HlsrPath, target_type: &TargetType) -> String {
|
||||
let prefix = if *target_type == TargetType::Xtream { "hlsr" } else { M3U_HLSR_PREFIX };
|
||||
format!("/{prefix}/{}/{username}/{password}/{stream_id}/{}/{}", hlsr.token, hlsr.hash, hlsr.chunk)
|
||||
}
|
||||
|
||||
pub fn rewrite_hls(content: &str, virtual_id: u32, user: &ProxyUserCredentials, target_type: &TargetType) -> String {
|
||||
content.lines().map(|line| {
|
||||
if line.starts_with('#') {
|
||||
line.to_string()
|
||||
} else {
|
||||
match parse_hlsr_path(line) {
|
||||
None => line.to_string(),
|
||||
Some(hlsr) => rewrite_hls_url(virtual_id, &user.username, &user.password, &hlsr, target_type)
|
||||
}
|
||||
}
|
||||
}).collect::<Vec<_>>()
|
||||
.join("\r\n")
|
||||
}
|
||||
@@ -201,10 +201,13 @@ where
|
||||
{
|
||||
let mut sort_order: Vec<Vec<PlaylistItem>> = vec![];
|
||||
let mut sort_order_idx: usize = 0;
|
||||
let mut group_map: std::collections::HashMap<Rc<String>, usize> = std::collections::HashMap::new();
|
||||
let mut group_map: std::collections::HashMap<String, usize> = std::collections::HashMap::new();
|
||||
consume_m3u(cfg, input, lines, |item| {
|
||||
// keep the original sort order for groups and group the playlist items
|
||||
let key = Rc::clone(&item.header.borrow().group);
|
||||
let key = {
|
||||
let header = item.header.borrow();
|
||||
format!("{}{}", &header.xtream_cluster, &header.group)
|
||||
};
|
||||
match group_map.entry(key) {
|
||||
std::collections::hash_map::Entry::Vacant(v) => {
|
||||
v.insert(sort_order_idx);
|
||||
|
||||
@@ -7,3 +7,4 @@ mod xtream_processor;
|
||||
mod affix_processor;
|
||||
mod xtream_processor_vod;
|
||||
mod xtream_processor_series;
|
||||
pub mod hls_parser;
|
||||
|
||||
@@ -79,7 +79,7 @@ pub fn parse_xtream_series_info(info: &Value, group_title: &str, series_name: &s
|
||||
}
|
||||
}
|
||||
|
||||
fn create_xtream_url(xtream_cluster: XtreamCluster, url: &str, username: &str, password: &str,
|
||||
pub fn create_xtream_url(xtream_cluster: XtreamCluster, url: &str, username: &str, password: &str,
|
||||
stream: &XtreamStream, live_stream_without_extension: bool) -> Rc<String> {
|
||||
if stream.direct_source.is_empty() {
|
||||
let stream_base_url = match xtream_cluster {
|
||||
|
||||
Reference in New Issue
Block a user