Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE AB] Fix live #1182

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 44 additions & 51 deletions resources/lib/channels/be/abbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@
# This file is part of Catch-up TV & More

from __future__ import unicode_literals
import re

import json
import random
import urlquick
import inputstreamhelper

from hashlib import sha256
from codecs import encode as codec_encode
import re
from codecs import decode as codec_decode
from codecs import encode as codec_encode
from hashlib import sha256

# noinspection PyUnresolvedReferences
import inputstreamhelper
import urlquick
# noinspection PyUnresolvedReferences
from codequick import Resolver, Listitem
# noinspection PyUnresolvedReferences
from kodi_six import xbmcgui
from resources.lib import web_utils
from resources.lib.web_utils import urlencode

from resources.lib.kodi_utils import (INPUTSTREAM_PROP, get_selected_item_art,
get_selected_item_info,
get_selected_item_label)

from resources.lib import web_utils, resolver_proxy
from resources.lib.web_utils import urlencode

# TO DO
# Add Paid contents ?
Expand All @@ -40,15 +39,17 @@

URL_AUTH_CALLBACK = URL_ROOT + '/auth-callback'

URL_API = 'https://subscription.digital.api.abweb.com/api/player/live/%s/%s'
URL_API = 'https://subscription.digital.api.abweb.com/api/player/flux/live/%s/%s/dash'

URL_LICENCE_KEY = 'https://mediawan.fe.cloud.vo.services/drmgateway/v1/drm/widevine/license?drmLicenseToken=%s'

URL_LICENCE_KEY = 'https://mediawan.fe.cloud.vo.services/drmgateway/v1/drm/widevine/license?drmLicenseToken=%s|User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3041.0 Safari/537.36&Origin=%s&Referer=%s&Authority=mediawan.fe.cloud.vo.services&Content-Type=|R{SSM}|'
PATTERN_TOKEN = re.compile(r'__RequestVerificationToken\" type=\"hidden\" value=\"(.*?)\"')


def genparams(item_id):
state = ''.join(random.choice('0123456789abcdef') for n in range(32))
state = ''.join(random.choice('0123456789abcdef') for _ in range(32))
while True:
code_verifier = ''.join(random.choice('0123456789abcdef') for n in range(96)).encode('utf-8')
code_verifier = ''.join(random.choice('0123456789abcdef') for _ in range(96)).encode('utf-8')
hashed = sha256(code_verifier).hexdigest()
code_challenge = codec_encode(codec_decode(hashed, 'hex'), 'base64').decode("utf-8").strip().replace('=', '')
# make sure that the hashed string doesn't contain + / =
Expand All @@ -74,40 +75,30 @@ def genparams(item_id):

@Resolver.register
def get_live_url(plugin, item_id, **kwargs):

# Using script (https://github.com/Catch-up-TV-and-More/plugin.video.catchuptvandmore/issues/484)

# Create session
session_urlquick = urlquick.Session()
json_parser = json.loads(genparams(item_id))
params = json_parser['params']
paramsencoded = urlencode(params)

# Get Token
# KO - resp = session_urlquick.get(URL_COMPTE_LOGIN)
resp = session_urlquick.get(URL_CONNECT_AUTHORIZE, params=params, max_age=-1)
value_token = re.compile(
r'__RequestVerificationToken\" type\=\"hidden\" value\=\"(.*?)\"').findall(resp.text)[0]
value_token = PATTERN_TOKEN.findall(resp.text)[0]
if plugin.setting.get_string('abweb.login') == '' or \
plugin.setting.get_string('abweb.password') == '':
xbmcgui.Dialog().ok(
'Info',
plugin.localize(30604) %
('ABWeb', 'http://www.abweb.com/BIS-TV-Online/abonnement.aspx'))
('ABWeb', 'https://live-replay.ab3.be/signup'))
return False
# Build PAYLOAD
payload = {
"__RequestVerificationToken":
value_token,
"Email":
plugin.setting.get_string('abweb.login'),
"Password":
plugin.setting.get_string('abweb.password'),
"button":
'login'
"__RequestVerificationToken": value_token,
"Email": plugin.setting.get_string('abweb.login'),
"Password": plugin.setting.get_string('abweb.password'),
"button": 'login'
}
paramslogin = {
'ReturnUrl': '/connect/authorize/callback?%s' % paramsencoded
'ReturnUrl': '/connect/authorize/callback?%s' % urlencode(params)
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
Expand All @@ -118,7 +109,7 @@ def get_live_url(plugin, item_id, **kwargs):
headers=headers,
verify=False)
next_url = resp2.history[1].headers['location']
code_value = re.compile(r'code\=(.*?)\&').findall(next_url)[0]
code_value = re.compile(r'code=(.*?)&').findall(next_url)[0]
code_verifier = json_parser['code_verifier']

paramtoken = {
Expand Down Expand Up @@ -146,21 +137,23 @@ def get_live_url(plugin, item_id, **kwargs):
resp4 = session_urlquick.get(URL_API % (item_id, item_id), headers=headers, max_age=-1)
json_parser4 = json.loads(resp4.text)

is_helper = inputstreamhelper.Helper("mpd", drm='widevine')
if not is_helper.check_inputstream():
return False
video_url = json_parser4["streamBaseUrl"] + ("/%s/dash/manifest.mpd?" % item_id)
if "hdnts" not in json_parser4["hdnts"]:
video_url += "hdnts="
video_url += json_parser4["hdnts"]

license_url = URL_LICENCE_KEY % (json_parser4["smToken"])

headers = {
'User-Agent': web_utils.get_random_ua(),
'Origin': URL_ROOT % item_id,
'Referer': URL_ROOT % item_id,
'Authority': 'mediawan.fe.cloud.vo.services',
'Content-Type': ''
}

item = Listitem()
if "hdnts" in json_parser4["hdnts"]:
item.path = json_parser4["streamBaseUrl"] + "/index.mpd?" + json_parser4["hdnts"]
else:
item.path = json_parser4["streamBaseUrl"] + "/index.mpd?hdnts=" + json_parser4["hdnts"]
item.property[INPUTSTREAM_PROP] = 'inputstream.adaptive'
item.property['inputstream.adaptive.manifest_type'] = 'mpd'
item.property['inputstream.adaptive.license_type'] = 'com.widevine.alpha'
item.property['inputstream.adaptive.license_key'] = URL_LICENCE_KEY % (
json_parser4["smToken"], URL_ROOT % item_id, URL_ROOT % item_id)
item.label = get_selected_item_label()
item.art.update(get_selected_item_art())
item.info.update(get_selected_item_info())
return item
return resolver_proxy.get_stream_with_quality(plugin,
video_url=video_url,
manifest_type='mpd',
headers=headers,
license_url=license_url)