Files
tuliprox/backend/src/processing/processor/xtream_vod.rs
T

69 lines
3.3 KiB
Rust
Raw Normal View History

2025-12-25 12:33:28 +01:00
use std::sync::Arc;
2025-12-16 20:35:19 +01:00
use crate::model::FetchedPlaylist;
2025-12-22 17:25:11 +01:00
use crate::model::{AppConfig, ConfigTarget};
2025-12-25 12:33:28 +01:00
use crate::processing::processor::xtream::{playlist_resolve_download_playlist_item};
use crate::processing::processor::{create_resolve_options_function_for_xtream_target};
use crate::repository::xtream_repository::{persists_input_vod_info};
use log::{error, info, log_enabled, Level};
2025-12-16 20:35:19 +01:00
use shared::error::TuliproxError;
2025-12-22 17:25:11 +01:00
use shared::model::{InputType, PlaylistEntry, StreamProperties, VideoStreamProperties, XtreamVideoInfo};
use shared::model::{PlaylistItemType, XtreamCluster};
use std::time::Instant;
2025-12-25 12:33:28 +01:00
use crate::repository::storage::get_input_storage_path;
2024-12-19 13:02:10 +01:00
2024-12-28 16:26:04 +01:00
create_resolve_options_function_for_xtream_target!(vod);
2024-12-22 05:00:59 +01:00
2025-12-25 12:33:28 +01:00
pub async fn playlist_resolve_vod(app_config: &Arc<AppConfig>, client: &reqwest::Client, target: &ConfigTarget, errors: &mut Vec<TuliproxError>, fpl: &mut FetchedPlaylist<'_>) {
2024-12-28 16:26:04 +01:00
let (resolve_movies, resolve_delay) = get_resolve_vod_options(target, fpl);
2024-12-19 13:02:10 +01:00
if !resolve_movies { return; }
2025-12-25 12:33:28 +01:00
let input = fpl.input;
let working_dir = &app_config.config.load().working_dir;
let storage_path = match get_input_storage_path(&input.name, working_dir) {
Ok(storage_path) => storage_path,
Err(err) => {
error!("Can't resolve vod, input storage directory for input '{}' failed: {err}", input.name);
return;
}
};
2024-12-22 05:00:59 +01:00
2025-12-17 17:37:25 +01:00
// LocalVideo entries are not resolved!
2025-03-11 14:56:10 +01:00
let vod_info_count = fpl.playlistgroups.iter()
2024-12-22 05:00:59 +01:00
.flat_map(|plg| &plg.channels)
2025-12-25 12:33:28 +01:00
.filter(|pli| pli.header.xtream_cluster == XtreamCluster::Video
&& pli.header.item_type == PlaylistItemType::Video
&& !pli.has_details()).count();
info!("Found {vod_info_count} vod info to resolve");
2025-12-11 09:53:49 +01:00
let mut last_log_time = Instant::now();
let mut processed_vod_info_count = 0;
2025-12-11 09:53:49 +01:00
for plg in &mut fpl.playlistgroups {
for pli in &mut plg.channels {
2025-12-25 12:33:28 +01:00
processed_vod_info_count += 1;
if pli.header.xtream_cluster != XtreamCluster::Video
|| pli.header.item_type != PlaylistItemType::Video
|| pli.has_details() {
2025-12-11 09:53:49 +01:00
continue;
}
2025-12-25 12:33:28 +01:00
let Some(provider_id) = pli.get_provider_id() else { continue; };
if provider_id != 0 {
2025-12-22 17:25:11 +01:00
if let Some(content) = playlist_resolve_download_playlist_item(client, pli, fpl.input, errors, resolve_delay, XtreamCluster::Video).await {
if let Ok(info) = serde_json::from_str::<XtreamVideoInfo>(&content) {
let video_stream_props = VideoStreamProperties::from_info(&info, pli);
2025-12-25 12:33:28 +01:00
let _ = persists_input_vod_info(app_config, &storage_path, pli.header.xtream_cluster, &input.name, provider_id, &video_stream_props).await;
2025-12-11 09:53:49 +01:00
// This makes the data available for subsequent processing steps like STRM export.
2025-12-22 17:25:11 +01:00
pli.header.additional_properties = Some(StreamProperties::Video(Box::new(video_stream_props)));
2025-12-11 09:53:49 +01:00
}
2024-12-19 13:02:10 +01:00
}
}
2025-12-25 12:33:28 +01:00
if log_enabled!(Level::Info) && last_log_time.elapsed().as_secs() >= 30 {
info!("resolved {processed_vod_info_count}/{vod_info_count} vod info");
last_log_time = Instant::now();
2025-01-01 11:09:27 +01:00
}
}
}
2025-12-11 09:53:49 +01:00
info!("resolved {processed_vod_info_count}/{vod_info_count} vod info");
2024-12-19 13:02:10 +01:00
}