Skip to content

Commit 0966dfb

Browse files
added dynamic totp secret and version fetching
1 parent 2e96a52 commit 0966dfb

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def read_file(fname):
1717

1818
setup(
1919
name=pkg_name,
20-
version="0.1.2.3",
20+
version="0.1.2.4",
2121
author="Akash R Chandran",
2222
author_email="chandranrakash@gmail.com",
2323
description="A command line tool to fetch lyrics from spotify and save it to lrc file. It can fetch both synced and unsynced lyrics from spotify. ",

syrics/totp.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import hashlib
22
import hmac
33
import math
4+
import requests
45

56
# thanks to https://github.com/glomatico/votify/blob/main/votify/totp.py
67
class TOTP:
78
def __init__(self) -> None:
8-
self.secret = b"46765510475331268151846763111112875241781186186871271119692"
9-
self.version = 17
9+
self.secret, self.version = self.get_secret_version()
1010
self.period = 30
1111
self.digits = 6
1212

@@ -25,4 +25,14 @@ def generate(self, timestamp: int) -> str:
2525
| (hmac_result[offset + 3] & 0xFF)
2626
)
2727

28-
return str(binary % (10**self.digits)).zfill(self.digits)
28+
return str(binary % (10**self.digits)).zfill(self.digits)
29+
30+
def get_secret_version(self) -> tuple[str, int]:
31+
req = requests.get("https://raw.githubusercontent.com/Thereallo1026/spotify-secrets/refs/heads/main/secrets/secrets.json")
32+
if req.status_code != 200:
33+
raise ValueError("Failed to fetch TOTP secret and version.")
34+
data = req.json()[-1]
35+
ascii_codes = [ord(c) for c in data['secret']]
36+
transformed = [val ^ ((i % 33) + 9) for i, val in enumerate(ascii_codes)]
37+
secret_key = "".join(str(num) for num in transformed)
38+
return bytes(secret_key, 'utf-8'), data['version']

0 commit comments

Comments
 (0)