Skip to content

Commit 9ff1520

Browse files
committed
refactor: inject Trakt API keys using obfuscation
Injects Trakt client ID and secret into the traktapi.py file during the build process.
1 parent 19f70d3 commit 9ff1520

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

.github/workflows/submit.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ jobs:
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v5
16+
- name: Inject Trakt Keys
17+
env:
18+
TRAKT_CLIENT_ID: ${{ secrets.TRAKT_CLIENT_ID }}
19+
TRAKT_CLIENT_SECRET: ${{ secrets.TRAKT_CLIENT_SECRET }}
20+
run: python3 scripts/inject_keys.py
1621
- name: Generate distribution zip and submit to official kodi repository
1722
id: kodi-addon-submitter
1823
uses: xbmc/action-kodi-addon-submitter@v1.3

resources/lib/obfuscation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
3+
def deobfuscate(data):
4+
if not data or not isinstance(data, list):
5+
return ""
6+
return "".join(chr(b ^ 0x42) for b in data)
7+
8+
def obfuscate(data):
9+
if not data:
10+
return []
11+
return [ord(c) ^ 0x42 for c in data]

resources/lib/traktapi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
findSeasonMatchInList,
2121
findShowMatchInList,
2222
)
23+
from resources.lib.obfuscation import deobfuscate
2324
from trakt import Trakt
2425
from trakt.objects import Movie, Show
2526

@@ -31,8 +32,9 @@
3132

3233

3334
class traktAPI(object):
34-
__client_id = "d4161a7a106424551add171e5470112e4afdaf2438e6ef2fe0548edc75924868"
35-
__client_secret = "b5fcd7cb5d9bb963784d11bbf8535bc0d25d46225016191eb48e50792d2155c0"
35+
# Placeholders for build-time injection
36+
__client_id = "TRAKT_CLIENT_ID_PLACEHOLDER"
37+
__client_secret = "TRAKT_CLIENT_SECRET_PLACEHOLDER"
3638

3739
def __init__(self, force=False):
3840
logger.debug("Initializing.")
@@ -43,7 +45,8 @@ def __init__(self, force=False):
4345

4446
# Configure
4547
Trakt.configuration.defaults.client(
46-
id=self.__client_id, secret=self.__client_secret
48+
id=deobfuscate(self.__client_id),
49+
secret=deobfuscate(self.__client_secret),
4750
)
4851

4952
# Bind event

scripts/inject_keys.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import sys
3+
4+
# Add the parent directory to sys.path to allow importing from resources
5+
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
6+
7+
from resources.lib.obfuscation import deobfuscate, obfuscate
8+
9+
def main():
10+
client_id = os.environ.get("TRAKT_CLIENT_ID")
11+
client_secret = os.environ.get("TRAKT_CLIENT_SECRET")
12+
13+
if not client_id or not client_secret:
14+
print("Error: TRAKT_CLIENT_ID or TRAKT_CLIENT_SECRET not set.")
15+
sys.exit(1)
16+
17+
obfuscated_id = obfuscate(client_id)
18+
obfuscated_secret = obfuscate(client_secret)
19+
20+
# Verify logic
21+
assert deobfuscate(obfuscated_id) == client_id
22+
assert deobfuscate(obfuscated_secret) == client_secret
23+
24+
target_file = "resources/lib/traktapi.py"
25+
with open(target_file, "r") as f:
26+
content = f.read()
27+
28+
# Replace placeholders
29+
new_content = content.replace(
30+
'"TRAKT_CLIENT_ID_PLACEHOLDER"',
31+
str(obfuscated_id),
32+
).replace(
33+
'"TRAKT_CLIENT_SECRET_PLACEHOLDER"',
34+
str(obfuscated_secret),
35+
)
36+
37+
if new_content == content:
38+
print("Error: Could not find placeholders in target file.")
39+
sys.exit(1)
40+
41+
with open(target_file, "w") as f:
42+
f.write(new_content)
43+
44+
print(f"Successfully injected obfuscated keys into {target_file}")
45+
46+
if __name__ == "__main__":
47+
main()

0 commit comments

Comments
 (0)