Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding argument for modify some values in generated m3u file #47

Closed
arjunior26 opened this issue Apr 30, 2020 · 11 comments
Closed

Adding argument for modify some values in generated m3u file #47

arjunior26 opened this issue Apr 30, 2020 · 11 comments
Labels
feature request A new feature request

Comments

@arjunior26
Copy link

Hi,

What do you think about adding one option (argument) to be able to change/correct some values in generated m3u file (incorrect channel names, groups, id, etc..)
I add the code below to your python script but it would be nicer if we have a new argument option to use in command line or Json file ;)

# personals modifications of m3u file
def edit_m3u_file(directory, m3u_filename):
	
    output_str("opening m3u file: " + directory + m3u_filename)
    with io.open(directory + m3u_filename, "r", encoding="utf-8") as m3u_file:
        datas = m3u_file.read()

        # edit wrong groups name
        output_str("editing wrong value for groups name...")
        datas = datas.replace("SICIENCE", "SCIENCE")
        .....

        # edit wrong channels name
        output_str("editing wrong value for channels name...")
        datas = datas.replace("LIVEFRANKLIN HD", "LIVE FRANKLIN HD")
        datas = datas.replace(" FULL HD", "")
        datas = datas.replace("  ", " ")
        .....

    output_str("saving edited m3u file: " + directory + m3u_filename)
    with io.open(directory + m3u_filename, "w", encoding="utf-8") as m3u_file:
        m3u_file.write(datas)

Regards.

@bebo-dot-dev bebo-dot-dev added the feature request A new feature request label May 1, 2020
@bebo-dot-dev
Copy link
Owner

bebo-dot-dev commented May 1, 2020

Hi there, I think that this is a decent feature request that I would be willing to take on.

A single new argument could work but I think it will be a better logical fit to introduce two new arguments, one that targets group name transformations and the other to target channel names.

I suggest:

  1. group_transforms [GROUP_TRANSFORMS], -gt - An array of key value pairs representing source group names to target groups names to be applied at processing time.
  2. channel_transforms [CHANNEL_TRANSFORMS], -ct - An array of key value pairs representing source channel names to target channel names to be applied at processing time.

If you're ok with this idea I'll have a think about how these arguments will look for both CLI and JSON input.

@arjunior26
Copy link
Author

Hi,

Love your suggestion :)
Maybe adding tvg-id transformation argument at processing time will be useful too!

Thank you.

@bebo-dot-dev
Copy link
Owner

Ok it sounds like a goer, I'll take a look asap.

I have reservations about introducing this same feature for the tvg-id / channel attribute at present due to this being the linking attribute between the m3u data and the epg data. I'm aware that service providers are notoriously bad at maintaining sensible (actually working) linkage data in this area but I feel attempting to fix this is a step too far at the moment.

Let's get the above idea introduced first and then we can review.

@arjunior26
Copy link
Author

Ok, let's go for implementing the two arguments first !

However, I think an option for changing tvd-id value remains legit in case of service providers make typo error like I can find in my current m3u list:
tvg-id="fr.Paramount Channel" instead of tvg-id="ParamountChannel.fr"
tvg-id="fr.TvBreizh" instead of tvg-id="TvBreizh.fr"
and others...

Users should probably understand that changing these values can cause problems with their epg ;)

bebo-dot-dev added a commit that referenced this issue May 2, 2020
@bebo-dot-dev
Copy link
Owner

One new commit pushed to the master branch, give that a try.

The -gt / group_transforms and -ct / channel_transforms arguments are optional and they can be supplied at the CLI and via JSON config.

They take a small blob of JSON that looks like the following:

{"group_transforms": [
    {"UK Entertainment": "UK Entertainment Edited"},
    {"UK Movies": "UK Movies Edited"}
]}

and

{"channel_transforms": [
    {"BBC 1": "BBC One Edited"},
    {"BBC 2": "BBC Two Edited"},
    {"More 4": "More 4 Edited"}
]}

String matching is case sensitive and regex pattern matching is not supported in this feature.

Thanks.

@arjunior26
Copy link
Author

arjunior26 commented May 2, 2020

Hi,

Hmmm, strange results here but not sure if is related to your modifications.
During creation of xml file, elements are created for every channel present in the new m3u file as expected but elements are created for all channels.

Will make some investigations here...

EDIT:
After verification, filtered m3u file contains all channels

Thanks.

@bebo-dot-dev
Copy link
Owner

Jolly good, no catastrophic bug found yet by the sound of things. Please give this feature a bit of a test and let me know if it appears to be working as you expect it to. Thanks.

@arjunior26
Copy link
Author

Ok, the problem was due to regex search in is_item_matched() function :(
This is probably caused by one more caracter which needs to be escaped in my list...
Don't worry about this.

Therefore this new feature works perfectly 👍

Maybe it will be better to change name of channel in addition to tvg-name by replacing
meta += ",%s\n" % entry.name by meta += ",%s\n" % entry.tvg_name
in save_new_m3u() function.

Thank you.

@bebo-dot-dev
Copy link
Owner

Thanks for confirming.

I was in two minds about what to do about the .name property of the m3u entry and ended up leaving it as-is. On reflection I think that you're correct, something needs to be done. Assuming that everyone will always want this value output into the new m3u file as the .tvg_name value is probably not the right decision though because it is possible (rightly or wrongly) for these props to have different values in the source data. As a compromise I'm going to apply the channel_transforms collection to the .name value.

bebo-dot-dev added a commit that referenced this issue May 2, 2020
@bebo-dot-dev
Copy link
Owner

Done, the .name transform change is squashed into the last commit, I'm going to close this now.

If you really do want / need a tvg-id transform feature please open a new issue. Thanks.

@arjunior26
Copy link
Author

Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A new feature request
Projects
None yet
Development

No branches or pull requests

2 participants