openm3u8 7.0.0__cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
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/__init__.py +113 -0
- openm3u8/_m3u8_parser.abi3.so +0 -0
- openm3u8/_m3u8_parser.c +3122 -0
- openm3u8/httpclient.py +36 -0
- openm3u8/mixins.py +52 -0
- openm3u8/model.py +1694 -0
- openm3u8/parser.py +786 -0
- openm3u8/protocol.py +47 -0
- openm3u8/version_matching.py +37 -0
- openm3u8/version_matching_rules.py +108 -0
- openm3u8-7.0.0.dist-info/METADATA +122 -0
- openm3u8-7.0.0.dist-info/RECORD +15 -0
- openm3u8-7.0.0.dist-info/WHEEL +6 -0
- openm3u8-7.0.0.dist-info/licenses/LICENSE +13 -0
- openm3u8-7.0.0.dist-info/top_level.txt +1 -0
openm3u8/__init__.py
ADDED
|
@@ -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)
|
|
Binary file
|