pawanpaudel93 / m3u-parser

A parser for m3u files. It parses the contents of the m3u file to a list of streams information which can be saved as a JSON/CSV/M3U file.
MIT License
30 stars 16 forks source link

Removing part of the title when it contains comma #12

Closed dineiar closed 2 years ago

dineiar commented 2 years ago

When the name of the entry in the M3U contains a comma, M3uParser only gets the last part of the name. Sample M3U:

#EXTM3U
#EXTINF:-1 tvg-name="John Doe, The gunslinger" group-title="Doe Family", Doe, John
https://johndoe.net/

Using parse_m3u and to_file('json') outputs:

[
    {
        "name": "John",
        "url": "https://johndoe.net/",
        "category": "Doe Family",
        "tvg": {
            "name": "John Doe, The gunslinger"
        },
        "status": "GOOD"
    }
]

The "name" field should be Doe, John, but it is only John.

Also, to_file('m3u') outputs:

#EXTM3U
#EXTINF:-1 tvg-name="John Doe, The gunslinger" group-title="Doe Family", John
https://johndoe.net/

The issue is the parsing of the title, which I'm still not entirely sure how to fix.

pawanpaudel93 commented 2 years ago

@dineiar I have tried fixing it. Can you try and give feedback and also parse_m3u method will take trim=True/False so by default trim is False but if you pass trim=True while generating json the empty values will be removed. I have kept this so that we can get desired output. And saving to m3u only saves info present on the original m3u file only.

dineiar commented 2 years ago

@pawanpaudel93, it looks great. I made some tests and it seems to be working great. I made some comments on your commit to some points that I think could be improved.

I've also renamed the trim parameter that you created to enforce_schema in PR #13. Merge it if you agree with me.
Also, I believe that the default value for this parameter should be False (ignoring non-existing fields by default), because that is what I would expect a library to do (keep the processed file as close as possible to the original), but I kept it True according to your implementation of the trim parameter.