Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use built-in ISO 8601 parse for Python 3.11 and later #336

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions m3u8/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -20,7 +25,7 @@


def cast_date_time(value):
return iso8601.parse_date(value)
return datetime.fromisoformat(value)


def format_date_time(value, **kwargs):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
iso8601
backports-datetime-fromisoformat; python_version < '3.11'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Loading