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

Source code #2

Closed
albinmedoc opened this issue Jun 11, 2024 · 2 comments
Closed

Source code #2

albinmedoc opened this issue Jun 11, 2024 · 2 comments

Comments

@albinmedoc
Copy link

Where is the source code?

@Xaque8787
Copy link
Owner

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
Copy link
Author

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"
}

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

No branches or pull requests

2 participants