bebo-dot-dev / m3u-epg-editor

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

tvg-id tag missing in generated m3u file #67

Closed Olivier6767 closed 2 years ago

Olivier6767 commented 2 years ago

Hello, I have an input M3U file that has some channels with a blank tvg-id tag (tvg-id=""). When running m3u-epg-editor to filter out some channels (based on groups), the generated M3U file has no tvg-id tag at all for the ones where it was empty.

My settings for tvg-id and epg are:

    "no_tvg_id": true,
    "no_epg": false,
    "force_epg": false,

When I then use the generated M3U file again to run a second pass of channel filtering (based on channel names), the process crashes here:

2022-02-25T09:22:13.546106 Traceback (most recent call last):
  File "/app/m3u/m3u-epg-editor-py3.py", line 1022, in <module>
    main()
  File "/app/m3u/m3u-epg-editor-py3.py", line 239, in main
    xml_tree = create_new_epg(args, epg_filename, m3u_entries)
  File "/app/m3u/m3u-epg-editor-py3.py", line 848, in create_new_epg
    tvg_id_unique_entries = {e.tvg_id.lower(): e for e in m3u_entries}.values()
  File "/app/m3u/m3u-epg-editor-py3.py", line 848, in <dictcomp>
    tvg_id_unique_entries = {e.tvg_id.lower(): e for e in m3u_entries}.values()
AttributeError: 'NoneType' object has no attribute 'lower'

After looking at the code, I think the following section is the reason for the issue (line 724):

                    if entry.tvg_id is not None and entry.tvg_id != "":
                        channel_id = entry.tvg_id.lower() if not args.preserve_case else entry.tvg_id
                        meta += ' tvg-id="%s"' % channel_id

I have been able to fix it by adding these 2 lines to this block of code:

                    else:
                        meta += ' tvg-id=""'

This forces the tvg-id tag to be present in the M3U file, even if the tvg-id value is blank.

This may not be the most elegant fix..., but it may be useful for other users.

bebo-dot-dev commented 2 years ago

Thanks for that, I suppose it could be argued that https://github.com/bebo-dot-dev/m3u-epg-editor/blob/master/m3u-epg-editor-py3.py#L724 is buggy in so far as it is currently lossy, it removes data from the newly rewritten m3u file that was present in the original m3u file when it shouldn't do that.

I think you could have achieved the same result as your fix by making line #724 look like this:

if entry.tvg_id is not None:

It looks like the the same could be said for a few of the other attributes in the same area, namely group-title, timeshift, catchup-days, catchup and catchup-source.

In a general sense I suspect that most people don't notice if a few empty string attributes go missing from the newly rewritten m3u file but in your case this behaviour seems to be causing an issue due to the double pass filtering arrangement in your setup.

Olivier6767 commented 2 years ago

Thanks. I adjusted the fix based on your recommendation.

bebo-dot-dev commented 2 years ago

After reflection I decided that this issue was a bug and applied https://github.com/bebo-dot-dev/m3u-epg-editor/commit/579c8909e026441fb346b463f99774d068c25530 as the fix.

Thank you for creating this issue.