bebo-dot-dev / m3u-epg-editor

a python m3u / epg optimizer
120 stars 27 forks source link

channel transform using regex #59

Closed Olivier6767 closed 3 years ago

Olivier6767 commented 3 years ago

Hello, First of all Thank you for this tool, very helpful ! Would it be possible to add Regex substitution for channel_transforms?

To explain why this would be useful, here is an example from my provider's channel list:

UK: VIP Sky Sports Arena FHD
UK: VIP Sky Sports Box Office HEVC
UK: VIP Sky Sports F1 HD
UK: VIP Sky Sports Football FHD
UK: VIP Sky Sports Golf FHD
UK: VIP Sky Sports Main Event HD
UK: VIP Sky Sports Mix FHD
UK: VIP Sky Sports NFL FHD
UK: VIP Sky Sports News HQ HEVC
UK: VIP Sky Sports Premier League HD
UK: VIP Sky Sports Racing FHD

And here is what I would like to have:

Sky Sports Arena 
Sky Sports Box Office 
Sky Sports F1
Sky Sports Football 
Sky Sports Golf 
Sky Sports Main Event
Sky Sports Mix 
Sky Sports NFL 
Sky Sports News HQ 
Sky Sports Premier League 
Sky Sports Racing 

I can use key:value pairs in channel_transforms, but I have over 300 channels to rename.

I was thinking about the possibility to use a regex substitution like this: / (UK: VIP )(.*)(HEVC|.HD) / $2 which provides the desired result. Obviously I would need multiple entries to cover other country prefixes for example.

Is this something that could be added?

Thanks for considering it!

bebo-dot-dev commented 3 years ago

Hi there, this sounds like a reasonable feature request. A decision was made to not introduce support for regular expressions when the transform arguments were introduced.. but I honestly can't remember what the reason was now because it was so long ago.

I'll take a look to see what can be done.

Olivier6767 commented 3 years ago

Great! Thank you.

bebo-dot-dev commented 3 years ago

I've added a new https://github.com/jjssoftware/m3u-epg-editor/tree/regex_transforms branch that contains a candidate change for this new feature.

I've given this a quick test using the following config which matches some test data similar as you advised and it appeared to result in the expected outcome:

"channel_transforms": [
        {"(UK: VIP )(.*)(HEVC|.HD)": "\\2"}
    ]

I'd appreciate it if you could give it a try, thanks.

Olivier6767 commented 3 years ago

Thank you! I've tested and it does work as expected. I was able to clean-up the channel names for my complete channel list using 11 regex in the channel_transforms. This is awesome!

Can this be easily implemented for group_transforms as well?

bebo-dot-dev commented 3 years ago

Thanks that's good to hear. Please give regex a try with the group_transforms argument too, the change has been applied in an area that hopefully should work for that too.

Olivier6767 commented 3 years ago

I confirm it works well in group_transforms as well. This is a great enhancement.

Many Thanks!

bebo-dot-dev commented 3 years ago

Thanks for confirming, I'll merge the change