diff options
Diffstat (limited to 'plugin.video.catchuptvandmore/resources/lib/channels/fr/france24.py')
-rw-r--r--[-rwxr-xr-x] | plugin.video.catchuptvandmore/resources/lib/channels/fr/france24.py | 196 |
1 files changed, 160 insertions, 36 deletions
diff --git a/plugin.video.catchuptvandmore/resources/lib/channels/fr/france24.py b/plugin.video.catchuptvandmore/resources/lib/channels/fr/france24.py index 6d61ec9..a7a65c5 100755..100644 --- a/plugin.video.catchuptvandmore/resources/lib/channels/fr/france24.py +++ b/plugin.video.catchuptvandmore/resources/lib/channels/fr/france24.py @@ -25,14 +25,14 @@ import time import re import json from bs4 import BeautifulSoup as bs +from youtube_dl import YoutubeDL from resources.lib import utils from resources.lib import common # TO DO -# Replay (emission) | (just 5 first episodes) Add More Button (with api) to download just some part ? (More Work TO DO) +# Replay (emission) | (just 5 first episodes) +# Add More Button (with api) to download just some part ? (More Work TO DO) # Add info LIVE TV (picture, plot) -# Add Video, Last JT, Last ECO, Last Meteo -# Select Language settings not show # Initialize GNU gettext emulation in addon # This allows to use UI strings from addon’s English @@ -45,10 +45,12 @@ URL_LIVE_SITE = 'http://www.france24.com/%s/' URL_INFO_LIVE = 'http://www.france24.com/%s/_fragment/player/nowplaying/' # Language -URL_API_VOD = 'http://api.france24.com/%s/services/json-rpc/emission_list?databases=f24%s&key=XXX' \ +URL_API_VOD = 'http://api.france24.com/%s/services/json-rpc/' \ + 'emission_list?databases=f24%s&key=XXX' \ '&start=0&limit=50&edition_start=0&edition_limit=5' # language + def channel_entry(params): """Entry function of the module""" if 'root' in params.next: @@ -61,32 +63,52 @@ def channel_entry(params): return list_live(params) elif 'play' in params.next: return get_video_url(params) + elif 'list_nwb' in params.next: + return list_nwb(params) return None -@common.PLUGIN.cached(common.CACHE_TIME) + +@common.PLUGIN.mem_cached(common.CACHE_TIME) def root(params): """Add Replay and Live in the listing""" modes = [] + desired_language = common.PLUGIN.get_setting( + params.channel_id + '.language') + # Add Replay - modes.append({ - 'label' : 'Replay', - 'url': common.PLUGIN.get_url( - action='channel_entry', - next='list_shows_1', - category='%s Replay' % params.channel_name.upper(), - window_title='%s Replay' % params.channel_name.upper() - ), - }) + if desired_language != 'ES': + modes.append({ + 'label': 'Replay', + 'url': common.PLUGIN.get_url( + action='channel_entry', + next='list_shows_1', + category='%s Replay' % params.channel_name.upper(), + window_title='%s Replay' % params.channel_name.upper() + ), + }) # Add Live + if desired_language != 'ES': + modes.append({ + 'label': 'Live TV', + 'url': common.PLUGIN.get_url( + action='channel_entry', + next='live_cat', + category='%s Live TV' % params.channel_name.upper(), + window_title='%s Live TV' % params.channel_name.upper() + ), + }) + modes.append({ - 'label' : 'Live TV', + 'label': 'News - Weather - Business', 'url': common.PLUGIN.get_url( action='channel_entry', - next='live_cat', - category='%s Live TV' % params.channel_name.upper(), - window_title='%s Live TV' % params.channel_name.upper() + next='list_nwb_1', + category='%s News - Weather - Business' % ( + params.channel_name.upper()), + window_title='%s News - Weather - Business' % ( + params.channel_name.upper()) ), }) @@ -98,7 +120,8 @@ def root(params): ), ) -@common.PLUGIN.cached(common.CACHE_TIME) + +@common.PLUGIN.mem_cached(common.CACHE_TIME) def list_shows(params): """Build shows listing""" shows = [] @@ -108,13 +131,17 @@ def list_shows(params): if params.next == 'list_shows_1': file_path = utils.download_catalog( - URL_API_VOD % (desired_language.lower(),desired_language.lower()), - '%s_%s_vod.json' % (params.channel_name,desired_language.lower()) + URL_API_VOD % ( + desired_language.lower(), desired_language.lower()), + '%s_%s_vod.json' % ( + params.channel_name, desired_language.lower()) ) json_vod = open(file_path).read() json_parser = json.loads(json_vod) - list_caterories = json_parser["result"]["f24%s" % desired_language.lower()]["list"] + list_caterories = json_parser["result"] + list_caterories = list_caterories["f24%s" % desired_language.lower()] + list_caterories = list_caterories["list"] for category in list_caterories: category_name = category["title"].encode('utf-8') @@ -144,7 +171,8 @@ def list_shows(params): ), ) -@common.PLUGIN.cached(common.CACHE_TIME) + +@common.PLUGIN.mem_cached(common.CACHE_TIME) def list_videos(params): """Build videos listing""" videos = [] @@ -159,7 +187,9 @@ def list_videos(params): json_vod = open(file_path).read() json_parser = json.loads(json_vod) - list_caterories = json_parser["result"]["f24%s" % desired_language.lower()]["list"] + list_caterories = json_parser["result"] + list_caterories = list_caterories["f24%s" % desired_language.lower()] + list_caterories = list_caterories["list"] for category in list_caterories: if str(params.nid) == str(category["nid"]): for video in category["editions"]["list"]: @@ -169,7 +199,8 @@ def list_videos(params): img = video["image"][0]["original"].encode('utf-8') url = video["video"][0]["mp4-mbr"].encode('utf-8') - value_date = time.strftime('%d %m %Y', time.localtime(int(video["created"]))) + value_date = time.strftime( + '%d %m %Y', time.localtime(int(video["created"]))) date = str(value_date).split(' ') day = date[0] mounth = date[1] @@ -182,9 +213,9 @@ def list_videos(params): 'title': title, 'aired': aired, 'date': date, - #'duration': video_duration, + # 'duration': video_duration, 'year': year, - 'plot' : plot, + 'plot': plot, 'mediatype': 'tvshow' } } @@ -212,7 +243,6 @@ def list_videos(params): 'context_menu': context_menu }) - # TO DO add More button Video return common.PLUGIN.create_listing( @@ -223,7 +253,8 @@ def list_videos(params): ), content='tvshows') -@common.PLUGIN.cached(common.CACHE_TIME) + +@common.PLUGIN.mem_cached(common.CACHE_TIME) def list_live(params): """Build live listing""" lives = [] @@ -246,14 +277,18 @@ def list_live(params): html_live = open(file_path).read() root_soup = bs(html_live, 'html.parser') - json_parser = json.loads(root_soup.select_one("script[type=application/json]").text) - media_datas_list = json_parser['medias']['media']['media_sources']['media_source'] + json_parser = json.loads( + root_soup.select_one("script[type=application/json]").text) + media_datas_list = json_parser['medias']['media'] + media_datas_list = media_datas_list['media_sources']['media_source'] for datas in media_datas_list: if datas['source']: url_live = datas['source'] - live_info = utils.get_webcontent(URL_INFO_LIVE % (desired_language.lower())) - title = re.compile('id="main-player-playing-value">(.+?)<').findall(live_info)[0] + live_info = utils.get_webcontent( + URL_INFO_LIVE % (desired_language.lower())) + title = re.compile( + 'id="main-player-playing-value">(.+?)<').findall(live_info)[0] info = { 'video': { @@ -267,7 +302,7 @@ def list_live(params): 'label': title, 'fanart': img, 'thumb': img, - 'url' : common.PLUGIN.get_url( + 'url': common.PLUGIN.get_url( action='channel_entry', next='play_l', url=url_live, @@ -284,11 +319,100 @@ def list_live(params): ) ) -@common.PLUGIN.cached(common.CACHE_TIME) + +@common.PLUGIN.mem_cached(common.CACHE_TIME) +def list_nwb(params): + """Build News - Weather - Business listing""" + nbe = [] + + desired_language = common.PLUGIN.get_setting( + params.channel_id + '.language') + + url_news = '' + url_weather = '' + url_business = '' + + if 'FR' == desired_language: + url_news = URL_LIVE_SITE % desired_language.lower() + \ + 'vod/journal-info' + url_weather = URL_LIVE_SITE % desired_language.lower() + \ + 'vod/meteo-internationale' + url_business = URL_LIVE_SITE % desired_language.lower() + \ + 'vod/journal-economie' + elif 'ES' == desired_language: + url_news = URL_LIVE_SITE % desired_language.lower() + \ + 'vod/ultimo-noticiero' + url_weather = URL_LIVE_SITE % desired_language.lower() + \ + 'vod/el-tiempo' + url_business = URL_LIVE_SITE % desired_language.lower() + \ + 'vod/economia' + elif 'EN' == desired_language or 'AR' == desired_language: + url_news = URL_LIVE_SITE % desired_language.lower() + \ + 'vod/latest-news' + url_weather = URL_LIVE_SITE % desired_language.lower() + \ + 'vod/international-weather-forecast' + url_business = URL_LIVE_SITE % desired_language.lower() + \ + 'vod/business-news' + + url_nbe_list = [] + url_nbe_list.append(url_news) + url_nbe_list.append(url_weather) + url_nbe_list.append(url_business) + + ydl = YoutubeDL() + + for url_nbe in url_nbe_list: + url_nbe_html = utils.get_webcontent(url_nbe) + root_soup = bs(url_nbe_html, 'html.parser') + url_nbe_yt_html = utils.get_webcontent( + root_soup.find( + 'div', class_='yt-vod-container').find('iframe').get('src')) + url_yt = re.compile( + '<link rel="canonical" href="(.*?)"').findall(url_nbe_yt_html)[0] + ydl.add_default_info_extractors() + with ydl: + result = ydl.extract_info(url_yt, download=False) + for format_video in result['formats']: + url_nbe_stream = format_video['url'] + title = result['title'] + plot = '' + duration = 0 + img = result['thumbnail'] + + info = { + 'video': { + 'title': title, + 'plot': plot, + 'duration': duration + } + } + + nbe.append({ + 'label': title, + 'fanart': img, + 'thumb': img, + 'url': common.PLUGIN.get_url( + action='channel_entry', + next='play_r', + url=url_nbe_stream, + ), + 'is_playable': True, + 'info': info + }) + + return common.PLUGIN.create_listing( + nbe, + sort_methods=( + common.sp.xbmcplugin.SORT_METHOD_UNSORTED, + common.sp.xbmcplugin.SORT_METHOD_LABEL + ) + ) + + +@common.PLUGIN.mem_cached(common.CACHE_TIME) def get_video_url(params): """Get video URL and start video player""" if params.next == 'play_l': return params.url elif params.next == 'play_r' or params.next == 'download_video': return params.url - |