diff --git a/m3u8/parser.py b/m3u8/parser.py index 3f511e3c..55e56e6b 100644 --- a/m3u8/parser.py +++ b/m3u8/parser.py @@ -3,12 +3,17 @@ # Use of this source code is governed by a MIT License # license that can be found in the LICENSE file. -import datetime import itertools import re +from datetime import datetime, timedelta from urllib.parse import urljoin as _urljoin -import iso8601 +try: + from backports.datetime_fromisoformat import MonkeyPatch + MonkeyPatch.patch_fromisoformat() +except ImportError: + pass + from m3u8 import protocol @@ -20,7 +25,7 @@ def cast_date_time(value): - return iso8601.parse_date(value) + return datetime.fromisoformat(value) def format_date_time(value, **kwargs): @@ -287,7 +292,7 @@ def _parse_ts_chunk(line, data, state): segment["program_date_time"] = state.pop("program_date_time") if state.get("current_program_date_time"): segment["current_program_date_time"] = state["current_program_date_time"] - state["current_program_date_time"] += datetime.timedelta( + state["current_program_date_time"] += timedelta( seconds=segment["duration"] ) segment["uri"] = line @@ -575,7 +580,7 @@ def _parse_part(line, data, state): # this should always be true according to spec if state.get("current_program_date_time"): part["program_date_time"] = state["current_program_date_time"] - state["current_program_date_time"] += datetime.timedelta( + state["current_program_date_time"] += timedelta( seconds=part["duration"] ) diff --git a/requirements.txt b/requirements.txt index 57c80f08..c785d132 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -iso8601 +backports-datetime-fromisoformat; python_version < '3.11' diff --git a/setup.py b/setup.py index d9a95375..f1c01d4a 100644 --- a/setup.py +++ b/setup.py @@ -23,5 +23,5 @@ url="https://github.com/globocom/m3u8", description="Python m3u8 parser", long_description=long_description, - python_requires=">=3.6", + python_requires=">=3.7", )