Wrong Category Id after update fix

This commit is contained in:
euzu
2025-12-30 15:06:16 +01:00
parent b3a7e6af7c
commit 25d3454932
20 changed files with 269 additions and 135 deletions
+2 -2
View File
@@ -108,7 +108,7 @@ impl EpgIdCache<'_> {
let smart_match_enabled = self.smart_match_enabled;
let fuzzy_matching = self.fuzzy_match_enabled;
for channel in fp.playlistgroups.iter().flat_map(|g| &g.channels) {
for channel in fp.playlist_groups.iter().flat_map(|g| &g.channels) {
let mut missing_epg_id = true;
// insert epg_id to known channel epg_ids
if let Some(id) = channel.header.epg_channel_id.as_deref() {
@@ -211,7 +211,7 @@ async fn assign_channel_epg(new_epg: &mut Vec<Epg>, fp: &mut FetchedPlaylist<'_>
};
let filter_live = |c: &&mut PlaylistItem| c.header.xtream_cluster == XtreamCluster::Live;
fp.playlistgroups.iter_mut()
fp.playlist_groups.iter_mut()
.flat_map(|g| &mut g.channels)
.filter(filter_live)
.for_each(assign_values);
+36 -34
View File
@@ -1,7 +1,7 @@
use crate::model::{AppConfig, Config, ConfigFavourites, ConfigInput, ConfigRename};
use crate::utils::epg;
use crate::utils::m3u;
use crate::utils::xtream;
use crate::utils::{epg, StepMeasureCallback};
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
use std::sync::Arc;
@@ -27,13 +27,13 @@ use crate::repository::playlist_repository::{persist_input_playlist, persist_pla
use crate::utils::StepMeasure;
use crate::utils::{debug_if_enabled, trace_if_enabled};
use futures::StreamExt;
use indexmap::IndexMap;
use log::{debug, error, info, log_enabled, trace, warn, Level};
use shared::error::{get_errors_notify_message, notify_err, TuliproxError};
use shared::foundation::filter::{get_field_value, set_field_value, Filter, ValueAccessor, ValueProvider};
use shared::model::{CounterModifier, FieldGetAccessor, FieldSetAccessor, InputType, ItemField, MsgKind, PlaylistEntry, PlaylistGroup, PlaylistItem, PlaylistItemType, PlaylistUpdateState, ProcessingOrder, UUIDType, XtreamCluster};
use shared::utils::{create_alias_uuid, default_as_default};
use std::time::Instant;
use indexmap::IndexMap;
fn is_valid(pli: &PlaylistItem, filter: &Filter, match_as_ascii: bool) -> bool {
let provider = ValueProvider { pli, match_as_ascii };
@@ -268,14 +268,7 @@ async fn process_source(client: &reqwest::Client, app_config: Arc<AppConfig>, so
if let Some(source) = sources.get_source_at(source_idx) {
let mut source_playlists = Vec::with_capacity(128);
let broadcast_step = {
let event_manager = event_manager.clone();
move |context: &str, msg: &str| {
if let Some(events) = &event_manager {
events.send_event(EventMessage::PlaylistUpdateProgress(context.to_owned(), msg.to_owned()));
}
}
};
let broadcast_step = create_broadcast_callback(event_manager.as_ref());
// Download the sources
let mut source_downloaded = false;
@@ -284,7 +277,7 @@ async fn process_source(client: &reqwest::Client, app_config: Arc<AppConfig>, so
source_downloaded = true;
let start_time = Instant::now();
// Download playlist for input
let (playlistgroups, mut error_list) = {
let (playlist_groups, mut error_list) = {
broadcast_step("Playlist download", &format!("Downloading input '{}'", input.name));
let (downloaded_playlist, mut download_err) = playlist_download_from_input(client, &app_config, input).await;
broadcast_step("Playlist download", &format!("Persisting input '{}' playlist", input.name));
@@ -308,10 +301,10 @@ async fn process_source(client: &reqwest::Client, app_config: Arc<AppConfig>, so
errors.append(&mut error_list);
errors.append(&mut tvguide_errors);
let group_count = playlistgroups.len();
let channel_count = playlistgroups.iter().map(|group| group.channels.len()).sum();
let group_count = playlist_groups.len();
let channel_count = playlist_groups.iter().map(|group| group.channels.len()).sum();
let input_name = &input.name;
if playlistgroups.is_empty() {
if playlist_groups.is_empty() {
broadcast_step("Playlist download", &format!("Input '{}' playlist is empty", input.name));
info!("Source is empty {input_name}");
errors.push(notify_err!(format!("Source is empty {input_name}")));
@@ -319,7 +312,7 @@ async fn process_source(client: &reqwest::Client, app_config: Arc<AppConfig>, so
source_playlists.push(
FetchedPlaylist {
input,
playlistgroups,
playlist_groups,
epg: tvguide,
}
);
@@ -334,7 +327,7 @@ async fn process_source(client: &reqwest::Client, app_config: Arc<AppConfig>, so
debug!("Source at index {source_idx} is empty");
errors.push(notify_err!(format!("Source at index {source_idx} is empty: {}", source.inputs.iter().map(|i| i.name.as_str()).collect::<Vec<_>>().join(", "))));
} else {
debug_if_enabled!("Source has {} groups", source_playlists.iter().map(|fpl| fpl.playlistgroups.len()).sum::<usize>());
debug_if_enabled!("Source has {} groups", source_playlists.iter().map(|fpl| fpl.playlist_groups.len()).sum::<usize>());
let event_manager_clone = event_manager.clone();
for target in &source.targets {
let event_manager_clone = event_manager_clone.clone();
@@ -356,6 +349,17 @@ async fn process_source(client: &reqwest::Client, app_config: Arc<AppConfig>, so
(input_stats.into_values().collect(), target_stats, errors)
}
fn create_broadcast_callback(event_manager: Option<&Arc<EventManager>>) -> StepMeasureCallback {
if let Some(event_mgr) = event_manager {
let events = event_mgr.clone();
Box::new(move |context: &str, msg: &str| {
events.send_event(EventMessage::PlaylistUpdateProgress(context.to_owned(), msg.to_owned()));
})
} else {
Box::new(move |_context: &str, _msg: &str| { /* noop */ })
}
}
fn create_input_stat(group_count: usize, channel_count: usize, error_count: usize, input_type: InputType, input_name: &str, secs_took: u64) -> InputStats {
InputStats {
name: input_name.to_string(),
@@ -454,22 +458,23 @@ fn duplicate_hash(item: &PlaylistItem) -> UUIDType {
item.get_uuid()
}
fn execute_pipe<'a>(target: &ConfigTarget, pipe: &ProcessingPipe, fpl: &FetchedPlaylist<'a>, duplicates: &mut HashSet<UUIDType>) -> FetchedPlaylist<'a> {
fn execute_pipe<'a>(target: &ConfigTarget, pipe: &ProcessingPipe, fpl: &FetchedPlaylist<'a>,
duplicates: &mut HashSet<UUIDType>) -> FetchedPlaylist<'a> {
let mut new_fpl = FetchedPlaylist {
input: fpl.input,
playlistgroups: fpl.playlistgroups.clone(), // we need to clone, because of multiple target definitions, we cant change the initial playlist.
playlist_groups: fpl.playlist_groups.clone(), // we need to clone, because of multiple target definitions, we cant change the initial playlist.
epg: fpl.epg.clone(),
};
if target.options.as_ref().is_some_and(|opt| opt.remove_duplicates) {
for group in &mut new_fpl.playlistgroups {
for group in &mut new_fpl.playlist_groups {
// `HashSet::insert` returns true for first insert, otherweise false
group.channels.retain(|item| duplicates.insert(duplicate_hash(item)));
}
}
for f in pipe {
if let Some(groups) = f(&mut new_fpl.playlistgroups, target) {
new_fpl.playlistgroups = groups;
if let Some(groups) = f(&mut new_fpl.playlist_groups, target) {
new_fpl.playlist_groups = groups;
}
}
new_fpl
@@ -516,25 +521,19 @@ async fn process_playlist_for_target(app_config: &Arc<AppConfig>,
let mut processed_fetched_playlists: Vec<FetchedPlaylist> = vec![];
debug!("Executing processing pipes");
let broadcast_step = {
let event_manager = event_manager.clone();
move |context: &str, msg: &str| {
if let Some(events) = &event_manager {
events.send_event(EventMessage::PlaylistUpdateProgress(context.to_owned(), msg.to_owned()));
}
}
};
let broadcast_step = create_broadcast_callback(event_manager.as_ref());
let mut step = StepMeasure::new(&target.name, broadcast_step);
for provider_fpl in playlists.iter_mut() {
step.broadcast("Executing transformations on '{}' playlist", &target.name);
let mut processed_fpl = execute_pipe(target, &pipe, provider_fpl, &mut duplicates);
playlist_resolve_series(app_config, client, target, errors, &pipe, provider_fpl, &mut processed_fpl, &step).await;
playlist_resolve_series(app_config, client, target, errors, &pipe, provider_fpl, &mut processed_fpl).await;
playlist_resolve_vod(app_config, client, target, errors, &mut processed_fpl).await;
// stats
let input_stats = stats.get_mut(&processed_fpl.input.name);
if let Some(stat) = input_stats {
stat.processed_stats.group_count = processed_fpl.playlistgroups.len();
stat.processed_stats.channel_count = processed_fpl.playlistgroups.iter()
stat.processed_stats.group_count = processed_fpl.playlist_groups.len();
stat.processed_stats.channel_count = processed_fpl.playlist_groups.iter()
.map(|group| group.channels.len())
.sum();
}
@@ -544,7 +543,10 @@ async fn process_playlist_for_target(app_config: &Arc<AppConfig>,
let (new_epg, mut new_playlist) = process_epg(&mut processed_fetched_playlists).await;
step.tick("epg");
process_favourites(&mut new_playlist, target.favourites.as_deref());
if target.favourites.is_some() {
step.broadcast("Processing favourites for '{}' playlist", &target.name);
process_favourites(&mut new_playlist, target.favourites.as_deref());
}
if new_playlist.is_empty() {
step.stop("");
@@ -642,7 +644,7 @@ async fn process_epg(processed_fetched_playlists: &mut Vec<FetchedPlaylist<'_>>)
// we need to process each input epg.
for fp in processed_fetched_playlists {
process_playlist_epg(fp, &mut new_epg).await;
new_playlist.append(&mut fp.playlistgroups);
new_playlist.append(&mut fp.playlist_groups);
}
(new_epg, new_playlist)
}
@@ -12,7 +12,6 @@ use shared::model::{InputType, PlaylistEntry, SeriesStreamProperties, StreamProp
use shared::model::{PlaylistGroup, PlaylistItemType, XtreamCluster};
use std::sync::Arc;
use std::time::Instant;
use crate::utils::StepMeasure;
create_resolve_options_function_for_xtream_target!(series);
@@ -28,7 +27,7 @@ async fn playlist_resolve_series_info(app_config: &Arc<AppConfig>, client: &reqw
}
};
let series_info_count = fpl.playlistgroups.iter()
let series_info_count = fpl.playlist_groups.iter()
.flat_map(|plg| &plg.channels)
.filter(|&pli| pli.header.xtream_cluster == XtreamCluster::Series
&& pli.header.item_type == PlaylistItemType::SeriesInfo
@@ -40,7 +39,7 @@ async fn playlist_resolve_series_info(app_config: &Arc<AppConfig>, client: &reqw
let input = fpl.input;
let mut result: Vec<PlaylistGroup> = vec![];
for plg in &mut fpl.playlistgroups {
for plg in &mut fpl.playlist_groups {
let mut group_series = vec![];
for pli in &mut plg.channels {
if pli.header.xtream_cluster != XtreamCluster::Series
@@ -102,15 +101,12 @@ pub async fn playlist_resolve_series(cfg: &Arc<AppConfig>,
pipe: &ProcessingPipe,
provider_fpl: &mut FetchedPlaylist<'_>,
processed_fpl: &mut FetchedPlaylist<'_>,
step: &StepMeasure,
) {
let (resolve_series, resolve_delay) = get_resolve_series_options(target, processed_fpl);
if !resolve_series { return; }
step.broadcast("Playlist resolve series info", "Resolving series info");
let series_playlist = playlist_resolve_series_info(cfg, client, errors, processed_fpl, resolve_delay).await;
if series_playlist.is_empty() { return; }
step.broadcast("Playlist resolve series info", "Series info resolved, updating playlist");
// original content saved into original list
for plg in &series_playlist {
provider_fpl.update_playlist(plg);
@@ -10,14 +10,12 @@ use shared::model::{InputType, PlaylistEntry, StreamProperties, VideoStreamPrope
use shared::model::{PlaylistItemType, XtreamCluster};
use std::sync::Arc;
use std::time::Instant;
use crate::utils::StepMeasure;
create_resolve_options_function_for_xtream_target!(vod);
pub async fn playlist_resolve_vod(app_config: &Arc<AppConfig>, client: &reqwest::Client,
target: &ConfigTarget, errors: &mut Vec<TuliproxError>,
fpl: &mut FetchedPlaylist<'_>,
step: &StepMeasure,) {
fpl: &mut FetchedPlaylist<'_>) {
let (resolve_movies, resolve_delay) = get_resolve_vod_options(target, fpl);
if !resolve_movies { return; }
@@ -32,7 +30,7 @@ pub async fn playlist_resolve_vod(app_config: &Arc<AppConfig>, client: &reqwest:
};
// LocalVideo entries are not resolved!
let vod_info_count = fpl.playlistgroups.iter()
let vod_info_count = fpl.playlist_groups.iter()
.flat_map(|plg| &plg.channels)
.filter(|pli| pli.header.xtream_cluster == XtreamCluster::Video
&& pli.header.item_type == PlaylistItemType::Video
@@ -43,7 +41,7 @@ pub async fn playlist_resolve_vod(app_config: &Arc<AppConfig>, client: &reqwest:
let mut last_log_time = Instant::now();
let mut processed_vod_info_count = 0;
for plg in &mut fpl.playlistgroups {
for plg in &mut fpl.playlist_groups {
for pli in &mut plg.channels {
if pli.header.xtream_cluster != XtreamCluster::Video
|| pli.header.item_type != PlaylistItemType::Video