Skip to content

Commit 754632a

Browse files
committed
add Oqee free login
1 parent 3fb78d2 commit 754632a

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

utils/input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def get_date_input():
6565
"type": "input",
6666
"message": "Enter a start date/time (YYYY-MM-DD HH:MM:SS):",
6767
"name": "datetime",
68-
"default": "2025-01-01 12:00:00",
68+
"default": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
6969
"validate": DatetimeValidator(),
7070
"invalid_message": "Invalid date/time format. Use YYYY-MM-DD HH:MM:SS",
7171
}
@@ -100,7 +100,7 @@ def get_date_input():
100100
"default": (
101101
start_date_result["datetime"]
102102
if start_date_result
103-
else "2025-01-01 12:00:00"
103+
else datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
104104
),
105105
"validate": DatetimeValidator(),
106106
"when": lambda answers: answers["input_type"] == "End date/time",

utils/oqee.py

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def __init__(self, username: str, password: str):
5959
self.right_token = None
6060
self.profil_id = None
6161
self.lic_url = "https://license.oqee.net/api/v1/live/license/widevine"
62+
if "fbx" in username.lower():
63+
self.abo = True
64+
else:
65+
self.abo = False
6266

6367
self.configure(username, password)
6468

@@ -124,10 +128,10 @@ def profil(self):
124128
data = self.session.get(
125129
"https://api.oqee.net/api/v2/user/profiles", headers=headers
126130
).json()
127-
logger.info("Selecting first profile by default.")
131+
# logger.info("Selecting first profile by default.")
128132
return data["result"][0]["id"]
129133

130-
def login_cred(self, username, password):
134+
def login_cred_abo(self, username, password):
131135
"""Authenticate with OQEE service using Free account credentials."""
132136
headers = self._build_headers(
133137
overrides={
@@ -209,6 +213,57 @@ def login_cred(self, username, password):
209213
json={"type": "freeoa", "token": token},
210214
).json()
211215
return data["result"]["token"]
216+
217+
218+
def login_cred_free(self, username, password):
219+
"""Authenticate with OQEE service using Free account credentials."""
220+
headers = {
221+
'accept': '*/*',
222+
'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8',
223+
'cache-control': 'no-cache',
224+
'content-type': 'application/json',
225+
'origin': 'https://tv.free.fr',
226+
'pragma': 'no-cache',
227+
'priority': 'u=1, i',
228+
'referer': 'https://tv.free.fr/',
229+
'sec-ch-ua': '"Chromium";v="146", "Not-A.Brand";v="24", "Google Chrome";v="146"',
230+
'sec-ch-ua-mobile': '?0',
231+
'sec-ch-ua-platform': '"macOS"',
232+
'sec-fetch-dest': 'empty',
233+
'sec-fetch-mode': 'cors',
234+
'sec-fetch-site': 'cross-site',
235+
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36',
236+
'x-oqee-customization': '0',
237+
'x-oqee-platform': 'web',
238+
}
239+
240+
data = {"provider":"oqee","platform":"web"}
241+
242+
response = self.session.post('https://api.oqee.net/api/v2/user/oauth/init', headers=headers, json=data).json()
243+
redirect_url = response['result']['redirect_url']
244+
token = parse_qs(urlparse(redirect_url).query)['token'][0]
245+
246+
data = {"email":username,"password":password,"token":token}
247+
response = self.session.post('https://api.oqee.net/api/v1/user/oauthorize', headers=headers, json=data).json()
248+
249+
if not response["success"]:
250+
raise ValueError(
251+
f"Login failed: invalid credentials or error in authentication - {response.get('error', {}).get('msg', 'No error message')}"
252+
)
253+
parsed_url = parse_qs(urlparse(response["result"]["redirect_url"]).query)
254+
if "code" not in parsed_url:
255+
raise ValueError(
256+
"Login failed: invalid credentials or error in authentication - no code in redirect URL"
257+
)
258+
code = parsed_url["code"][0]
259+
260+
data = self.session.post(
261+
"https://api.oqee.net/api/v5/user/login",
262+
headers=headers,
263+
json={"type": "oqeeoa", "token": code},
264+
).json()
265+
return data["result"]["token"]
266+
212267

213268
def login_ip(self):
214269
"""
@@ -231,9 +286,13 @@ def login(self, username, password):
231286
logger.info("No credentials provided, using IP login.")
232287
self.access_token = self.login_ip()
233288
else:
234-
logger.info("Logging in with provided credentials")
235289
try:
236-
self.access_token = self.login_cred(username, password)
290+
if self.abo:
291+
logger.info("Logging in with provided credentials (abo account detected).")
292+
self.access_token = self.login_cred_abo(username, password)
293+
else:
294+
logger.info("Logging in with provided credentials (free account detected).")
295+
self.access_token = self.login_cred_free(username, password)
237296
except ValueError as e:
238297
logger.warning(
239298
"Credential login failed: %s. Falling back to IP login.", e
@@ -242,8 +301,10 @@ def login(self, username, password):
242301

243302
logger.info("Fetching rights token")
244303
self.right_token = self.right()
304+
logger.debug("Rights token obtained: %s", self.right_token[:10] + "..." if self.right_token else "None")
245305
logger.info("Fetching profile ID")
246306
self.profil_id = self.profil()
307+
logger.debug("Profile ID obtained: %s", self.profil_id)
247308

248309
self.headers = self._build_headers(
249310
overrides={

0 commit comments

Comments
 (0)