Fix Python <3.11 incompatibility bug (#306)
datetime.UTC is not supported on Python <3.11. Signed-off-by: rany <rany2@riseup.net>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"""This module contains functions for generating the Sec-MS-GEC and Sec-MS-GEC-Version tokens."""
|
"""This module contains functions for generating the Sec-MS-GEC and Sec-MS-GEC-Version tokens."""
|
||||||
|
|
||||||
import datetime
|
from datetime import datetime, timezone
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from .constants import CHROMIUM_FULL_VERSION, TRUSTED_CLIENT_TOKEN
|
from .constants import CHROMIUM_FULL_VERSION, TRUSTED_CLIENT_TOKEN
|
||||||
@@ -12,9 +12,7 @@ def generate_sec_ms_gec_token() -> str:
|
|||||||
See: https://github.com/rany2/edge-tts/issues/290#issuecomment-2464956570"""
|
See: https://github.com/rany2/edge-tts/issues/290#issuecomment-2464956570"""
|
||||||
|
|
||||||
# Get the current time in Windows file time format (100ns intervals since 1601-01-01)
|
# Get the current time in Windows file time format (100ns intervals since 1601-01-01)
|
||||||
ticks = int(
|
ticks = int((datetime.now(timezone.utc).timestamp() + 11644473600) * 10000000)
|
||||||
(datetime.datetime.now(datetime.UTC).timestamp() + 11644473600) * 10000000
|
|
||||||
)
|
|
||||||
|
|
||||||
# Round down to the nearest 5 minutes (3,000,000,000 * 100ns = 5 minutes)
|
# Round down to the nearest 5 minutes (3,000,000,000 * 100ns = 5 minutes)
|
||||||
ticks -= ticks % 3_000_000_000
|
ticks -= ticks % 3_000_000_000
|
||||||
@@ -22,12 +20,8 @@ def generate_sec_ms_gec_token() -> str:
|
|||||||
# Create the string to hash by concatenating the ticks and the trusted client token
|
# Create the string to hash by concatenating the ticks and the trusted client token
|
||||||
str_to_hash = f"{ticks}{TRUSTED_CLIENT_TOKEN}"
|
str_to_hash = f"{ticks}{TRUSTED_CLIENT_TOKEN}"
|
||||||
|
|
||||||
# Compute the SHA256 hash
|
# Compute the SHA256 hash and return the uppercased hex digest
|
||||||
hash_object = hashlib.sha256(str_to_hash.encode("ascii"))
|
return hashlib.sha256(str_to_hash.encode("ascii")).hexdigest().upper()
|
||||||
hex_dig = hash_object.hexdigest()
|
|
||||||
|
|
||||||
# Return the hexadecimal representation of the hash
|
|
||||||
return hex_dig.upper()
|
|
||||||
|
|
||||||
|
|
||||||
def generate_sec_ms_gec_version() -> str:
|
def generate_sec_ms_gec_version() -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user