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

[FR - FRANCETV] fix replay and live #1299

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
96 changes: 62 additions & 34 deletions resources/lib/resolver_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,20 +468,19 @@ def get_mtvnservices_stream(plugin,
return video_url


def get_francetv_program_info(video_id):
def __get_francetv_program_info(video_id):
# Move Live TV on the new API
geoip_value = web_utils.geoip()
if not geoip_value:
geoip_value = 'FR'
params = {
'country_code': geoip_value,
'browser': 'firefox',
'device_type': 'desktop',
'player_version': '5.105.1',
'domain': 'www.france.tv'
'os': 'iOS',
'device_type': 'mobile'
}
resp = urlquick.get(URL_FRANCETV_PROGRAM_INFO % video_id, params=params, headers=GENERIC_HEADERS, max_age=-1)
return json.loads(resp.text)
json_parser_live_id = json.loads(resp.text)
return json_parser_live_id


# FranceTV Part
Expand All @@ -490,7 +489,7 @@ def get_francetv_video_stream(plugin,
id_diffusion,
download_mode=False):

json_parser = get_francetv_program_info(id_diffusion)
json_parser = __get_francetv_program_info(id_diffusion)

if 'video' not in json_parser:
plugin.notify('ERROR', plugin.localize(30716))
Expand All @@ -505,45 +504,74 @@ def get_francetv_video_stream(plugin,
else:
all_video_datas.append((video_datas['format'], None, video_datas['token']))

url_selected = all_video_datas[0][2]
params = {
'format': 'json',
'url': video_datas['url']
}
resp = urlquick.get(url_selected, params=params, headers=GENERIC_HEADERS, max_age=-1)
json_parser = json.loads(resp.text)
final_video_url = json_parser['url']
url_selected = all_video_datas[0][2] + '&url=' + video_datas['url']
if 'hls' in all_video_datas[0][0]:
json_parser2 = json.loads(
urlquick.get(url_selected, max_age=-1).text)
final_video_url = json_parser2['url']
if download_mode:
return download.download_video(final_video_url)
return final_video_url + '|User-Agent=' + web_utils.get_random_ua()
return final_video_url + '|X-Forwarded-For=' + '2.' + str(randint(0, 15)) + '.' + str(
randint(0, 255)) + '.' + str(randint(0, 255)) + '&User-Agent=' + web_utils.get_random_ua()

if 'dash' in all_video_datas[0][0]:
headers = {
'User-Agent': web_utils.get_random_ua(),
'origin': 'https://www.france.tv'
}

input_stream_properties = {'license_type': None}
return get_stream_with_quality(plugin,
video_url=final_video_url,
manifest_type='mpd',
input_stream_properties=input_stream_properties,
headers=headers)

is_helper = inputstreamhelper.Helper('mpd')
if not is_helper.check_inputstream():
return False

item = Listitem()
item.property[INPUTSTREAM_PROP] = 'inputstream.adaptive'
item.property['inputstream.adaptive.manifest_type'] = 'mpd'
item.label = get_selected_item_label()
item.art.update(get_selected_item_art())
item.info.update(get_selected_item_info())

if all_video_datas[0][1]:
if download_mode:
xbmcgui.Dialog().ok(plugin.localize(14116), plugin.localize(30603))
return False
item.path = video_datas['url']
token_request = json.loads('{"id": "%s", "drm_type": "%s", "license_type": "%s"}'
% (id_diffusion, video_datas['drm_type'], video_datas['license_type']))
token = urlquick.post(video_datas['token'], json=token_request).json()['token']
license_request = '{"token": "%s", "drm_info": [D{SSM}]}' % token
license_key = 'https://widevine-proxy.drm.technology/proxy|Content-Type=application%%2Fjson|%s|' \
% quote_plus(license_request)
item.property['inputstream.adaptive.license_type'] = 'com.widevine.alpha'
item.property['inputstream.adaptive.license_key'] = license_key
else:
headers = {
'User-Agent': web_utils.get_random_ua(),
# 2.0.0.0 -> 2.16.0.255 are french IP addresses, see https://lite.ip2location.com/france-ip-address-ranges
# 'X-Forwarded-For': '2.' + str(randint(0, 15)) + '.' + str(randint(0, 255)) + '.' + str(randint(0, 255)),
}
stream_headers = urlencode(headers)
json_parser2 = json.loads(urlquick.get(url_selected, headers=headers, max_age=-1).text)
resp3 = urlquick.get(json_parser2['url'], headers=headers, max_age=-1, allow_redirects=False)
if 400 > resp3.status_code >= 300:
location_url = resp3.headers['location']
else:
location_url = resp3.url
item.path = location_url
if get_kodi_version() == 20:
item.property['inputstream.adaptive.manifest_headers'] = stream_headers
else:
item.property['inputstream.adaptive.stream_headers'] = stream_headers
if download_mode:
return download.download_video(item.path)
return item

# Return info the format is not known
return False


def get_francetv_live_stream(plugin, broadcast_id):

json_parser_live_id = get_francetv_program_info(broadcast_id)
final_url = json_parser_live_id['video']['token']
params = {
'format': 'json',
'url': json_parser_live_id['video']['url']
}
resp = urlquick.get(final_url, params=params, headers=GENERIC_HEADERS, max_age=-1)
json_parser_live_id = __get_francetv_program_info(broadcast_id)
final_url = json_parser_live_id['video']['token'] + '&url=' + json_parser_live_id['video']['url']

resp = urlquick.get(final_url, max_age=-1)
video_url = json.loads(resp.text)['url']
return get_stream_with_quality(plugin, video_url, license_url=URL_LICENSE_FRANCETV)

Expand Down
Loading