Skip to content

Commit

Permalink
Adaptation to plugin structure
Browse files Browse the repository at this point in the history
  • Loading branch information
remzouille committed Dec 7, 2024
1 parent 20ae6bc commit 0a3f16f
Showing 1 changed file with 53 additions and 22 deletions.
75 changes: 53 additions & 22 deletions resources/lib/providers/abstract_orange_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from lib.exceptions import AuthenticationRequired, StreamDataDecodeError, StreamNotIncluded
from lib.providers.abstract_provider import AbstractProvider
from lib.utils.kodi import build_addon_url, get_addon_setting, get_drm, get_global_setting, log, set_addon_setting
from lib.utils.request import request, request_json, to_cookie_string
from lib.utils.request import request, request_json, to_cookie_string, get_random_ua

_PROGRAMS_ENDPOINT = "https://rp-ott-mediation-tv.woopic.com/api-gw/live/v3/applications/STB4PC/programs?period={period}&epgIds=all&mco={mco}"
_CATCHUP_CHANNELS_ENDPOINT = "https://rp-ott-mediation-tv.woopic.com/api-gw/catchup/v4/applications/PC/channels"
Expand All @@ -30,6 +30,7 @@
_STREAM_LOGO_URL = "https://proxymedia.woopic.com/api/v1/images/2090{path}"
_LIVE_HOMEPAGE_URL = "https://chaines-tv.orange.fr/"
_CATCHUP_VIDEO_URL = "https://replay.orange.fr/videos/{stream_id}"
_LOGIN_URL = 'https://login.orange.fr'


class AbstractOrangeProvider(AbstractProvider, ABC):
Expand Down Expand Up @@ -269,30 +270,25 @@ def _retrieve_auth_data(self, auth_url: str, login: str = None, password: str =
tv_token, tv_token_expires, wassup = (provider_session_data.get(k) for k in ("tv_token", "tv_token_expires", "wassup"))

if not tv_token_expires or datetime.utcnow().timestamp() > tv_token_expires:
URL_ROOT = 'https://chaines-tv.orange.fr'
USER_AGENT_FIREFOX = "Mozilla/5.0 (Windows NT 10.0; rv:114.0) Gecko/20100101 Firefox/114.0"
session = Session()
session.headers = {
'User-Agent': USER_AGENT_FIREFOX,
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate, br'
}

if not self._expired_wassup(wassup):
log("Cookie reuse", xbmc.LOGINFO)
response = session.get(URL_ROOT + '/token', cookies={'wassup': wassup})
else:
response = session.get(URL_ROOT + '/token')
if response.status_code != 200:
log('Login required', xbmc.LOGINFO)
self._login(session)
response = session.get(URL_ROOT + '/token')
session.headers['Cookie'] = f'wassup={wassup}'

try:
response = request("GET", f'{_LIVE_HOMEPAGE_URL}token', s=session)
except:
log('Login required', xbmc.LOGINFO)
self._login(session)
response = request("GET", f'{_LIVE_HOMEPAGE_URL}token', s=session)

tv_token = response.json()
tv_token_expires = datetime.utcnow().timestamp() + 30 * 60

if 'wassup' in session.cookies:
wassup = session.cookies.get('wassup')

provider_session_data = {
"tv_token": tv_token,
"tv_token_expires": tv_token_expires,
Expand All @@ -313,13 +309,48 @@ def _expired_wassup(self, wassup):
except:
return True

def _login(self, session) -> dict:
"""Login to Orange and return session cookie."""
URL_LOGIN = 'https://login.orange.fr'
def _login(self, session):
"""Login to Orange"""
login, password = get_addon_setting("provider.username"), get_addon_setting("provider.password")
session.get(URL_LOGIN)
session.post(URL_LOGIN + '/api/login', data={'login': login, 'params': {}})
session.post(URL_LOGIN + '/api/password', json={'password': password, 'remember': True})
session.headers = {
'User-Agent': get_random_ua(),
'Accept': 'application/xhtml+xml,application/xml',
"Accept-Encoding": "gzip, deflate, br",
}

session.get(_LOGIN_URL)
session.post(f'{_LOGIN_URL}/api/login', data={'login': login, 'params': {}})
session.post(f'{_LOGIN_URL}/api/password', json={'password': password, 'remember': True})

# try:
# res = request("GET", _LOGIN_URL, headers=session.headers, s=session)
# except RequestException:
# log("Error while authenticating (init)", xbmc.LOGWARNING)
# return

# try:
# res = request(
# "POST",
# f"{_LOGIN_URL}/api/login",
# headers = session.headers,
# data=json.dumps({'login': login, 'params': {}}),
# s=session,
# )
# except RequestException:
# log("Error while authenticating (login)", xbmc.LOGWARNING)
# return

# session.headers["Content-Type"] = "application/json"
# try:
# res = request(
# "POST",
# f"{_LOGIN_URL}/api/password",
# headers = session.headers,
# data=json.dumps({'password': password, 'remember': True}),
# s=session,
# )
# except RequestException:
# log("Error while authenticating (password)", xbmc.LOGWARNING)

def _extract_logo(self, logos: list, definition_type: str = "mobileAppliDark") -> str:
for logo in logos:
Expand Down

0 comments on commit 0a3f16f

Please sign in to comment.