mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-29 10:12:22 +01:00
refactoring for favourites
- implemented favourites config to target config - added add_favourite() function to mapping
This commit is contained in:
@@ -966,6 +966,7 @@ pub async fn stream_response(
|
||||
| PlaylistItemType::LiveDash
|
||||
| PlaylistItemType::Video
|
||||
| PlaylistItemType::Series
|
||||
| PlaylistItemType::LocalSeries
|
||||
| PlaylistItemType::Catchup
|
||||
) {
|
||||
let _ = app_state
|
||||
|
||||
@@ -152,7 +152,7 @@ fn map_channel(mut channel: PlaylistItem, mapping: &Mapping) -> (PlaylistItem, V
|
||||
(channel, virtual_items, matched)
|
||||
}
|
||||
|
||||
fn map_channel_with_aliases(channel: PlaylistItem, mapping: &Mapping) -> Vec<PlaylistItem> {
|
||||
fn map_channel_and_flatten(channel: PlaylistItem, mapping: &Mapping) -> Vec<PlaylistItem> {
|
||||
let (mapped_channel, mut virtual_items, _matched) = map_channel(channel, mapping);
|
||||
let mut result = Vec::with_capacity(1 + virtual_items.len());
|
||||
|
||||
@@ -167,7 +167,7 @@ fn map_playlist(playlist: &mut [PlaylistGroup], target: &ConfigTarget) -> Option
|
||||
let mut grp = playlist_group.clone();
|
||||
mappings.iter().filter(|&mapping| mapping.mapper.as_ref().is_some_and(|v| !v.is_empty()))
|
||||
.for_each(|mapping|
|
||||
grp.channels = grp.channels.drain(..).flat_map(|chan| map_channel_with_aliases(chan, mapping)).collect());
|
||||
grp.channels = grp.channels.drain(..).flat_map(|chan| map_channel_and_flatten(chan, mapping)).collect());
|
||||
grp
|
||||
}).collect();
|
||||
|
||||
@@ -568,8 +568,8 @@ pub fn process_favourites(playlist: &mut Vec<PlaylistGroup>, favourites_cfg: Opt
|
||||
let mut fav_groups: IndexMap<String, Vec<PlaylistItem>> = IndexMap::new();
|
||||
for pg in playlist.iter() {
|
||||
for pli in &pg.channels {
|
||||
// skip episodes, only containers or videos/live
|
||||
if pli.header.item_type == PlaylistItemType::Series {
|
||||
// series episodes cant be included in favourites
|
||||
if pli.header.item_type == PlaylistItemType::Series || pli.header.item_type == PlaylistItemType::LocalSeries {
|
||||
continue;
|
||||
}
|
||||
for fav in favourites {
|
||||
|
||||
@@ -69,8 +69,7 @@ pub async fn persist_playlist(app_config: &Arc<AppConfig>, playlist: &mut [Playl
|
||||
|
||||
if item_type == PlaylistItemType::LocalSeries {
|
||||
assign_local_series_info_episode_key(&mut local_library_series, header, item_type);
|
||||
}
|
||||
if item_type == PlaylistItemType::Series {
|
||||
} else if item_type == PlaylistItemType::Series {
|
||||
assign_provider_series_info_episode_key(&mut provider_series, header, item_type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +194,11 @@ impl Filter {
|
||||
Self::TypeComparison(field, item_type) => {
|
||||
if let Some(value) = provider.get(field.as_str()) {
|
||||
get_filter_item_type(&value).is_some_and(|pli_type| {
|
||||
let is_match = pli_type.eq(item_type);
|
||||
let is_match = match item_type {
|
||||
PlaylistItemType::Video => matches!(pli_type, PlaylistItemType::Video | PlaylistItemType::LocalVideo),
|
||||
PlaylistItemType::Series => matches!(pli_type, PlaylistItemType::Series | PlaylistItemType::LocalSeries),
|
||||
_ => pli_type.eq(item_type),
|
||||
};
|
||||
if log_enabled!(Level::Trace) {
|
||||
if is_match {
|
||||
trace!("Match found: {field:?} {value}");
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::error::{create_tuliprox_error_result, info_err, TuliproxError, TuliproxErrorKind};
|
||||
use crate::foundation::filter::ValueAccessor;
|
||||
use crate::foundation::mapper::EvalResult::{AnyValue, Failure, Named, Number, Undefined, Value};
|
||||
use crate::model::{PatternTemplate, TemplateValue};
|
||||
use crate::model::{PatternTemplate, PlaylistItemType, TemplateValue};
|
||||
use crate::utils::Capitalize;
|
||||
use log::{debug, trace};
|
||||
use pest::iterators::{Pair, Pairs};
|
||||
@@ -1247,7 +1247,8 @@ impl Expression {
|
||||
BuiltInFunction::AddFavourite => {
|
||||
let group_name = extract_evaluated_arg_value!(evaluated_args, 0);
|
||||
if let Some(group) = group_name {
|
||||
if accessor.pli.header.item_type != crate::model::PlaylistItemType::Series {
|
||||
let item_type = accessor.pli.header.item_type;
|
||||
if item_type != PlaylistItemType::Series && item_type != PlaylistItemType::LocalSeries {
|
||||
let mut pli = accessor.pli.clone();
|
||||
pli.header.group.clone_from(group);
|
||||
pli.header.uuid = crate::utils::create_alias_uuid(&accessor.pli.header.uuid, group);
|
||||
@@ -1571,7 +1572,7 @@ mod tests {
|
||||
..Default::default()
|
||||
}
|
||||
};
|
||||
let mut accessor = ValueAccessor { pli: &mut series_info, virtual_items: vec![] };
|
||||
let mut accessor = ValueAccessor { pli: &mut series_info, virtual_items: vec![], match_as_ascii: false };
|
||||
mapper.eval(&mut accessor, None);
|
||||
assert_eq!(accessor.virtual_items.len(), 1);
|
||||
|
||||
@@ -1583,7 +1584,7 @@ mod tests {
|
||||
..Default::default()
|
||||
}
|
||||
};
|
||||
let mut accessor = ValueAccessor { pli: &mut episode, virtual_items: vec![] };
|
||||
let mut accessor = ValueAccessor { pli: &mut episode, virtual_items: vec![], match_as_ascii: false };
|
||||
mapper.eval(&mut accessor, None);
|
||||
assert_eq!(accessor.virtual_items.len(), 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user