Reuses compiled regex, fixes #10, and flexible m3u generation #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
By reusing the regexes, we avoid recompiling them for each stream item being processed, and also they now are next to the other regexes defined in the
M3uParser
class.I added extra flexibility when parsing the M3U, now the only field that is always stored is the
url
(which is always present). All the other fields are only stored if they were present in the original m3u. Also, if the field was defined as an empty string (eg.:#EXTINF:-1 tvg-id="", Google
), it is stored as an empty string.Also, I changed the way of generating the M3U to avoid concatenating big strings in the memory, which usually consumes large portions of memory and slows down when the string gets big (I'm processing M3U files of several megabytes). Using a list avoids these issues, since the big string is only generated at the end of the processing.
This way, when generating JSON and M3U it only generates the fields that were originally present in the parsed M3U.
For example, with this input:
Now using
parse_m3u
andto_file( ... , 'm3u')
the generated file is exactly the same as the original (parsed) M3U.Related to #7 and #10