|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | """ |
3 | 3 | Author: Michal Szymanski <misiektoja-github@rm-rf.ninja> |
4 | | -v2.9.1 |
| 4 | +v2.9.2 |
5 | 5 |
|
6 | 6 | Tool implementing real-time tracking of Spotify friends music activity: |
7 | 7 | https://github.com/misiektoja/spotify_monitor/ |
|
17 | 17 | spotipy (required since v2.7 due to new Spotify restrictions introduced on 22 Dec 2025) |
18 | 18 | """ |
19 | 19 |
|
20 | | -VERSION = "2.9.1" |
| 20 | +VERSION = "2.9.2" |
21 | 21 |
|
22 | 22 | # --------------------------- |
23 | 23 | # CONFIGURATION SECTION START |
@@ -1579,16 +1579,24 @@ def fetch_server_time(session: req.Session, ua: str) -> int: |
1579 | 1579 | return int(parsedate_to_datetime(date_hdr).timestamp()) |
1580 | 1580 |
|
1581 | 1581 |
|
| 1582 | +# Resolves the effective TOTP version, falling back to the highest available when the configured TOTP_VER is missing from SECRET_CIPHER_DICT |
| 1583 | +def resolve_totp_ver() -> int: |
| 1584 | + if not SECRET_CIPHER_DICT: |
| 1585 | + raise SecretsUnavailableError("resolve_totp_ver(): SECRET_CIPHER_DICT is empty") |
| 1586 | + if TOTP_VER and str(TOTP_VER) in SECRET_CIPHER_DICT: |
| 1587 | + return TOTP_VER |
| 1588 | + available = sorted(map(int, SECRET_CIPHER_DICT)) |
| 1589 | + fallback = available[-1] |
| 1590 | + if TOTP_VER: |
| 1591 | + print(f"Warning: configured TOTP_VER ({TOTP_VER}) is missing from SECRET_CIPHER_DICT (available: {available}); falling back to auto-selected version {fallback}") |
| 1592 | + return fallback |
| 1593 | + |
| 1594 | + |
1582 | 1595 | # Creates a TOTP object using a secret derived from transformed cipher bytes |
1583 | 1596 | def generate_totp(): |
1584 | 1597 | import pyotp |
1585 | 1598 |
|
1586 | | - if not SECRET_CIPHER_DICT: |
1587 | | - raise SecretsUnavailableError("generate_totp(): SECRET_CIPHER_DICT is empty") |
1588 | | - |
1589 | | - ver = TOTP_VER or max(map(int, SECRET_CIPHER_DICT)) |
1590 | | - if str(ver) not in SECRET_CIPHER_DICT: |
1591 | | - raise SecretsUnavailableError(f"generate_totp(): Defined TOTP_VER ({ver}) is missing in SECRET_CIPHER_DICT") |
| 1599 | + ver = resolve_totp_ver() |
1592 | 1600 |
|
1593 | 1601 | secret_cipher_bytes = SECRET_CIPHER_DICT[str(ver)] |
1594 | 1602 |
|
@@ -1681,7 +1689,7 @@ def refresh_access_token_from_sp_dc(sp_dc: str) -> dict: |
1681 | 1689 | client_time = int(time_ns() / 1000 / 1000) |
1682 | 1690 | otp_value = totp_obj.at(server_time) |
1683 | 1691 |
|
1684 | | - totp_ver = TOTP_VER or max(map(int, SECRET_CIPHER_DICT)) |
| 1692 | + totp_ver = resolve_totp_ver() |
1685 | 1693 |
|
1686 | 1694 | params = { |
1687 | 1695 | "reason": "transport", |
|
0 commit comments