Xaque8787 / m3uparser

Parse your m3u VOD list and make a .strm library for media server
4 stars 0 forks source link

Source code #2

Closed albinmedoc closed 3 weeks ago

albinmedoc commented 3 weeks ago

Where is the source code?

Xaque8787 commented 3 weeks ago

Where is the source code?

It is available now. My apologies, still learning how to properly use git. Future updates should be done in the proper manner with commits, PR and merge, and all that jazz. Currently redoing the parser script to properly handle varying m3u formats, which should then support m3us from more providers.

albinmedoc commented 3 weeks ago

I ran into problems running the code, and I seem to understand why. In current code, tvgroup is assumed to be the first attribute, but this is not always the case. A slightly "kinder" way of retrieving the attribute would be needed.

Wrote up a quick function that can be used to support various m3u formats. Hopefully this can help you. I tried to implement it in the codebase, but I still don't really understand how the current code works.

import re

def extract_key_value_pairs(s):
    # Define the regular expression pattern
    pattern = r'(\w+(?:-\w+)?)="([^"]*)"'

    # Find all matches in the string
    matches = re.findall(pattern, s)

    # Create a dictionary from the matches
    result = {key: value for key, value in matches}

    return result

# Example input string
input_string = '#EXTINF:0 channelID="x-ID.0" tvg-chno="1000" tvg-name="Apan [SE] [2009]" tvg-id="1000" tvg-logo="https://image.tmdb.org/t/p/w600_and_h900_bestv2/bZcK8blLUXjMv2u0Kh7GDl9kT2I.jpg" group-title="VOD: Svenska",Apan [SE] [2009]'

# Extract key-value pairs
result_dict = extract_key_value_pairs(input_string)

# Print the full dict
print(result_dict)

# Print a specific key
print(result_dict["group-title"])

The function returns a dict representing all attributes.

{
   "channelID":"x-ID.0",
   "tvg-chno":"1000",
   "tvg-name":"Apan [SE] [2009]",
   "tvg-id":"1000",
   "tvg-logo":"https://image.tmdb.org/t/p/w600_and_h900_bestv2/bZcK8blLUXjMv2u0Kh7GDl9kT2I.jpg",
   "group-title":"VOD: Svenska"
}