started implementing xtream series to m3u playlist.

This commit is contained in:
euzu
2023-12-08 19:08:04 +01:00
parent d6fe0caa44
commit 1c8abcb01a
18 changed files with 548 additions and 269 deletions
+1
View File
@@ -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`
+8 -3
View File
@@ -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`
+4 -1
View File
@@ -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,
+1 -1
View File
@@ -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};
+49 -6
View File
@@ -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<PathBuf> {
@@ -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<M3uFilterError>) {
let input = fpl.input;
for plg in &mut fpl.playlist {
let mut group_series: Option<Vec<PlaylistItem>> = 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));
+1 -1
View File
@@ -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};
+2
View File
@@ -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)]
+1 -1
View File
@@ -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 {
+3 -2
View File
@@ -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;
pub(crate) mod xmltv;
pub(crate) mod model_xtream;
@@ -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<Rc<String>>;
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<Vec<(String, Value)>>,
#[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<String>,
pub channels: Vec<PlaylistItem>,
#[serde(default = "default_stream_cluster", skip_serializing, skip_deserializing)]
pub xtream_cluster: XtreamCluster,
}
+333
View File
@@ -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<PlaylistItem> { vec![] }
fn deserialize_number_from_string<'de, D, T: DeserializeOwned>(
deserializer: D,
) -> Result<Option<T>, 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<U> {
// if it can be parsed as Option<T>, it will be
Value(Option<U>),
// otherwise try parsing as a string
NumberString(String),
}
// deserialize into local enum
let value: MaybeNumber<T> = 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::<T>(string.as_str()) {
Ok(val) => Ok(Some(val)),
Err(_) => Ok(None)
}
}
}
}
fn value_to_string_array(value: &[Value]) -> Option<Vec<String>> {
Some(value.iter().filter_map(value_to_string).collect())
}
fn value_to_string(v: &Value) -> Option<String> {
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<Option<Rc<String>>, 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<Rc<String>, 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<Option<Vec<String>>, 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<String>,
#[serde(deserialize_with = "deserialize_as_rc_string")]
pub category_name: Rc<String>,
//pub parent_id: i32,
#[serde(default = "default_as_empty_list")]
pub channels: Vec<PlaylistItem>,
}
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<String>,
#[serde(default, deserialize_with = "deserialize_as_rc_string")]
pub category_id: Rc<String>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
pub stream_id: Option<i32>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
pub series_id: Option<i32>,
#[serde(default = "default_as_empty_rc_str", deserialize_with = "deserialize_as_rc_string")]
pub stream_icon: Rc<String>,
#[serde(default = "default_as_empty_rc_str", deserialize_with = "deserialize_as_rc_string")]
pub direct_source: Rc<String>,
// optional attributes
#[serde(default, deserialize_with = "deserialize_as_string_array")]
pub backdrop_path: Option<Vec<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub added: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub cast: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub container_extension: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub cover: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub director: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub episode_run_time: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub genre: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub last_modified: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub plot: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
pub rating: Option<f64>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
pub rating_5based: Option<f64>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub release_date: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub stream_type: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub title: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub year: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub youtube_trailer: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
pub epg_channel_id: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
pub tv_archive: Option<i32>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
pub tv_archive_duration: Option<i32>,
}
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<Vec<(String, Value)>> {
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<String>,
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<XtreamSeriesInfoSeason>,
pub info: XtreamSeriesInfoInfo,
pub episodes: HashMap<String, Vec<XtreamSeriesInfoEpisode>>,
}
impl XtreamSeriesInfoEpisode {
pub(crate) fn get_additional_properties(&self, series_info: &XtreamSeriesInfo) -> Option<Vec<(String, Value)>> {
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) }
}
}
+6 -3
View File
@@ -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<String>) -> Vec<PlaylistGroup>
}
let mut result: Vec<PlaylistGroup> = 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 });
}
+43 -21
View File
@@ -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<PlaylistGroup> = 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<Config>, source_idx: usize, user_targets: Arc<ProcessTargets>) -> (Vec<InputStats>, Vec<M3uFilterError>) {
let source = cfg.sources.get(source_idx).unwrap();
let mut all_playlist = Vec::new();
@@ -278,7 +282,6 @@ async fn process_source(cfg: Arc<Config>, source_idx: usize, user_targets: Arc<P
let mut errors = vec![];
let mut stats = HashMap::<u16, InputStats>::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<Config>, source_idx: usize, user_targets: Arc<P
InputType::Xtream => 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<Config>, source_idx: usize, user_targets: Arc<P
FetchedPlaylist {
input,
playlist,
epg: tvguide
epg: tvguide,
}
);
}
@@ -330,16 +335,14 @@ async fn process_source(cfg: Arc<Config>, source_idx: usize, user_targets: Arc<P
errors.push(M3uFilterError::new(M3uFilterErrorKind::Notify, format!("Source at {} input is empty", source_idx)));
} else {
debug!("Input has {} groups", all_playlist.len());
source.targets.iter().for_each(|target| {
let should_process = (!user_targets.enabled && target.enabled)
|| (user_targets.enabled && user_targets.has_target(target.id));
if should_process {
match process_playlist(&mut all_playlist, target, &cfg, &mut stats) {
for target in &source.targets {
if is_target_enabled(target, &user_targets) {
match process_playlist(&mut all_playlist, target, &cfg, &mut stats, &mut errors).await {
Ok(_) => {}
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<u16, InputStats>) -> Result<(), Vec<M3uFilterError>> {
pub(crate) async fn process_playlist<'a>(playlists: &mut [FetchedPlaylist<'a>],
target: &ConfigTarget, cfg: &Config,
stats: &mut HashMap<u16, InputStats>,
errors: &mut Vec<M3uFilterError>) -> Result<(), Vec<M3uFilterError>> {
let pipe = get_processing_pipe(target);
debug!("Processing order is {}", &target.processing_order);
let mut new_fetched_playlists: Vec<FetchedPlaylist> = 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<Epg>,
Ok(_) => {
if !playlist.is_empty() {
match write_epg(target, cfg, &epg, output) {
Ok(_) => {},
Ok(_) => {}
Err(err) => errors.push(err)
}
}
+1 -1
View File
@@ -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) {
+65 -224
View File
@@ -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<PlaylistItem> { vec![] }
fn deserialize_number_from_string<'de, D, T: DeserializeOwned>(
deserializer: D,
) -> Result<Option<T>, 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<U> {
// if it can be parsed as Option<T>, it will be
Value(Option<U>),
// otherwise try parsing as a string
NumberString(String),
}
// deserialize into local enum
let value: MaybeNumber<T> = 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::<T>(string.as_str()) {
Ok(val) => Ok(Some(val)),
Err(_) => Ok(None)
}
}
}
}
fn value_to_string_array(value: &[Value]) -> Option<Vec<String>> {
Some(value.iter().filter_map(value_to_string).collect())
}
fn value_to_string(v: &Value) -> Option<String> {
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<Option<Rc<String>>, 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<Rc<String>, 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<Option<Vec<String>>, 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<String>,
#[serde(deserialize_with = "deserialize_as_rc_string")]
pub category_name: Rc<String>,
//pub parent_id: i32,
#[serde(default = "default_as_empty_list")]
pub channels: Vec<PlaylistItem>,
}
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<String>,
#[serde(default, deserialize_with = "deserialize_as_rc_string")]
pub category_id: Rc<String>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
pub stream_id: Option<i32>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
pub series_id: Option<i32>,
#[serde(default = "default_as_empty_rc_str", deserialize_with = "deserialize_as_rc_string")]
pub stream_icon: Rc<String>,
#[serde(default = "default_as_empty_rc_str", deserialize_with = "deserialize_as_rc_string")]
pub direct_source: Rc<String>,
// optional attributes
#[serde(default, deserialize_with = "deserialize_as_string_array")]
backdrop_path: Option<Vec<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
added: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
cast: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
container_extension: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
cover: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
director: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
episode_run_time: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
genre: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
last_modified: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
plot: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
rating: Option<f64>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
rating_5based: Option<f64>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
release_date: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
stream_type: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
title: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
year: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
youtube_trailer: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_as_option_rc_string")]
epg_channel_id: Option<Rc<String>>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
tv_archive: Option<i32>,
#[serde(default, deserialize_with = "deserialize_number_from_string")]
tv_archive_duration: Option<i32>,
}
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<Vec<(String, Value)>> {
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<Vec<XtreamCategory>, M3uFilterError> {
match serde_json::from_value::<Vec<XtreamCategory>>(category.to_owned()) {
@@ -242,15 +31,61 @@ fn process_streams(xtream_cluster: &XtreamCluster, streams: &Value) -> Result<Ve
}
}
pub(crate) fn parse_xtream(cat_id_cnt: &AtomicI32,
pub(crate) fn parse_xtream_series_info(info: &Value, group_title: &str, input: &ConfigInput) -> Result<Option<Vec<PlaylistItem>>, 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::<XtreamSeriesInfo>(info.to_owned()) {
Ok(series_info) => {
let result: Vec<PlaylistItem> = 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<Option<Vec<PlaylistGroup>>, 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::<Rc<String>, RefCell<XtreamCategory>> =
@@ -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()))
}
+5 -1
View File
@@ -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(_) => (),
+6 -2
View File
@@ -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()))]))),
+1 -1
View File
@@ -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<PathBuf>) -> Result<serde_json::Value, M3uFilterError> {
pub(crate) async fn get_input_json_content(input: &ConfigInput, url_str: &str, persist_filepath: Option<PathBuf>) -> Result<serde_json::Value, M3uFilterError> {
match url_str.parse::<url::Url>() {
Ok(url) => match download_json_content(input, url, persist_filepath).await {
Ok(content) => Ok(content),