globocom / m3u8

Python m3u8 Parser for HTTP Live Streaming (HLS) Transmissions
Other
1.98k stars 464 forks source link

Wrongfully parsing custom tag as URI instead of ignoring it #326

Closed MrChick closed 10 months ago

MrChick commented 10 months ago

The readme states the following:

Quoting the documentation:

Lines that start with the character '#' are either comments or tags. Tags begin with #EXT. They are case-sensitive. All other lines that begin with '#' are comments and SHOULD be ignored.

This library ignores all the non-standard tags by default.

I have a m3u file from my cable router (DVBC streaming) using the following format:

EXTM3U

EXTINF:0,Channel 1

EXTVLCOPT:network-caching=1000

rtsp://192.168.[...]

EXTINF:0,Channel 2

EXTVLCOPT:network-caching=1000

rtsp://192.168.[...]

EXTINF:0,Channel 3

EXTVLCOPT:network-caching=1000

rtsp://192.168.[...]

It looks like parser.py expects any line following an EXTINF that is not a handled tag to be the actual URI no matter what.

I was expecting the EXTVLCOPT tags to simply be ignored, but instead after parsing the m3u file I get the channels correctly as titles, but instead of the rtsp URIs i get the EXTVLCOPT lines returned as URI.

I managed to easily remedy this by using a custom tag parser, but it sounds to me like the EXTVLCOPT tag should have been ignored out of the box?

bbayles commented 10 months ago

I think PR #327 will fix this.

In [1]: from m3u8 import loads

In [2]: playlist_text = """#EXTM3U
   ...: #EXTINF:0,Channel 1
   ...: #EXTVLCOPT:network-caching=1000
   ...: rtsp://192.168.[...]
   ...: #EXTINF:0,Channel 2
   ...: #EXTVLCOPT:network-caching=1000
   ...: rtsp://192.168.[...]
   ...: #EXTINF:0,Channel 3
   ...: #EXTVLCOPT:network-caching=1000
   ...: rtsp://192.168.[...]"""

In [3]:

In [3]: parsed_playlist = loads(playlist_text, uri="https://localhost:24601/hls/playlist.m3u8")

In [4]: parsed_playlist.data
Out[4]:
{'media_sequence': 0,
 'is_variant': False,
 'is_endlist': False,
 'is_i_frames_only': False,
 'is_independent_segments': False,
 'is_images_only': False,
 'playlist_type': None,
 'playlists': [],
 'segments': [{'duration': 0.0,
   'title': 'Channel 1',
   'uri': 'rtsp://192.168.[...]',
   'cue_in': False,
   'cue_out': False,
   'cue_out_start': False,
   'scte35': None,
   'oatcls_scte35': None,
   'scte35_duration': None,
   'scte35_elapsedtime': None,
   'asset_metadata': None,
   'discontinuity': False,
   'dateranges': None,
   'gap_tag': None},
  {'duration': 0.0,
   'title': 'Channel 2',
   'uri': 'rtsp://192.168.[...]',
   'cue_in': False,
   'cue_out': False,
   'cue_out_start': False,
   'scte35': None,
   'oatcls_scte35': None,
   'scte35_duration': None,
   'scte35_elapsedtime': None,
   'asset_metadata': None,
   'discontinuity': False,
   'dateranges': None,
   'gap_tag': None},
  {'duration': 0.0,
   'title': 'Channel 3',
   'uri': 'rtsp://192.168.[...]',
   'cue_in': False,
   'cue_out': False,
   'cue_out_start': False,
   'scte35': None,
   'oatcls_scte35': None,
   'scte35_duration': None,
   'scte35_elapsedtime': None,
   'asset_metadata': None,
   'discontinuity': False,
   'dateranges': None,
   'gap_tag': None}],
 'iframe_playlists': [],
 'image_playlists': [],
 'tiles': [],
 'media': [],
 'keys': [None],
 'rendition_reports': [],
 'skip': {},
 'part_inf': {},
 'session_data': [],
 'session_keys': [],
 'segment_map': []}
mauricioabreu commented 10 months ago

@MrChick could you test using the master version while we don't release a new version?

MrChick commented 10 months ago

@mauricioabreu can confirm, it now works as expected and I get the actual URI of the stream instead of the EXTVLCOPTS tag.

mauricioabreu commented 10 months ago

New release has just launched