Giter Club home page Giter Club logo

m3uparser's People

Contributors

xaque8787 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

m3uparser's Issues

NameError: name 'filepath' is not defined

Hi,

I have an issue with parsing my file

Processing line: #EXTINF:-1 tvg-id="#.No.Channel.#" tvg-name="✺ FR ⋆ GENERALE FHD ✺" tvg-logo="http://lg.mygolden.xyz:8080/logo/EUROPE/FRANCE/flag_france.png" group-title="FR ❖ GENERALE",✺ FR ⋆ GENERALE FHD ✺
Processing line: http://maxprime.xyz:80/Y27P36K66B57Z3/B2MR6VBCL5L7HQNJ/2586
Traceback (most recent call last):
File "/usr/src/app/parser.py", line 115, in
with open(filepath, "w") as f:
NameError: name 'filepath' is not defined

Could you suggest what could be the issue?

BR
Cris

Problem retrieving attributes

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

Originally posted by @albinmedoc in #2 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.