Skip to content

Commit

Permalink
Chaînes et logos codés en dur (pour l'instant)
Browse files Browse the repository at this point in the history
  • Loading branch information
remzouille committed Nov 4, 2023
1 parent 1608ed7 commit baaf50b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
61 changes: 35 additions & 26 deletions resources/lib/provider_templates/orange.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import xbmcvfs

from lib.providers.provider_interface import ProviderInterface
from lib.utils import get_drm, get_global_setting, log, LogLevel, random_ua, get_addon_profile
from lib.utils import get_drm, get_global_setting, log, LogLevel, random_ua, get_addon_profile, get_addon_path

@dataclass
class OrangeTemplate(ProviderInterface):
Expand All @@ -30,6 +30,27 @@ def __init__(
self.endpoint_programs = endpoint_programs
self.groups = groups

def _get_auth(self) -> tuple:
timestamp = datetime.timestamp(datetime.today())
filepath = os.path.join(xbmcvfs.translatePath(get_addon_profile()), 'auth')

req = Request("https://chaines-tv.orange.fr", headers={
'User-Agent': random_ua(),
'Host': 'chaines-tv.orange.fr',
})

with urlopen(req) as res:
nuxt = re.sub('.*<script>window', 'window', str(res.read()), 1)
nuxt = re.sub('</script>.*', '', nuxt, 1)
cookie = res.headers['Set-Cookie'].split(";")[0]
tv_token = re.sub('.*token:"', 'Bearer ', nuxt, 1)
tv_token = re.sub('",claims:.*', '', tv_token, 1)
auth = {'timestamp': timestamp, 'cookie': cookie, 'tv_token': tv_token}
with open(filepath, 'w', encoding='UTF-8') as file:
file.write(json.dumps(auth))

return nuxt, cookie, tv_token

def _auth_urlopen(self, url: str, headers: dict = None) -> tuple:
if headers is None:
headers = {}
Expand Down Expand Up @@ -59,18 +80,7 @@ def _auth_urlopen(self, url: str, headers: dict = None) -> tuple:
log(f"erreur {error}", LogLevel.INFO)
raise

req = Request("https://chaines-tv.orange.fr", headers={
'User-Agent': random_ua(),
'Host': 'chaines-tv.orange.fr',
})

with urlopen(req) as res:
cookie = res.headers['Set-Cookie'].split(";")[0]
tv_token = re.sub('.*token:"', 'Bearer ', str(res.read()), 1)
tv_token = re.sub('",claims:.*', '', tv_token, 1)
auth = {'timestamp': timestamp, 'cookie': cookie, 'tv_token': tv_token}
with open(filepath, 'w', encoding='UTF-8') as file:
file.write(json.dumps(auth))
_, auth['cookie'], auth['tv_token'] = self._get_auth()

return None

Expand Down Expand Up @@ -106,27 +116,26 @@ def get_stream_info(self, channel_id: int) -> dict:
return stream_info

def get_streams(self) -> list:
# pylint: disable=unreachable
return []

res, _, _ = self._auth_urlopen(self.endpoint_streams, headers={
'User-Agent': random_ua(),
'Host': urlparse(self.endpoint_streams).netloc
})

channels = json.loads(res)
filepath = os.path.join(xbmcvfs.translatePath(get_addon_path()), 'channels.json')
with open(filepath, encoding='UTF-8') as file:
channels = json.load(file)

streams = []

for channel in channels:
channel_id: str = channel['id']
channel_id = str(channel['idEPG'])
logourl = None
for logo in channel['logos']:
if logo['definitionType'] == 'webTVSquare':
logourl = logo['listLogos'][0]['path']
break
streams.append({
'id': channel_id,
'name': channel['name'],
'preset': channel['zappingNumber'],
'logo': channel['logos']['square'].replace('%2F/', '%2F') if 'square' in channel['logos'] else None,
'preset': str(channel['displayOrder']),
'logo': logourl,
'stream': f'plugin://plugin.video.orange.fr/channel/{channel_id}',
'group': [group_name for group_name in self.groups if int(channel['id']) in self.groups[group_name]]
'group': [group_name for group_name in self.groups if int(channel_id) in self.groups[group_name]]
})

return streams
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/providers/fr/orange.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class OrangeFranceProvider(OrangeTemplate):
def __init__(self) -> None:
super().__init__(
endpoint_stream_info = 'https://mediation-tv.orange.fr/all/api-gw/live/v3/auth/accountToken/applications/PC/channels/{channel_id}/stream?terminalModel=WEB_PC',
endpoint_streams = 'https://mediation-tv.orange.fr/all/api-gw/live/v3/auth/accountToken/applications/PC/channels?mco=OFR',
endpoint_streams = 'https://rp-ott-mediation-tv.woopic.com/api-gw/live/v3/applications/PC/programs?groupBy=channel&mco=OFR',
endpoint_programs = 'https://rp-ott-mediation-tv.woopic.com/api-gw/live/v3/applications/PC/programs?period={period}&mco=OFR',
groups = {
'TNT': \
Expand Down
4 changes: 4 additions & 0 deletions resources/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def get_addon_name():
"""Return the addon info name property"""
return _ADDON.getAddonInfo('name')

def get_addon_path():
"""Return the addon info path property"""
return _ADDON.getAddonInfo('path')

def get_addon_profile():
"""Return the addon info profile property"""
return _ADDON.getAddonInfo('profile')
Expand Down

0 comments on commit baaf50b

Please sign in to comment.