diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c985a2bf..ebf5e5684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog # v1.1.5(2023-12-??) * Changed api-proxy user default proxy type from `reverse` to `redirect` +* Added `xtream_resolve_series` option for `m3u` target # v1.1.4(2023-12-06) * Breaking change, `config.yml` split into `config.yml` and `source.yml` diff --git a/README.md b/README.md index 6a3ab24b3..ad8a02d95 100644 --- a/README.md +++ b/README.md @@ -281,13 +281,18 @@ Each format has 2 properties - `kodi_style`. `xtream` output has additional options -- `xtream_skip_live_direct_source` -- `xtream_skip_video_direct_source` +- `xtream_skip_live_direct_source` if true the direct_source property from provider for live is ignored +- `xtream_skip_video_direct_source` if true the direct_source property from provider for movies is ignored + +`m3u` output has additional options +- `xtream_resolve_series` `This is option is currently ignored because of mass requests its highly possible that you are banned` +if you have xtream input and m3u output, the series are fetched and resolved. +This can cause a lot of requests to the provider. Be cautious when using this option. ```yaml output: - type: m3u - filename: {}.m3u + filename: playlist.m3u ``` ### 2.2.2.3 `processing_order` diff --git a/frontend/src/model/server-config.ts b/frontend/src/model/server-config.ts index 6067c29bc..6c5f58aa9 100644 --- a/frontend/src/model/server-config.ts +++ b/frontend/src/model/server-config.ts @@ -41,7 +41,10 @@ export interface TargetConfig { ignore_logo: boolean, underscore_whitespace: boolean, cleanup: boolean, - kodi_style: boolean + kodi_style: boolean, + xtream_skip_live_direct_source: boolean, + xtream_skip_video_direct_source: boolean, + xtream_resolve_series: boolean, }, sort: { match_as_ascii: boolean, diff --git a/src/api/xtream_player_api.rs b/src/api/xtream_player_api.rs index e1eaa3a3f..9b747e225 100644 --- a/src/api/xtream_player_api.rs +++ b/src/api/xtream_player_api.rs @@ -13,7 +13,7 @@ use crate::api::api_model::{AppState, UserApiRequest, XtreamAuthorizationRespons use crate::model::api_proxy::{ProxyType, UserCredentials}; use crate::model::config::{Config, ConfigInput, InputType}; use crate::model::model_config::{TargetType}; -use crate::model::model_m3u::XtreamCluster; +use crate::model::model_playlist::XtreamCluster; use crate::repository::xtream_repository::{COL_CAT_LIVE, COL_CAT_SERIES, COL_CAT_VOD, COL_LIVE, COL_SERIES, COL_VOD, xtream_get_all, xtream_get_stored_stream_info, xtream_persist_stream_info}; use crate::utils::{get_client_request}; diff --git a/src/download.rs b/src/download.rs index 09df59190..5b224f294 100644 --- a/src/download.rs +++ b/src/download.rs @@ -1,12 +1,14 @@ use std::path::PathBuf; -use std::sync::atomic::AtomicI32; +use std::sync::atomic::{AtomicU32}; +use std::thread::sleep; use log::debug; use crate::{utils}; use crate::m3u_filter_error::M3uFilterError; use crate::model::config::{Config, ConfigInput}; -use crate::model::model_m3u::{PlaylistGroup, XtreamCluster}; +use crate::model::model_playlist::{FetchedPlaylist, PlaylistGroup, PlaylistItem, PlaylistItemType, XtreamCluster}; use crate::model::xmltv::TVGuide; use crate::processing::{m3u_parser, xmltv_parser, xtream_parser}; +use crate::processing::xtream_parser::parse_xtream_series_info; use crate::utils::add_prefix_to_filename; fn prepare_file_path(input: &ConfigInput, working_dir: &String, action: &str) -> Option { @@ -39,6 +41,42 @@ pub(crate) async fn get_m3u_playlist(cfg: &Config, input: &ConfigInput, working_ } } + +pub(crate) async fn get_xtream_playlist_series<'a>(fpl: &mut FetchedPlaylist<'a>, errors: &mut Vec) { + let input = fpl.input; + for plg in &mut fpl.playlist { + let mut group_series: Option> = None; + for pli in &plg.channels { + let (fetch_series, series_info_url) = { + let mut header = pli.header.borrow_mut(); + let fetch_series = !header.series_fetched && header.item_type == PlaylistItemType::SeriesInfo; + if fetch_series { + header.series_fetched = true; + } + (fetch_series, header.url.to_string()) + }; + if fetch_series { + match utils::get_input_json_content(fpl.input, series_info_url.as_str(), None).await { + Ok(series_content) => { + match parse_xtream_series_info(&series_content, pli.header.borrow().group.as_str(), input) { + Ok(series_info) => { + group_series = series_info; + } + Err(err) => errors.push(err), + } + } + Err(err) => errors.push(err) + }; + sleep(std::time::Duration::new(2, 0)); // 2 seconds between + } + } + if let Some(mut series) = group_series { + series.drain(..).for_each(|spli| plg.channels.push(spli)); + } + } +} + + const ACTIONS: [(XtreamCluster, &str, &str); 3] = [ (XtreamCluster::Live, "get_live_categories", "get_live_streams"), (XtreamCluster::Video, "get_vod_categories", "get_vod_streams"), @@ -51,18 +89,23 @@ pub(crate) async fn get_xtream_playlist(input: &ConfigInput, working_dir: &Strin let base_url = format!("{}/player_api.php?username={}&password={}", input.url, username, password); let mut errors = vec![]; - let category_id_cnt = AtomicI32::new(0); + let category_id_cnt = AtomicU32::new(0); for (xtream_cluster, category, stream) in &ACTIONS { let category_url = format!("{}&action={}", base_url, category); let stream_url = format!("{}&action={}", base_url, stream); let category_file_path = prepare_file_path(input, working_dir, format!("{}_", category).as_str()); let stream_file_path = prepare_file_path(input, working_dir, format!("{}_", stream).as_str()); - match utils::get_input_json_content(input, &category_url, category_file_path).await { + match utils::get_input_json_content(input, category_url.as_str(), category_file_path).await { Ok(category_content) => { - match utils::get_input_json_content(input, &stream_url, stream_file_path).await { + match utils::get_input_json_content(input, stream_url.as_str(), stream_file_path).await { Ok(stream_content) => { - match xtream_parser::parse_xtream(&category_id_cnt, xtream_cluster, &category_content,input.url.as_str(),username, password, &stream_content) { + match xtream_parser::parse_xtream(&category_id_cnt, + xtream_cluster, + &category_content, + input, + &stream_content, + ) { Ok(sub_playlist_opt) => { if let Some(mut sub_playlist) = sub_playlist_opt { sub_playlist.drain(..).for_each(|group| playlist.push(group)); diff --git a/src/filter.rs b/src/filter.rs index 32453ffc1..aa00576c1 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -6,7 +6,7 @@ use log::{debug, error}; use pest::iterators::Pair; use pest::Parser; use petgraph::algo::toposort; -use crate::model::model_m3u::PlaylistItem; +use crate::model::model_playlist::PlaylistItem; use crate::model::model_config::ItemField; use petgraph::graph::DiGraph; use crate::{create_m3u_filter_error_result}; diff --git a/src/model/config.rs b/src/model/config.rs index 69bde29bb..ffbfa1d21 100644 --- a/src/model/config.rs +++ b/src/model/config.rs @@ -157,6 +157,8 @@ pub(crate) struct ConfigTargetOptions { pub xtream_skip_live_direct_source: bool, #[serde(default = "default_as_false")] pub xtream_skip_video_direct_source: bool, + #[serde(default = "default_as_false")] + pub xtream_resolve_series: bool, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] diff --git a/src/model/mapping.rs b/src/model/mapping.rs index a95cbd7f7..e723d79b1 100644 --- a/src/model/mapping.rs +++ b/src/model/mapping.rs @@ -10,7 +10,7 @@ use crate::filter::{Filter, get_filter, PatternTemplate, prepare_templates, Rege use crate::m3u_filter_error::{M3uFilterError, M3uFilterErrorKind}; use crate::model::model_config::{AFFIX_FIELDS, default_as_empty_map, default_as_empty_str, default_as_false, ItemField, MAPPER_ATTRIBUTE_FIELDS, }; -use crate::model::model_m3u::{FieldAccessor, PlaylistItem}; +use crate::model::model_playlist::{FieldAccessor, PlaylistItem}; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub(crate) struct MappingTag { diff --git a/src/model/mod.rs b/src/model/mod.rs index dc569f00c..afff12d12 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -1,7 +1,8 @@ pub(crate) mod config; pub(crate) mod model_config; -pub(crate) mod model_m3u; +pub(crate) mod model_playlist; pub(crate) mod mapping; pub(crate) mod api_proxy; pub(crate) mod stats; -pub(crate) mod xmltv; \ No newline at end of file +pub(crate) mod xmltv; +pub(crate) mod model_xtream; \ No newline at end of file diff --git a/src/model/model_m3u.rs b/src/model/model_playlist.rs similarity index 88% rename from src/model/model_m3u.rs rename to src/model/model_playlist.rs index 606b52832..c1f376440 100644 --- a/src/model/model_m3u.rs +++ b/src/model/model_playlist.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use crate::model::config::{ConfigInput, ConfigTargetOptions}; +use crate::model::model_config::{default_as_false}; use crate::model::xmltv::TVGuide; // https://de.wikipedia.org/wiki/M3U @@ -37,6 +38,17 @@ impl Display for XtreamCluster { pub(crate) fn default_stream_cluster() -> XtreamCluster { XtreamCluster::Live } +#[derive(Debug, Clone, PartialEq)] +pub(crate) enum PlaylistItemType { + Live = 1, + Movie = 2, + Series = 3, + SeriesInfo = 4, +} + +pub(crate) fn default_playlist_item_type() -> PlaylistItemType { PlaylistItemType::Live } + + pub(crate) trait FieldAccessor { fn get_field(&self, field: &str) -> Option>; fn set_field(&mut self, field: &str, value: &str) -> bool; @@ -62,6 +74,10 @@ pub(crate) struct PlaylistItemHeader { pub xtream_cluster: XtreamCluster, #[serde(skip_serializing, skip_deserializing)] pub additional_properties: Option>, + #[serde(default = "default_playlist_item_type", skip_serializing, skip_deserializing)] + pub item_type: PlaylistItemType, + #[serde(default = "default_as_false", skip_serializing, skip_deserializing)] + pub series_fetched: bool, // only used for series_info } macro_rules! update_fields { @@ -143,9 +159,10 @@ impl PlaylistItem { #[derive(Debug, Clone, Serialize, Deserialize)] pub(crate) struct PlaylistGroup { - pub id: i32, + pub id: u32, pub title: Rc, pub channels: Vec, #[serde(default = "default_stream_cluster", skip_serializing, skip_deserializing)] pub xtream_cluster: XtreamCluster, } + diff --git a/src/model/model_xtream.rs b/src/model/model_xtream.rs new file mode 100644 index 000000000..f0b6941b8 --- /dev/null +++ b/src/model/model_xtream.rs @@ -0,0 +1,333 @@ +use std::collections::HashMap; +use std::rc::Rc; + +use serde::{Deserialize, Deserializer, Serialize}; +use serde::de::DeserializeOwned; +use serde_json::Value; + +use crate::model::model_config::{default_as_empty_rc_str}; +use crate::model::model_playlist::{PlaylistItem}; + +fn default_as_empty_list() -> Vec { vec![] } + +fn deserialize_number_from_string<'de, D, T: DeserializeOwned>( + deserializer: D, +) -> Result, D::Error> + where + D: Deserializer<'de>, +{ + // we define a local enum type inside of the function + // because it is untagged, serde will deserialize as the first variant + // that it can + #[derive(Deserialize)] + #[serde(untagged)] + enum MaybeNumber { + // if it can be parsed as Option, it will be + Value(Option), + // otherwise try parsing as a string + NumberString(String), + } + + // deserialize into local enum + let value: MaybeNumber = Deserialize::deserialize(deserializer)?; + match value { + // if parsed as T or None, return that + MaybeNumber::Value(value) => Ok(value), + + // (if it is any other string) + MaybeNumber::NumberString(string) => { + match serde_json::from_str::(string.as_str()) { + Ok(val) => Ok(Some(val)), + Err(_) => Ok(None) + } + } + } +} + +fn value_to_string_array(value: &[Value]) -> Option> { + Some(value.iter().filter_map(value_to_string).collect()) +} + +fn value_to_string(v: &Value) -> Option { + match v { + Value::Bool(value) => Some(value.to_string()), + Value::Number(value) => Some(value.to_string()), + Value::String(value) => Some(value.to_string()), + _ => None, + } +} + +fn deserialize_as_option_rc_string<'de, D>(deserializer: D) -> Result>, D::Error> + where + D: Deserializer<'de>, +{ + let value: Value = Deserialize::deserialize(deserializer)?; + + match &value { + Value::String(s) => Ok(Some(Rc::new(s.to_owned()))), + Value::Number(s) => Ok(Some(Rc::new(s.to_string()))), + _ => Ok(None), + } +} + +fn deserialize_as_rc_string<'de, D>(deserializer: D) -> Result, D::Error> + where + D: Deserializer<'de>, +{ + let value: Value = Deserialize::deserialize(deserializer)?; + + match &value { + Value::String(s) => Ok(Rc::new(s.to_owned())), + _ => Ok(Rc::new(value.to_string())), + } +} + +fn deserialize_as_string_array<'de, D>(deserializer: D) -> Result>, D::Error> + where + D: Deserializer<'de>, +{ + Value::deserialize(deserializer).map(|v| match v { + Value::Array(value) => value_to_string_array(&value), + _ => None, + }) +} + +#[derive(Deserialize)] +pub(crate) struct XtreamCategory { + #[serde(deserialize_with = "deserialize_as_rc_string")] + pub category_id: Rc, + #[serde(deserialize_with = "deserialize_as_rc_string")] + pub category_name: Rc, + //pub parent_id: i32, + #[serde(default = "default_as_empty_list")] + pub channels: Vec, +} + +impl XtreamCategory { + pub(crate) fn add(&mut self, item: PlaylistItem) { + self.channels.push(item); + } +} + +#[derive(Serialize, Deserialize)] +pub(crate) struct XtreamStream { + #[serde(default, deserialize_with = "deserialize_as_rc_string")] + pub name: Rc, + #[serde(default, deserialize_with = "deserialize_as_rc_string")] + pub category_id: Rc, + #[serde(default, deserialize_with = "deserialize_number_from_string")] + pub stream_id: Option, + #[serde(default, deserialize_with = "deserialize_number_from_string")] + pub series_id: Option, + #[serde(default = "default_as_empty_rc_str", deserialize_with = "deserialize_as_rc_string")] + pub stream_icon: Rc, + #[serde(default = "default_as_empty_rc_str", deserialize_with = "deserialize_as_rc_string")] + pub direct_source: Rc, + + // optional attributes + #[serde(default, deserialize_with = "deserialize_as_string_array")] + pub backdrop_path: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub added: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub cast: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub container_extension: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub cover: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub director: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub episode_run_time: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub genre: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub last_modified: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub plot: Option>, + #[serde(default, deserialize_with = "deserialize_number_from_string")] + pub rating: Option, + #[serde(default, deserialize_with = "deserialize_number_from_string")] + pub rating_5based: Option, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub release_date: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub stream_type: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub title: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub year: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub youtube_trailer: Option>, + #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] + pub epg_channel_id: Option>, + #[serde(default, deserialize_with = "deserialize_number_from_string")] + pub tv_archive: Option, + #[serde(default, deserialize_with = "deserialize_number_from_string")] + pub tv_archive_duration: Option, +} + +macro_rules! add_str_property_if_exists { + ($vec:expr, $prop:expr, $prop_name:expr) => { + $vec.push((String::from($prop_name), Value::String($prop.to_string()))); + } +} +macro_rules! add_rc_str_property_if_exists { + ($vec:expr, $prop:expr, $prop_name:expr) => { + $prop.as_ref().map(|v| $vec.push((String::from($prop_name), Value::String(v.to_string())))); + } +} +macro_rules! add_opt_i64_property_if_exists { + ($vec:expr, $prop:expr, $prop_name:expr) => { + $prop.as_ref().map(|v| $vec.push((String::from($prop_name), Value::Number(serde_json::value::Number::from(i64::from(*v)))))); + } +} + +macro_rules! add_opt_f64_property_if_exists { + ($vec:expr, $prop:expr, $prop_name:expr) => { + $prop.as_ref().map(|v| $vec.push((String::from($prop_name), Value::Number(serde_json::value::Number::from_f64(f64::from(*v)).unwrap())))); + } +} + +macro_rules! add_f64_property_if_exists { + ($vec:expr, $prop:expr, $prop_name:expr) => { + $vec.push((String::from($prop_name), Value::Number(serde_json::value::Number::from_f64(f64::from($prop)).unwrap()))); + } +} + +macro_rules! add_i64_property_if_exists { + ($vec:expr, $prop:expr, $prop_name:expr) => { + $vec.push((String::from($prop_name), Value::Number(serde_json::value::Number::from(i64::from($prop))))); + } +} + + +impl XtreamStream { + pub(crate) fn get_stream_id(&self) -> String { + self.stream_id.map_or_else(|| self.series_id.map_or_else(|| String::from(""), |seid| format!("{}", seid)), |sid| format!("{}", sid)) + } + + pub(crate) fn get_additional_properties(&self) -> Option> { + let mut result = vec![]; + if let Some(bdpath) = self.backdrop_path.as_ref() { + if !bdpath.is_empty() { + result.push((String::from("backdrop_path"), Value::Array(Vec::from([Value::String(String::from(bdpath.get(0).unwrap()))])))); + } + } + add_rc_str_property_if_exists!(result, self.added, "added"); + add_rc_str_property_if_exists!(result, self.cast, "cast"); + add_rc_str_property_if_exists!(result, self.container_extension, "container_extension"); + add_rc_str_property_if_exists!(result, self.cover, "cover"); + add_rc_str_property_if_exists!(result, self.director, "director"); + add_rc_str_property_if_exists!(result, self.episode_run_time, "episode_run_time"); + add_rc_str_property_if_exists!(result, self.genre, "genre"); + add_rc_str_property_if_exists!(result, self.last_modified, "last_modified"); + add_rc_str_property_if_exists!(result, self.plot, "plot"); + add_opt_f64_property_if_exists!(result, self.rating, "rating"); + add_opt_f64_property_if_exists!(result, self.rating_5based, "rating_5based"); + add_rc_str_property_if_exists!(result, self.release_date, "release_date"); + add_rc_str_property_if_exists!(result, self.stream_type, "stream_type"); + add_rc_str_property_if_exists!(result, self.title, "title"); + add_rc_str_property_if_exists!(result, self.year, "year"); + add_rc_str_property_if_exists!(result, self.youtube_trailer, "youtube_trailer"); + //add_str_property_if_exists!(result, self.epg_channel_id, "epg_channel_id"); + add_opt_i64_property_if_exists!(result, self.tv_archive, "tv_archive"); + add_opt_i64_property_if_exists!(result, self.tv_archive_duration, "tv_archive_duration"); + if result.is_empty() { None } else { Some(result) } + } +} + + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub(crate) struct XtreamSeriesInfoSeason { + pub air_date: String, + pub episode_count: u32, + pub id: u32, + pub name: String, + pub overview: String, + pub season_number: u32, + pub vote_average: f64, + pub cover: String, + pub cover_big: String, + +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[allow(non_snake_case)] +pub(crate) struct XtreamSeriesInfoInfo { + name: String, + cover: String, + plot: String, + cast: String, + director: String, + genre: String, + releaseDate: String, + last_modified: String, + rating: String, + rating_5based: f64, + backdrop_path: Vec, + youtube_trailer: String, + episode_run_time: String, + category_id: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub(crate) struct XtreamSeriesInfoEpisodeInfo { + pub tmdb_id: u32, + pub releasedate: String, + pub plot: String, + pub duration_secs: u32, + pub duration: String, + pub movie_image: String, + // "video": [], + // "audio": [], + pub bitrate: u32, + pub rating: f64, + pub season: u32, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub(crate) struct XtreamSeriesInfoEpisode { + pub id: String, + pub episode_num: u32, + pub title: String, + pub container_extension: String, + pub info: XtreamSeriesInfoEpisodeInfo, + pub custom_sid: String, + pub added: String, + pub season: u32, + pub direct_source: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub(crate) struct XtreamSeriesInfo { + pub seasons: Vec, + pub info: XtreamSeriesInfoInfo, + pub episodes: HashMap>, +} + + +impl XtreamSeriesInfoEpisode { + pub(crate) fn get_additional_properties(&self, series_info: &XtreamSeriesInfo) -> Option> { + let mut result = vec![]; + let bdpath = &series_info.info.backdrop_path; + if !bdpath.is_empty() { + result.push((String::from("backdrop_path"), Value::Array(Vec::from([Value::String(String::from(bdpath.get(0).unwrap()))])))); + } + add_str_property_if_exists!(result, self.added.as_str(), "added"); + add_str_property_if_exists!(result, series_info.info.cast.as_str(), "cast"); + add_str_property_if_exists!(result, self.container_extension.as_str(), "container_extension"); + add_str_property_if_exists!(result, self.info.movie_image, "cover"); + add_str_property_if_exists!(result, series_info.info.director, "director"); + add_str_property_if_exists!(result, series_info.info.episode_run_time, "episode_run_time"); + add_str_property_if_exists!(result, series_info.info.last_modified, "last_modified"); + add_str_property_if_exists!(result, self.info.plot, "plot"); + add_str_property_if_exists!(result, series_info.info.rating, "rating"); + add_f64_property_if_exists!(result, series_info.info.rating_5based, "rating_5based"); + add_str_property_if_exists!(result, self.info.releasedate, "release_date"); + add_str_property_if_exists!(result, self.title, "title"); + add_i64_property_if_exists!(result, self.season, "season"); + add_str_property_if_exists!(result, series_info.info.youtube_trailer, "youtube_trailer"); + if result.is_empty() { None } else { Some(result) } + } +} \ No newline at end of file diff --git a/src/processing/m3u_parser.rs b/src/processing/m3u_parser.rs index 92dad71cf..6ab8f373e 100644 --- a/src/processing/m3u_parser.rs +++ b/src/processing/m3u_parser.rs @@ -3,7 +3,7 @@ use std::cell::RefCell; use std::rc::Rc; use crate::model::config::Config; use crate::model::model_config::default_as_empty_rc_str; -use crate::model::model_m3u::{PlaylistGroup, PlaylistItem, PlaylistItemHeader, XtreamCluster}; +use crate::model::model_playlist::{default_playlist_item_type, default_stream_cluster, PlaylistGroup, PlaylistItem, PlaylistItemHeader, PlaylistItemType, XtreamCluster}; fn token_value(it: &mut std::str::Chars) -> String { if let Some(oc) = it.next() { @@ -67,8 +67,10 @@ fn create_empty_playlistitem_header(content: &String, url: String) -> PlaylistIt source: Rc::new(content.to_owned()), url: Rc::new(url), epg_channel_id: None, - xtream_cluster: XtreamCluster::Live, + item_type: default_playlist_item_type(), + xtream_cluster: default_stream_cluster(), additional_properties: None, + series_fetched: false, } } @@ -124,6 +126,7 @@ fn process_header(video_suffixes: &Vec<&str>, content: &String, url: String) -> if url.ends_with(suffix) { // TODO find Series based on group or configured names plih.xtream_cluster = XtreamCluster::Video; + plih.item_type = PlaylistItemType::Movie; break; } } @@ -182,7 +185,7 @@ pub(crate) fn parse_m3u(cfg: &Config, lines: &Vec) -> Vec } let mut result: Vec = vec![]; - for (grp_id, (key, channels)) in (1_i32..).zip(groups.into_iter()) { + for (grp_id, (key, channels)) in (1_u32..).zip(groups.into_iter()) { let cluster = channels.first().map(|pli| pli.header.borrow().xtream_cluster.clone()); result.push(PlaylistGroup { id: grp_id, xtream_cluster: cluster.unwrap(), title: Rc::clone(&key), channels }); } diff --git a/src/processing/playlist_processor.rs b/src/processing/playlist_processor.rs index d669da2a0..b0854fb59 100644 --- a/src/processing/playlist_processor.rs +++ b/src/processing/playlist_processor.rs @@ -11,14 +11,14 @@ use log::{debug, error, info}; use unidecode::unidecode; use crate::{Config, get_errors_notify_message, model::config, valid_property}; -use crate::download::{get_m3u_playlist, get_xmltv, get_xtream_playlist}; +use crate::download::{get_m3u_playlist, get_xmltv, get_xtream_playlist, get_xtream_playlist_series}; use crate::filter::{get_field_value, MockValueProcessor, set_field_value, ValueProvider}; use crate::m3u_filter_error::{M3uFilterError, M3uFilterErrorKind}; use crate::messaging::{MsgKind, send_message}; use crate::model::config::{ConfigTarget, default_as_default, InputAffix, InputType, ProcessTargets}; use crate::model::mapping::{Mapping, MappingValueProcessor}; use crate::model::model_config::{AFFIX_FIELDS, ItemField, ProcessingOrder, SortOrder::{Asc, Desc}, TargetType}; -use crate::model::model_m3u::{FetchedPlaylist, FieldAccessor, PlaylistGroup, PlaylistItem, PlaylistItemHeader}; +use crate::model::model_playlist::{FetchedPlaylist, FieldAccessor, PlaylistGroup, PlaylistItem, PlaylistItemHeader}; use crate::model::stats::{InputStats, PlaylistStats}; use crate::model::xmltv::{Epg}; use crate::processing::playlist_watch::process_group_watch; @@ -44,7 +44,7 @@ fn filter_playlist(playlist: &mut [PlaylistGroup], target: &ConfigTarget) -> Opt id: pg.id, title: pg.title.clone(), channels, - xtream_cluster: pg.xtream_cluster.clone(), + xtream_cluster: pg.xtream_cluster.clone() }); } }); @@ -207,7 +207,7 @@ fn map_channel(channel: PlaylistItem, mapping: &Mapping) -> PlaylistItem { let provider = ValueProvider { pli: ref_chan.clone() }; let mut mock_processor = MockValueProcessor {}; for m in &mapping.mapper { - let mut processor = MappingValueProcessor { pli: ref_chan.clone(), mapper: m}; + let mut processor = MappingValueProcessor { pli: ref_chan.clone(), mapper: m }; match &m._filter { Some(filter) => { if filter.filter(&provider, &mut mock_processor) { @@ -236,7 +236,7 @@ fn map_playlist(playlist: &mut [PlaylistGroup], target: &ConfigTarget) -> Option // if the group names are changed, restructure channels to the right groups // we use let mut new_groups: Vec = Vec::new(); - let mut grp_id: i32 = 0; + let mut grp_id: u32 = 0; for playlist_group in new_playlist { for channel in &playlist_group.channels { let cluster = &channel.header.borrow().xtream_cluster; @@ -249,7 +249,7 @@ fn map_playlist(playlist: &mut [PlaylistGroup], target: &ConfigTarget) -> Option id: grp_id, title: Rc::clone(title), channels: vec![channel.clone()], - xtream_cluster: cluster.clone(), + xtream_cluster: cluster.clone() }) } } @@ -271,6 +271,10 @@ fn is_input_enabled(enabled_inputs: usize, input_enabled: bool, input_id: u16, u input_enabled } +fn is_target_enabled(target: &ConfigTarget, user_targets: &ProcessTargets) -> bool { + (!user_targets.enabled && target.enabled) || (user_targets.enabled && user_targets.has_target(target.id)) +} + async fn process_source(cfg: Arc, source_idx: usize, user_targets: Arc) -> (Vec, Vec) { let source = cfg.sources.get(source_idx).unwrap(); let mut all_playlist = Vec::new(); @@ -278,7 +282,6 @@ async fn process_source(cfg: Arc, source_idx: usize, user_targets: Arc

::new(); for input in &source.inputs { - //if input.enabled || (user_targets.enabled && user_targets.has_input(input.id)) { let input_id = input.id; if is_input_enabled(enabled_inputs, input.enabled, input_id, &user_targets) { let (playlist, mut error_list) = match input.input_type { @@ -286,7 +289,9 @@ async fn process_source(cfg: Arc, source_idx: usize, user_targets: Arc

get_xtream_playlist(input, &cfg.working_dir).await, }; let (tvguide, mut tvguide_errors) = if error_list.is_empty() { - get_xmltv(&cfg, input, &cfg.working_dir).await } else { (None, vec![]) + get_xmltv(&cfg, input, &cfg.working_dir).await + } else { + (None, vec![]) }; error_list.drain(..).for_each(|err| errors.push(err)); tvguide_errors.drain(..).for_each(|err| errors.push(err)); @@ -306,7 +311,7 @@ async fn process_source(cfg: Arc, source_idx: usize, user_targets: Arc

, source_idx: usize, user_targets: Arc

{} Err(mut err) => err.drain(..).for_each(|e| errors.push(e)) } } - }); + } } (stats.drain().map(|(_, v)| v).collect(), errors) } @@ -401,15 +404,16 @@ fn get_processing_pipe(target: &ConfigTarget) -> ProcessingPipe { } } -pub(crate) fn process_playlist(playlists: &mut [FetchedPlaylist], - target: &ConfigTarget, cfg: &Config, - stats: &mut HashMap) -> Result<(), Vec> { +pub(crate) async fn process_playlist<'a>(playlists: &mut [FetchedPlaylist<'a>], + target: &ConfigTarget, cfg: &Config, + stats: &mut HashMap, + errors: &mut Vec) -> Result<(), Vec> { let pipe = get_processing_pipe(target); debug!("Processing order is {}", &target.processing_order); let mut new_fetched_playlists: Vec = vec![]; - playlists.iter_mut().for_each(|fpl| { + for fpl in playlists.iter_mut() { let mut new_fpl = FetchedPlaylist { input: fpl.input, playlist: fpl.playlist.clone(), // we need to clone, because of multiple target definitions, we cant change the initial playlist. @@ -422,6 +426,24 @@ pub(crate) fn process_playlist(playlists: &mut [FetchedPlaylist], new_fpl.playlist = v; } } + let resolve_series = + if let Some(options) = &target.options { + options.xtream_resolve_series && fpl.input.input_type == InputType::Xtream && target.has_output(&TargetType::M3u) + } else { + false + }; + if resolve_series { + get_xtream_playlist_series(fpl, errors).await; + // the original list has now resolved the series info items. + // wee need to pipe them an put them into + // TODO + //for plg in fpl.playlist { + // 1. extract series playlistitems per group + // 2. run processing pipe + // 3. assign results to the new_fpl groups. + //} + } + // stats let input_stats = stats.get_mut(&new_fpl.input.id); if let Some(stat) = input_stats { @@ -432,7 +454,7 @@ pub(crate) fn process_playlist(playlists: &mut [FetchedPlaylist], } new_fetched_playlists.push(new_fpl); - }); + } apply_affixes(&mut new_fetched_playlists); let mut new_playlist = vec![]; @@ -491,7 +513,7 @@ fn persist_playlist(playlist: &[PlaylistGroup], epg: Option, Ok(_) => { if !playlist.is_empty() { match write_epg(target, cfg, &epg, output) { - Ok(_) => {}, + Ok(_) => {} Err(err) => errors.push(err) } } diff --git a/src/processing/playlist_watch.rs b/src/processing/playlist_watch.rs index fdd63ff8c..e72f9e124 100644 --- a/src/processing/playlist_watch.rs +++ b/src/processing/playlist_watch.rs @@ -4,7 +4,7 @@ use log::{error, info}; use regex::Regex; use crate::messaging::{MsgKind, send_message}; use crate::model::config::Config; -use crate::model::model_m3u::PlaylistGroup; +use crate::model::model_playlist::PlaylistGroup; use crate::utils; pub(crate) fn process_group_watch(cfg: &Config, target_name: &str, pl: &PlaylistGroup) { diff --git a/src/processing/xtream_parser.rs b/src/processing/xtream_parser.rs index 679014ec8..80780ea98 100644 --- a/src/processing/xtream_parser.rs +++ b/src/processing/xtream_parser.rs @@ -1,227 +1,16 @@ use std::cell::RefCell; use std::collections::HashMap; use std::rc::Rc; -use std::sync::atomic::{AtomicI32, Ordering}; +use std::sync::atomic::{AtomicU32, Ordering}; -use serde::{Deserialize, Deserializer, Serialize}; -use serde::de::DeserializeOwned; use serde_json::Value; -use crate::create_m3u_filter_error_result; +use crate::{create_m3u_filter_error_result}; use crate::m3u_filter_error::{M3uFilterError, M3uFilterErrorKind}; +use crate::model::config::ConfigInput; use crate::model::model_config::{default_as_empty_rc_str}; -use crate::model::model_m3u::{PlaylistGroup, PlaylistItem, PlaylistItemHeader, XtreamCluster}; - -fn default_as_empty_list() -> Vec { vec![] } - -fn deserialize_number_from_string<'de, D, T: DeserializeOwned>( - deserializer: D, -) -> Result, D::Error> - where - D: Deserializer<'de>, -{ - // we define a local enum type inside of the function - // because it is untagged, serde will deserialize as the first variant - // that it can - #[derive(Deserialize)] - #[serde(untagged)] - enum MaybeNumber { - // if it can be parsed as Option, it will be - Value(Option), - // otherwise try parsing as a string - NumberString(String), - } - - // deserialize into local enum - let value: MaybeNumber = Deserialize::deserialize(deserializer)?; - match value { - // if parsed as T or None, return that - MaybeNumber::Value(value) => Ok(value), - - // (if it is any other string) - MaybeNumber::NumberString(string) => { - match serde_json::from_str::(string.as_str()) { - Ok(val) => Ok(Some(val)), - Err(_) => Ok(None) - } - } - } -} - -fn value_to_string_array(value: &[Value]) -> Option> { - Some(value.iter().filter_map(value_to_string).collect()) -} - -fn value_to_string(v: &Value) -> Option { - match v { - Value::Bool(value) => Some(value.to_string()), - Value::Number(value) => Some(value.to_string()), - Value::String(value) => Some(value.to_string()), - _ => None, - } -} - -fn deserialize_as_option_rc_string<'de, D>(deserializer: D) -> Result>, D::Error> - where - D: Deserializer<'de>, -{ - let value: Value = Deserialize::deserialize(deserializer)?; - - match &value { - Value::String(s) => Ok(Some(Rc::new(s.to_owned()))), - Value::Number(s) => Ok(Some(Rc::new(s.to_string()))), - _ => Ok(None), - } -} - -fn deserialize_as_rc_string<'de, D>(deserializer: D) -> Result, D::Error> - where - D: Deserializer<'de>, -{ - let value: Value = Deserialize::deserialize(deserializer)?; - - match &value { - Value::String(s) => Ok(Rc::new(s.to_owned())), - _ => Ok(Rc::new(value.to_string())), - } -} - -fn deserialize_as_string_array<'de, D>(deserializer: D) -> Result>, D::Error> - where - D: Deserializer<'de>, -{ - Value::deserialize(deserializer).map(|v| match v { - Value::Array(value) => value_to_string_array(&value), - _ => None, - }) -} - -#[derive(Deserialize)] -struct XtreamCategory { - #[serde(deserialize_with = "deserialize_as_rc_string")] - pub category_id: Rc, - #[serde(deserialize_with = "deserialize_as_rc_string")] - pub category_name: Rc, - //pub parent_id: i32, - #[serde(default = "default_as_empty_list")] - pub channels: Vec, -} - -impl XtreamCategory { - fn add(&mut self, item: PlaylistItem) { - self.channels.push(item); - } -} - -#[derive(Serialize, Deserialize)] -struct XtreamStream { - #[serde(default, deserialize_with = "deserialize_as_rc_string")] - pub name: Rc, - #[serde(default, deserialize_with = "deserialize_as_rc_string")] - pub category_id: Rc, - #[serde(default, deserialize_with = "deserialize_number_from_string")] - pub stream_id: Option, - #[serde(default, deserialize_with = "deserialize_number_from_string")] - pub series_id: Option, - #[serde(default = "default_as_empty_rc_str", deserialize_with = "deserialize_as_rc_string")] - pub stream_icon: Rc, - #[serde(default = "default_as_empty_rc_str", deserialize_with = "deserialize_as_rc_string")] - pub direct_source: Rc, - - // optional attributes - #[serde(default, deserialize_with = "deserialize_as_string_array")] - backdrop_path: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - added: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - cast: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - container_extension: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - cover: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - director: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - episode_run_time: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - genre: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - last_modified: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - plot: Option>, - #[serde(default, deserialize_with = "deserialize_number_from_string")] - rating: Option, - #[serde(default, deserialize_with = "deserialize_number_from_string")] - rating_5based: Option, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - release_date: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - stream_type: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - title: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - year: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - youtube_trailer: Option>, - #[serde(default, deserialize_with = "deserialize_as_option_rc_string")] - epg_channel_id: Option>, - #[serde(default, deserialize_with = "deserialize_number_from_string")] - tv_archive: Option, - #[serde(default, deserialize_with = "deserialize_number_from_string")] - tv_archive_duration: Option, -} - -macro_rules! add_str_property_if_exists { - ($vec:expr, $prop:expr, $prop_name:expr) => { - $prop.as_ref().map(|v| $vec.push((String::from($prop_name), Value::String(v.to_string())))); - } -} -macro_rules! add_i64_property_if_exists { - ($vec:expr, $prop:expr, $prop_name:expr) => { - $prop.as_ref().map(|v| $vec.push((String::from($prop_name), Value::Number(serde_json::value::Number::from(i64::from(*v)))))); - } -} - -macro_rules! add_f64_property_if_exists { - ($vec:expr, $prop:expr, $prop_name:expr) => { - $prop.as_ref().map(|v| $vec.push((String::from($prop_name), Value::Number(serde_json::value::Number::from_f64(f64::from(*v)).unwrap())))); - } -} - -impl XtreamStream { - pub(crate) fn get_stream_id(&self) -> String { - self.stream_id.map_or_else(|| self.series_id.map_or_else(|| String::from(""), |seid| format!("{}", seid)), |sid| format!("{}", sid)) - } - - pub(crate) fn get_additional_properties(&self) -> Option> { - let mut result = vec![]; - if let Some(bdpath) = self.backdrop_path.as_ref() { - if !bdpath.is_empty() { - result.push((String::from("backdrop_path"), Value::Array(Vec::from([Value::String(String::from(bdpath.get(0).unwrap()))])))); - } - } - add_str_property_if_exists!(result, self.added, "added"); - add_str_property_if_exists!(result, self.cast, "cast"); - add_str_property_if_exists!(result, self.container_extension, "container_extension"); - add_str_property_if_exists!(result, self.cover, "cover"); - add_str_property_if_exists!(result, self.director, "director"); - add_str_property_if_exists!(result, self.episode_run_time, "episode_run_time"); - add_str_property_if_exists!(result, self.genre, "genre"); - add_str_property_if_exists!(result, self.last_modified, "last_modified"); - add_str_property_if_exists!(result, self.plot, "plot"); - add_f64_property_if_exists!(result, self.rating, "rating"); - add_f64_property_if_exists!(result, self.rating_5based, "rating_5based"); - add_str_property_if_exists!(result, self.release_date, "release_date"); - add_str_property_if_exists!(result, self.stream_type, "stream_type"); - add_str_property_if_exists!(result, self.title, "title"); - add_str_property_if_exists!(result, self.year, "year"); - add_str_property_if_exists!(result, self.youtube_trailer, "youtube_trailer"); - //add_str_property_if_exists!(result, self.epg_channel_id, "epg_channel_id"); - add_i64_property_if_exists!(result, self.tv_archive, "tv_archive"); - add_i64_property_if_exists!(result, self.tv_archive_duration, "tv_archive_duration"); - if result.is_empty() { None } else { Some(result) } - } -} +use crate::model::model_playlist::{PlaylistGroup, PlaylistItem, PlaylistItemHeader, PlaylistItemType, XtreamCluster}; +use crate::model::model_xtream::{XtreamCategory, XtreamSeriesInfo, XtreamStream}; fn process_category(category: &Value) -> Result, M3uFilterError> { match serde_json::from_value::>(category.to_owned()) { @@ -242,15 +31,61 @@ fn process_streams(xtream_cluster: &XtreamCluster, streams: &Value) -> Result Result>, M3uFilterError> { + let url = input.url.as_str(); + let username = input.username.as_ref().map_or("", |v| v); + let password = input.password.as_ref().map_or("", |v| v); + + match serde_json::from_value::(info.to_owned()) { + Ok(series_info) => { + let result: Vec = series_info.episodes.values().flatten().map(|episode| + PlaylistItem { + header: RefCell::new(PlaylistItemHeader { + id: Rc::new(episode.id.to_owned()), + name: Rc::new(episode.title.to_owned()), + logo: Rc::new(episode.info.movie_image.to_owned()), + logo_small: default_as_empty_rc_str(), + group: Rc::new(group_title.to_string()), + title: Rc::new(episode.title.to_owned()), + parent_code: default_as_empty_rc_str(), + audio_track: default_as_empty_rc_str(), + time_shift: default_as_empty_rc_str(), + rec: default_as_empty_rc_str(), + // source is meant to hold the original provider data + source: default_as_empty_rc_str(), + url: if episode.direct_source.is_empty() { + let ext = episode.container_extension.to_owned(); + let stream_base_url = format!("{}/series/{}/{}/{}.{}", url, username, password, episode.id.as_str(), ext); + Rc::new(stream_base_url) + } else { + Rc::new(episode.direct_source.to_owned()) + }, + epg_channel_id: None, + item_type: PlaylistItemType::Series, + xtream_cluster: XtreamCluster::Series, + additional_properties: episode.get_additional_properties(&series_info), + series_fetched: false, + }) + }).collect(); + if result.is_empty() { Ok(None) } else { Ok(Some(result)) } + } + Err(err) => { + create_m3u_filter_error_result!(M3uFilterErrorKind::Notify, "Failed to process series info {}", &err) + } + } +} + +pub(crate) fn parse_xtream(cat_id_cnt: &AtomicU32, xtream_cluster: &XtreamCluster, category: &Value, - url: &str, - username: &str, - password: &str, + input: &ConfigInput, streams: &Value) -> Result>, M3uFilterError> { match process_category(category) { Ok(mut categories) => { + let url = input.url.as_str(); + let username = input.username.as_ref().map_or("", |v| v); + let password = input.password.as_ref().map_or("", |v| v); + return match process_streams(xtream_cluster, streams) { Ok(streams) => { let group_map: HashMap::, RefCell> = @@ -278,11 +113,11 @@ pub(crate) fn parse_xtream(cat_id_cnt: &AtomicI32, source: default_as_empty_rc_str(), url: if stream.direct_source.is_empty() { let stream_base_url = match xtream_cluster { - XtreamCluster::Live => format!("{}/live/{}/{}/{}.ts", url, username, password, &stream.get_stream_id()), + XtreamCluster::Live => format!("{}/live/{}/{}/{}.ts", url, username, password, &stream.get_stream_id()), XtreamCluster::Video => { let ext = stream.container_extension.as_ref().map_or("mp4", |e| e.as_str()); - format!("{}/live/{}/{}/{}.{}", url, username, password, &stream.get_stream_id(), ext) - }, + format!("{}/movie/{}/{}/{}.{}", url, username, password, &stream.get_stream_id(), ext) + } XtreamCluster::Series => format!("{}/player_api.php?username={}&password={}&action=get_series_info&series_id={}", url, username, password, &stream.get_stream_id()) @@ -292,8 +127,14 @@ pub(crate) fn parse_xtream(cat_id_cnt: &AtomicI32, Rc::clone(&stream.direct_source) }, epg_channel_id: stream.epg_channel_id.clone(), + item_type: match xtream_cluster { + XtreamCluster::Live => PlaylistItemType::Live, + XtreamCluster::Video => PlaylistItemType::Movie, + XtreamCluster::Series => PlaylistItemType::SeriesInfo, + }, xtream_cluster: xtream_cluster.clone(), additional_properties: stream.get_additional_properties(), + series_fetched: false, }), }; grp.add(item); @@ -307,7 +148,7 @@ pub(crate) fn parse_xtream(cat_id_cnt: &AtomicI32, id: cat_id_cnt.load(Ordering::Relaxed), xtream_cluster: xtream_cluster.clone(), title: Rc::clone(&cat.category_name), - channels: cat.channels.clone(), + channels: cat.channels.clone() } }).collect())) } diff --git a/src/repository/m3u_repository.rs b/src/repository/m3u_repository.rs index 540d7a170..c3674c976 100644 --- a/src/repository/m3u_repository.rs +++ b/src/repository/m3u_repository.rs @@ -7,7 +7,7 @@ use log::error; use crate::{create_m3u_filter_error_result, utils}; use crate::m3u_filter_error::{M3uFilterError, M3uFilterErrorKind}; use crate::model::config::{Config, ConfigTarget}; -use crate::model::model_m3u::PlaylistGroup; +use crate::model::model_playlist::{PlaylistGroup, PlaylistItemType}; use crate::utils::add_prefix_to_filename; fn check_write(res: std::io::Result<()>) -> Result<(), std::io::Error> { @@ -113,6 +113,10 @@ pub(crate) fn write_m3u_playlist(target: &ConfigTarget, cfg: &Config, new_playli } for pg in new_playlist { for pli in &pg.channels { + if pli.header.borrow().item_type == PlaylistItemType::SeriesInfo { + // we skip series info, because this is only necessary when writing xtream files + continue; + } let content = pli.to_m3u(&target.options); match check_write(m3u_file.write_all(content.as_bytes())) { Ok(_) => (), diff --git a/src/repository/xtream_repository.rs b/src/repository/xtream_repository.rs index 012b02b3d..bbd2b6345 100644 --- a/src/repository/xtream_repository.rs +++ b/src/repository/xtream_repository.rs @@ -9,7 +9,7 @@ use log::{error}; use serde::Serialize; use serde_json::{json, Map, Value}; use crate::model::config::{Config, ConfigInput, ConfigTarget}; -use crate::model::model_m3u::{PlaylistGroup, PlaylistItemHeader, XtreamCluster}; +use crate::model::model_playlist::{PlaylistGroup, PlaylistItemHeader, PlaylistItemType, XtreamCluster}; use crate::{create_m3u_filter_error_result, utils}; use crate::api::api_model::AppState; use crate::m3u_filter_error::{M3uFilterError, M3uFilterErrorKind}; @@ -147,8 +147,12 @@ pub(crate) fn write_xtream_playlist(target: &ConfigTarget, cfg: &Config, playlis })); for pli in &plg.channels { - channel_num += 1; let header = &pli.header.borrow(); + if header.item_type == PlaylistItemType::Series { + // we skip resolved series, because this is only necessary when writing m3u files + continue; + } + channel_num += 1; let mut document = serde_json::Map::from_iter([ ("category_id".to_string(), Value::String(format!("{}", &plg.id))), ("category_ids".to_string(), Value::Array(Vec::from([Value::Number(serde_json::Number::from(plg.id.to_owned()))]))), diff --git a/src/utils.rs b/src/utils.rs index e5f4a4ebd..70f414d65 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -254,7 +254,7 @@ async fn download_json_content(input: &ConfigInput, url: url::Url, persist_filep } } -pub(crate) async fn get_input_json_content(input: &ConfigInput, url_str: &String, persist_filepath: Option) -> Result { +pub(crate) async fn get_input_json_content(input: &ConfigInput, url_str: &str, persist_filepath: Option) -> Result { match url_str.parse::() { Ok(url) => match download_json_content(input, url, persist_filepath).await { Ok(content) => Ok(content),