From b40504de42b24cc89600da13690c73ddca2642e2 Mon Sep 17 00:00:00 2001 From: euzu Date: Sat, 25 Feb 2023 14:02:53 +0100 Subject: [PATCH] ISSUE-15 ISSUE-14 ISSUE-13 fixed suffix/prefix tag problems added new fields to mapping attributes and assignments --- CHANGELOG.md | 15 +++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 35 ++++++++++++++++++++++++----------- bin/release.sh | 20 ++++++++++++++++---- frontend/package.json | 2 +- src/mapping.rs | 25 ++++++++++++++----------- src/model.rs | 12 ++++++++++-- 8 files changed, 82 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 030d552e5..86ad94e17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,19 @@ # Changelog +# v0.9.8(2023-02-25) +* Added new fields to mapping attributes and assignments + - "name" + - "title" + - "group" + - "id" + - "chno" + - "logo" + - "logo_small" + - "parent_code" + - "audio_track" + - "time_shift" + - "rec" + - "source" + # v0.9.7(2023-02-15) * Breaking changes, mappings.yml refactored * Added `threads` property to config, which executes different sources in threads. diff --git a/Cargo.lock b/Cargo.lock index c512fc388..cccc1c9f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1066,7 +1066,7 @@ dependencies = [ [[package]] name = "m3u-filter" -version = "0.9.6" +version = "0.9.7" dependencies = [ "actix-cors", "actix-files", diff --git a/Cargo.toml b/Cargo.toml index 3657f7d63..a12123f5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "m3u-filter" -version = "0.9.6" +version = "0.9.7" edition = "2018" [profile.release] diff --git a/README.md b/README.md index 17eff359e..720222a70 100644 --- a/README.md +++ b/README.md @@ -246,12 +246,18 @@ but lacks a few features like look around and backreferences. #### 2.3.4.2 `attributes` Attributes is a map of key value pairs. Valid keys are: -- name -- group -- title -- logo -- id -- chno +- `id` +- `chno` +- `name` +- `group` +- `title` +- `logo` +- `logo_small` +- `parent_code` +- `audio_track` +- `time_shift` +- `rec` +- `source` If the regexps matches, the given fields will be set to the new value @@ -293,11 +299,18 @@ If the regexps matches, the given fields will be prefixed to field value #### 2.3.4.5 `assignments` Attributes is a map of key value pairs. Valid keys and values are: -- name -- group -- title -- id -- chno +- `id` +- `chno` +- `name` +- `group` +- `title` +- `logo` +- `logo_small` +- `parent_code` +- `audio_track` +- `time_shift` +- `rec` +- `source` Example configuration is: ``` diff --git a/bin/release.sh b/bin/release.sh index 461100f7e..05a0010ed 100755 --- a/bin/release.sh +++ b/bin/release.sh @@ -1,11 +1,23 @@ #!/usr/bin/env bash -if [[ -z "$1" ]]; then - echo "No argument supplied. First argument should be version number like 1.0.0" - exit 1 +if ! command -v cargo-set-version &> /dev/null +then + echo "cargo-set-version could not be found. install it with 'cargo install cargo-edit'" + exit fi -VERSION=v$1 +#if [[ -z "$1" ]]; then +# echo "No argument supplied. First argument should be version number like 1.0.0" +# exit 1 +#fi + +cd ./frontend || (echo "cant find frontend directory" && exit) +NEW_VERSION=$(yarn version --patch | grep "New version" | grep -Po "(\d+\.)+\d+") +cd .. +cargo-set-version set-version ./Cargo.toml "$NEW_VERSION" + + +VERSION=v$NEW_VERSION LIN_DIR=m3u-filter_${VERSION}_linux_x86_64 WIN_DIR=m3u-filter_${VERSION}_windows_x86_64 DARWIN_DIR=m3u-filter_${VERSION}_darwin_x86_64 diff --git a/frontend/package.json b/frontend/package.json index 95656fdd5..a0e3a80d8 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -2,7 +2,7 @@ "name": "m3u-filter", "description": "m3u-filter", "author": "euzu", - "version": "0.9.8", + "version": "0.9.7", "private": true, "homepage": "./", "scripts": { diff --git a/src/mapping.rs b/src/mapping.rs index cd8653314..259d654fb 100644 --- a/src/mapping.rs +++ b/src/mapping.rs @@ -5,7 +5,9 @@ use crate::m3u::{FieldAccessor, PlaylistItem}; use crate::model::{ItemField, MAPPER_ATTRIBUTE_FIELDS, MAPPER_PREFIX_SUFFIX_FIELDS}; fn default_as_false() -> bool { false } + fn default_as_empty_str() -> String { String::from("") } + fn default_as_empty_map() -> HashMap { HashMap::new() } #[derive(Debug, serde::Serialize, serde::Deserialize)] @@ -92,7 +94,7 @@ impl MappingValueProcessor<'_> { fn get_property(&self, key: &str) -> Option { match self.pli.header.get_field(key) { Some(value) => Some(String::from(value)), - _=> None + _ => None } } @@ -123,24 +125,26 @@ impl MappingValueProcessor<'_> { for mapping_tag in &self.mapper._tags { if mapping_tag.name.eq(tag_capture) { // we have the right tag, now get all captured values - let mut captured_tag_values : Vec<&str> = Vec::new(); + let mut captured_tag_values: Vec<&str> = Vec::new(); for cap in &mapping_tag.captures { match captures.get(&cap) { Some(cap_value) => captured_tag_values.push(cap_value), _ => { if verbose { println!("Cant find any tag match for {}", tag_capture) } - return None + return None; } } } if captured_tag_values.len() > 0 { let captured_text = captured_tag_values.join(&mapping_tag.concat); - if captured_text.trim().len() > 0 { + let replacement = if captured_text.trim().len() > 0 { // Now we have all our captured values, lets create the tag - new_value = new_value.replace( - format!("", mapping_tag.name).as_str(), - format!("{}{}{}", &mapping_tag.prefix, captured_text, &mapping_tag.suffix).as_str()); - } + format!("{}{}{}", &mapping_tag.prefix, captured_text, &mapping_tag.suffix) + } else { + // nothing found so replace tag with empty string + String::from("") + }; + new_value = new_value.replace(format!("", mapping_tag.name).as_str(), replacement.as_str()); } } } @@ -193,13 +197,12 @@ impl MappingValueProcessor<'_> { match self.get_property(value) { Some(prop_value) => { self.set_property(key, &prop_value, verbose); - }, + } _ => {} } } } } - } impl ValueProcessor for MappingValueProcessor<'_> { @@ -275,7 +278,7 @@ pub struct MappingDefinition { impl MappingDefinition { pub(crate) fn prepare(&mut self, verbose: bool) { match &mut self.templates { - Some(templates) =>self.templates = Some(prepare_templates(templates, verbose)), + Some(templates) => self.templates = Some(prepare_templates(templates, verbose)), _ => {} }; for mapping in &mut self.mapping { diff --git a/src/model.rs b/src/model.rs index ac117494d..92b3da8e8 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1,6 +1,14 @@ use enum_iterator::Sequence; -pub const MAPPER_ATTRIBUTE_FIELDS: &[&str] = &["name", "title", "group", "id", "chno"]; +pub const MAPPER_ATTRIBUTE_FIELDS: &[&str] = &[ + "name", "title", "group", "id", "chno", "logo", + "logo_small", + "parent_code", + "audio_track", + "time_shift", + "rec", + "source", +]; pub const MAPPER_PREFIX_SUFFIX_FIELDS: &[&str] = &["name", "title", "group"]; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Sequence)] @@ -33,7 +41,7 @@ pub enum ProcessingOrder { #[serde(rename = "mfr")] MFR, #[serde(rename = "mrf")] - MRF + MRF, } impl std::fmt::Display for ProcessingOrder {