Skip to content

Commit

Permalink
Fix Python <3.11 incompatibility bug
Browse files Browse the repository at this point in the history
datetime.UTC is not supported on Python <3.11.

Signed-off-by: rany <[email protected]>
  • Loading branch information
rany2 committed Nov 9, 2024
1 parent 9652a90 commit bd95fb7
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/edge_tts/drm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""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

from .constants import CHROMIUM_FULL_VERSION, TRUSTED_CLIENT_TOKEN
Expand All @@ -12,22 +12,16 @@ def generate_sec_ms_gec_token() -> str:
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)
ticks = int(
(datetime.datetime.now(datetime.UTC).timestamp() + 11644473600) * 10000000
)
ticks = int((datetime.now(timezone.utc).timestamp() + 11644473600) * 10000000)

# Round down to the nearest 5 minutes (3,000,000,000 * 100ns = 5 minutes)
ticks -= ticks % 3_000_000_000

# Create the string to hash by concatenating the ticks and the trusted client token
str_to_hash = f"{ticks}{TRUSTED_CLIENT_TOKEN}"

# Compute the SHA256 hash
hash_object = hashlib.sha256(str_to_hash.encode("ascii"))
hex_dig = hash_object.hexdigest()

# Return the hexadecimal representation of the hash
return hex_dig.upper()
# Compute the SHA256 hash and return the uppercased hex digest
return hashlib.sha256(str_to_hash.encode("ascii")).hexdigest().upper()


def generate_sec_ms_gec_version() -> str:
Expand Down

0 comments on commit bd95fb7

Please sign in to comment.