openm3u8 7.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
openm3u8-7.0.0/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ openm3u8 is licensed under the MIT License:
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2012 globo.com webmedia@corp.globo.com
6
+
7
+ Modifications Copyright (c) 2026 Wurl (solutions@wurl.com)
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,122 @@
1
+ Metadata-Version: 2.4
2
+ Name: openm3u8
3
+ Version: 7.0.0
4
+ Summary: Python m3u8 parser
5
+ Author: wurl.com
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/openwurl/openm3u8
8
+ Project-URL: Repository, https://github.com/openwurl/openm3u8
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: backports-datetime-fromisoformat; python_version < "3.11"
17
+ Provides-Extra: dev
18
+ Requires-Dist: bottle; extra == "dev"
19
+ Requires-Dist: pytest>=9.0.1; extra == "dev"
20
+ Requires-Dist: pytest-cov>=7.0.0; extra == "dev"
21
+ Dynamic: license-file
22
+
23
+ # openm3u8
24
+
25
+ `openm3u8` is a Python library for parsing .m3u8 files, which are used as [HTTP Live Streaming (HLS)](https://tools.ietf.org/html/rfc8216) playlists.
26
+
27
+ This project is a fork of [m3u8](https://github.com/globocom/m3u8/) and is maintained by [Wurl](https://www.wurl.com/).
28
+
29
+ # Documentation
30
+
31
+ ## Loading a playlist
32
+
33
+ To load a playlist into an object from uri, file path or directly from
34
+ string, use the `load/loads` functions:
35
+
36
+ ```python
37
+ import openm3u8
38
+
39
+ playlist = openm3u8.load('http://videoserver.com/playlist.m3u8') # this could also be an absolute filename
40
+ print(playlist.segments)
41
+ print(playlist.target_duration)
42
+
43
+ # if you already have the content as string, use
44
+
45
+ playlist = openm3u8.loads('#EXTM3U8 ... etc ... ')
46
+ ```
47
+
48
+ ## Dumping a playlist
49
+
50
+ To dump a playlist from an object to the console or a file, use the
51
+ `dump/dumps` functions:
52
+
53
+ ``` python
54
+ import openm3u8
55
+
56
+ playlist = openm3u8.load('http://videoserver.com/playlist.m3u8')
57
+ print(playlist.dumps())
58
+
59
+ # if you want to write a file from its content
60
+
61
+ playlist.dump('playlist.m3u8')
62
+ ```
63
+
64
+ # Supported tags
65
+
66
+ - [\#EXT-X-TARGETDURATION](https://tools.ietf.org/html/rfc8216#section-4.3.3.1)
67
+ - [\#EXT-X-MEDIA-SEQUENCE](https://tools.ietf.org/html/rfc8216#section-4.3.3.2)
68
+ - [\#EXT-X-DISCONTINUITY-SEQUENCE](https://tools.ietf.org/html/rfc8216#section-4.3.3.3)
69
+ - [\#EXT-X-PROGRAM-DATE-TIME](https://tools.ietf.org/html/rfc8216#section-4.3.2.6)
70
+ - [\#EXT-X-MEDIA](https://tools.ietf.org/html/rfc8216#section-4.3.4.1)
71
+ - [\#EXT-X-PLAYLIST-TYPE](https://tools.ietf.org/html/rfc8216#section-4.3.3.5)
72
+ - [\#EXT-X-KEY](https://tools.ietf.org/html/rfc8216#section-4.3.2.4)
73
+ - [\#EXT-X-STREAM-INF](https://tools.ietf.org/html/rfc8216#section-4.3.4.2)
74
+ - [\#EXT-X-VERSION](https://tools.ietf.org/html/rfc8216#section-4.3.1.2)
75
+ - [\#EXT-X-ALLOW-CACHE](https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-07#section-3.3.6)
76
+ - [\#EXT-X-ENDLIST](https://tools.ietf.org/html/rfc8216#section-4.3.3.4)
77
+ - [\#EXTINF](https://tools.ietf.org/html/rfc8216#section-4.3.2.1)
78
+ - [\#EXT-X-I-FRAMES-ONLY](https://tools.ietf.org/html/rfc8216#section-4.3.3.6)
79
+ - [\#EXT-X-BITRATE](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.4.8)
80
+ - [\#EXT-X-BYTERANGE](https://tools.ietf.org/html/rfc8216#section-4.3.2.2)
81
+ - [\#EXT-X-I-FRAME-STREAM-INF](https://tools.ietf.org/html/rfc8216#section-4.3.4.3)
82
+ - [\#EXT-X-IMAGES-ONLY](https://github.com/image-media-playlist/spec/blob/master/image_media_playlist_v0_4.pdf)
83
+ - [\#EXT-X-IMAGE-STREAM-INF](https://github.com/image-media-playlist/spec/blob/master/image_media_playlist_v0_4.pdf)
84
+ - [\#EXT-X-TILES](https://github.com/image-media-playlist/spec/blob/master/image_media_playlist_v0_4.pdf)
85
+ - [\#EXT-X-DISCONTINUITY](https://tools.ietf.org/html/rfc8216#section-4.3.2.3)
86
+ - \#EXT-X-CUE-OUT
87
+ - \#EXT-X-CUE-OUT-CONT
88
+ - \#EXT-X-CUE-IN
89
+ - \#EXT-X-CUE-SPAN
90
+ - \#EXT-OATCLS-SCTE35
91
+ - [\#EXT-X-INDEPENDENT-SEGMENTS](https://tools.ietf.org/html/rfc8216#section-4.3.5.1)
92
+ - [\#EXT-X-MAP](https://tools.ietf.org/html/rfc8216#section-4.3.2.5)
93
+ - [\#EXT-X-START](https://tools.ietf.org/html/rfc8216#section-4.3.5.2)
94
+ - [\#EXT-X-SERVER-CONTROL](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.3.8)
95
+ - [\#EXT-X-PART-INF](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.3.7)
96
+ - [\#EXT-X-PART](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.4.9)
97
+ - [\#EXT-X-RENDITION-REPORT](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.5.4)
98
+ - [\#EXT-X-SKIP](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.5.2)
99
+ - [\#EXT-X-SESSION-DATA](https://tools.ietf.org/html/rfc8216#section-4.3.4.4)
100
+ - [\#EXT-X-PRELOAD-HINT](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-09#section-4.4.5.3)
101
+ - [\#EXT-X-SESSION-KEY](https://tools.ietf.org/html/rfc8216#section-4.3.4.5)
102
+ - [\#EXT-X-DATERANGE](https://tools.ietf.org/html/rfc8216#section-4.3.2.7)
103
+ - [\#EXT-X-GAP](https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-05#section-4.4.2.7)
104
+ - [\#EXT-X-CONTENT-STEERING](https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-10#section-4.4.6.64)
105
+
106
+ # Running Tests
107
+
108
+ ``` bash
109
+ $ ./runtests
110
+ ```
111
+
112
+ # Contributing
113
+
114
+ All contributions are welcome, but we will merge a pull request if, and
115
+ only if, it
116
+
117
+ - Has tests
118
+ - Follows the code conventions
119
+
120
+ If you plan to implement a new feature or something that will take more
121
+ than a few minutes, please open an issue to make sure we don't work on
122
+ the same thing.
@@ -0,0 +1,100 @@
1
+ # openm3u8
2
+
3
+ `openm3u8` is a Python library for parsing .m3u8 files, which are used as [HTTP Live Streaming (HLS)](https://tools.ietf.org/html/rfc8216) playlists.
4
+
5
+ This project is a fork of [m3u8](https://github.com/globocom/m3u8/) and is maintained by [Wurl](https://www.wurl.com/).
6
+
7
+ # Documentation
8
+
9
+ ## Loading a playlist
10
+
11
+ To load a playlist into an object from uri, file path or directly from
12
+ string, use the `load/loads` functions:
13
+
14
+ ```python
15
+ import openm3u8
16
+
17
+ playlist = openm3u8.load('http://videoserver.com/playlist.m3u8') # this could also be an absolute filename
18
+ print(playlist.segments)
19
+ print(playlist.target_duration)
20
+
21
+ # if you already have the content as string, use
22
+
23
+ playlist = openm3u8.loads('#EXTM3U8 ... etc ... ')
24
+ ```
25
+
26
+ ## Dumping a playlist
27
+
28
+ To dump a playlist from an object to the console or a file, use the
29
+ `dump/dumps` functions:
30
+
31
+ ``` python
32
+ import openm3u8
33
+
34
+ playlist = openm3u8.load('http://videoserver.com/playlist.m3u8')
35
+ print(playlist.dumps())
36
+
37
+ # if you want to write a file from its content
38
+
39
+ playlist.dump('playlist.m3u8')
40
+ ```
41
+
42
+ # Supported tags
43
+
44
+ - [\#EXT-X-TARGETDURATION](https://tools.ietf.org/html/rfc8216#section-4.3.3.1)
45
+ - [\#EXT-X-MEDIA-SEQUENCE](https://tools.ietf.org/html/rfc8216#section-4.3.3.2)
46
+ - [\#EXT-X-DISCONTINUITY-SEQUENCE](https://tools.ietf.org/html/rfc8216#section-4.3.3.3)
47
+ - [\#EXT-X-PROGRAM-DATE-TIME](https://tools.ietf.org/html/rfc8216#section-4.3.2.6)
48
+ - [\#EXT-X-MEDIA](https://tools.ietf.org/html/rfc8216#section-4.3.4.1)
49
+ - [\#EXT-X-PLAYLIST-TYPE](https://tools.ietf.org/html/rfc8216#section-4.3.3.5)
50
+ - [\#EXT-X-KEY](https://tools.ietf.org/html/rfc8216#section-4.3.2.4)
51
+ - [\#EXT-X-STREAM-INF](https://tools.ietf.org/html/rfc8216#section-4.3.4.2)
52
+ - [\#EXT-X-VERSION](https://tools.ietf.org/html/rfc8216#section-4.3.1.2)
53
+ - [\#EXT-X-ALLOW-CACHE](https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-07#section-3.3.6)
54
+ - [\#EXT-X-ENDLIST](https://tools.ietf.org/html/rfc8216#section-4.3.3.4)
55
+ - [\#EXTINF](https://tools.ietf.org/html/rfc8216#section-4.3.2.1)
56
+ - [\#EXT-X-I-FRAMES-ONLY](https://tools.ietf.org/html/rfc8216#section-4.3.3.6)
57
+ - [\#EXT-X-BITRATE](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.4.8)
58
+ - [\#EXT-X-BYTERANGE](https://tools.ietf.org/html/rfc8216#section-4.3.2.2)
59
+ - [\#EXT-X-I-FRAME-STREAM-INF](https://tools.ietf.org/html/rfc8216#section-4.3.4.3)
60
+ - [\#EXT-X-IMAGES-ONLY](https://github.com/image-media-playlist/spec/blob/master/image_media_playlist_v0_4.pdf)
61
+ - [\#EXT-X-IMAGE-STREAM-INF](https://github.com/image-media-playlist/spec/blob/master/image_media_playlist_v0_4.pdf)
62
+ - [\#EXT-X-TILES](https://github.com/image-media-playlist/spec/blob/master/image_media_playlist_v0_4.pdf)
63
+ - [\#EXT-X-DISCONTINUITY](https://tools.ietf.org/html/rfc8216#section-4.3.2.3)
64
+ - \#EXT-X-CUE-OUT
65
+ - \#EXT-X-CUE-OUT-CONT
66
+ - \#EXT-X-CUE-IN
67
+ - \#EXT-X-CUE-SPAN
68
+ - \#EXT-OATCLS-SCTE35
69
+ - [\#EXT-X-INDEPENDENT-SEGMENTS](https://tools.ietf.org/html/rfc8216#section-4.3.5.1)
70
+ - [\#EXT-X-MAP](https://tools.ietf.org/html/rfc8216#section-4.3.2.5)
71
+ - [\#EXT-X-START](https://tools.ietf.org/html/rfc8216#section-4.3.5.2)
72
+ - [\#EXT-X-SERVER-CONTROL](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.3.8)
73
+ - [\#EXT-X-PART-INF](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.3.7)
74
+ - [\#EXT-X-PART](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.4.9)
75
+ - [\#EXT-X-RENDITION-REPORT](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.5.4)
76
+ - [\#EXT-X-SKIP](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.5.2)
77
+ - [\#EXT-X-SESSION-DATA](https://tools.ietf.org/html/rfc8216#section-4.3.4.4)
78
+ - [\#EXT-X-PRELOAD-HINT](https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-09#section-4.4.5.3)
79
+ - [\#EXT-X-SESSION-KEY](https://tools.ietf.org/html/rfc8216#section-4.3.4.5)
80
+ - [\#EXT-X-DATERANGE](https://tools.ietf.org/html/rfc8216#section-4.3.2.7)
81
+ - [\#EXT-X-GAP](https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-05#section-4.4.2.7)
82
+ - [\#EXT-X-CONTENT-STEERING](https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-10#section-4.4.6.64)
83
+
84
+ # Running Tests
85
+
86
+ ``` bash
87
+ $ ./runtests
88
+ ```
89
+
90
+ # Contributing
91
+
92
+ All contributions are welcome, but we will merge a pull request if, and
93
+ only if, it
94
+
95
+ - Has tests
96
+ - Follows the code conventions
97
+
98
+ If you plan to implement a new feature or something that will take more
99
+ than a few minutes, please open an issue to make sure we don't work on
100
+ the same thing.
@@ -0,0 +1,113 @@
1
+ # Copyright 2014 Globo.com Player authors. All rights reserved.
2
+ # Modifications Copyright (c) 2026 Wurl.
3
+ # Use of this source code is governed by a MIT License
4
+ # license that can be found in the LICENSE file.
5
+
6
+ import os
7
+ from urllib.parse import urljoin, urlsplit
8
+
9
+ from openm3u8.httpclient import DefaultHTTPClient
10
+ from openm3u8.model import (
11
+ M3U8,
12
+ ContentSteering,
13
+ DateRange,
14
+ DateRangeList,
15
+ IFramePlaylist,
16
+ ImagePlaylist,
17
+ Key,
18
+ Media,
19
+ MediaList,
20
+ PartialSegment,
21
+ PartialSegmentList,
22
+ PartInformation,
23
+ Playlist,
24
+ PlaylistList,
25
+ PreloadHint,
26
+ RenditionReport,
27
+ RenditionReportList,
28
+ Segment,
29
+ SegmentList,
30
+ ServerControl,
31
+ Skip,
32
+ Start,
33
+ Tiles,
34
+ )
35
+ from openm3u8.parser import parse, ParseError
36
+
37
+ # Try to import the C extension for faster parsing, fall back to Python
38
+ if os.environ.get("M3U8_NO_C_EXTENSION", "") != "1":
39
+ try:
40
+ from openm3u8._m3u8_parser import parse
41
+ except ImportError:
42
+ pass
43
+
44
+ __all__ = (
45
+ "M3U8",
46
+ "Segment",
47
+ "SegmentList",
48
+ "PartialSegment",
49
+ "PartialSegmentList",
50
+ "Key",
51
+ "Playlist",
52
+ "IFramePlaylist",
53
+ "Media",
54
+ "MediaList",
55
+ "PlaylistList",
56
+ "Start",
57
+ "RenditionReport",
58
+ "RenditionReportList",
59
+ "ServerControl",
60
+ "Skip",
61
+ "PartInformation",
62
+ "PreloadHint",
63
+ "DateRange",
64
+ "DateRangeList",
65
+ "ContentSteering",
66
+ "ImagePlaylist",
67
+ "Tiles",
68
+ "loads",
69
+ "load",
70
+ "parse",
71
+ "ParseError",
72
+ )
73
+
74
+
75
+ def loads(content, uri=None, custom_tags_parser=None):
76
+ """
77
+ Given a string with a m3u8 content, returns a M3U8 object.
78
+ Optionally parses a uri to set a correct base_uri on the M3U8 object.
79
+ Raises ValueError if invalid content
80
+ """
81
+
82
+ if uri is None:
83
+ return M3U8(content, custom_tags_parser=custom_tags_parser)
84
+ else:
85
+ base_uri = urljoin(uri, ".")
86
+ return M3U8(content, base_uri=base_uri, custom_tags_parser=custom_tags_parser)
87
+
88
+
89
+ def load(
90
+ uri,
91
+ timeout=None,
92
+ headers={},
93
+ custom_tags_parser=None,
94
+ http_client=DefaultHTTPClient(),
95
+ verify_ssl=True,
96
+ ):
97
+ """
98
+ Retrieves the content from a given URI and returns a M3U8 object.
99
+ Raises ValueError if invalid content or IOError if request fails.
100
+ """
101
+ base_uri_parts = urlsplit(uri)
102
+ if base_uri_parts.scheme and base_uri_parts.netloc:
103
+ content, base_uri = http_client.download(uri, timeout, headers, verify_ssl)
104
+ return M3U8(content, base_uri=base_uri, custom_tags_parser=custom_tags_parser)
105
+ else:
106
+ return _load_from_file(uri, custom_tags_parser)
107
+
108
+
109
+ def _load_from_file(uri, custom_tags_parser=None):
110
+ with open(uri, encoding="utf8") as fileobj:
111
+ raw_content = fileobj.read().strip()
112
+ base_uri = os.path.dirname(uri)
113
+ return M3U8(raw_content, base_uri=base_uri, custom_tags_parser=custom_tags_parser)