def connect_openvpn(config, restart=False, sudopassword=None): storage = common.sp.MemStorage('vpn') common.PLUGIN.log_debug('Connecting OpenVPN configuration: [%s]' % config) if common.PLUGIN.get_setting('vpn.sudo') and \ common.PLUGIN.get_setting('vpn.sudopsw') and sudopassword is None: keyboard = common.sp.xbmc.Keyboard( default='', heading=common.GETTEXT('Enter your sudo password'), hidden=True) keyboard.doModal() if keyboard.isConfirmed(): sudopassword = keyboard.getText() openvpn = vpnlib.OpenVPN(common.PLUGIN.get_setting('vpn.openvpnfilepath'), config, ip=ip, port=port, args=common.PLUGIN.get_setting('vpn.args'), sudo=common.PLUGIN.get_setting('vpn.sudo'), sudopwd=sudopassword, debug=True) try: if restart: openvpn.disconnect() storage['status'] = "disconnected" openvpn.connect() utils.send_notification(common.GETTEXT('Started VPN connection'), title="OpenVPN", time=3000) storage['status'] = "connected" except vpnlib.OpenVPNError as exception: if exception.errno == 1: storage['status'] = "connected" if common.sp.xbmcgui.Dialog().yesno( 'OpenVPN', common.GETTEXT( 'An existing OpenVPN instance appears to be running.'), common.GETTEXT('Disconnect it?')): common.PLUGIN.log_debug('User has decided to restart OpenVPN') connect_openvpn(config, True, sudopassword) else: common.PLUGIN.log_debug( 'User has decided not to restart OpenVPN') else: common.sp.xbmcgui.Dialog().ok( 'OpenVPN', common.GETTEXT( 'An error has occurred whilst trying to connect OpenVPN')) storage['status'] = "failed"
def hide(params): if common.PLUGIN.get_setting('show_hidden_items_information'): common.sp.xbmcgui.Dialog().ok( common.GETTEXT('Information'), common.GETTEXT( 'To re-enable hidden items go to the plugin settings')) common.PLUGIN.set_setting('show_hidden_items_information', False) common.PLUGIN.set_setting(params.item_id, False) common.sp.xbmc.executebuiltin('XBMC.Container.Refresh()') return None
def vpn_context_menu_item(): vpn_label = common.GETTEXT('Connect VPN') storage = common.sp.MemStorage('vpn') if 'status' in storage: if storage['status'] == "connected": vpn_label = common.GETTEXT('Disconnect VPN') else: storage['status'] = "disconnected" vpn = (vpn_label, 'XBMC.RunPlugin(' + common.PLUGIN.get_url(action='vpn_entry') + ')') return vpn
def list_shows(params): """Build shows listing""" shows = [] if params.next == 'list_shows_1': all_video = common.ADDON.get_localized_string(30701) url_channel_replay = list_channels[params.module_name] shows.append({ 'label': common.GETTEXT('All videos'), 'url': common.PLUGIN.get_url(module_path=params.module_path, module_name=params.module_name, action='replay_entry', next='list_videos_1', url_channel_replay=url_channel_replay, all_video=all_video, window_title=all_video) }) return common.PLUGIN.create_listing( shows, sort_methods=(common.sp.xbmcplugin.SORT_METHOD_UNSORTED, common.sp.xbmcplugin.SORT_METHOD_LABEL), category=common.get_window_title(params))
def get_stream_youtube(video_id, isDownloadVideo): url_youtube = URL_YOUTUBE % video_id if isDownloadVideo is True: return url_youtube YDStreamExtractor = __import__('YDStreamExtractor') quality = 3 desired_quality = common.PLUGIN.get_setting('quality') if desired_quality == "DIALOG": all_quality = ['SD', '720p', '1080p', 'Highest available'] seleted_item = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Choose video quality'), all_quality) if seleted_item == -1: quality = 3 selected_quality_string = all_quality[seleted_item] quality_string = { 'SD': 0, '720p': 1, '1080p': 2, 'Highest available': 3 } quality = quality_string[selected_quality_string] vid = YDStreamExtractor.getVideoInfo( url_youtube, quality=quality, resolve_redirects=True ) return vid.streamURL()
def get_stream_facebook(video_id, isDownloadVideo): url_facebook = URL_FACEBOOK_BY_ID % (video_id) if isDownloadVideo == True: return url_facebook html_facebook = utils.get_webcontent(url_facebook) if len(re.compile(r'hd_src_no_ratelimit:"(.*?)"').findall( html_facebook)) > 0: if DESIRED_QUALITY == "DIALOG": all_datas_videos_quality = [] all_datas_videos_path = [] all_datas_videos_quality.append('SD') all_datas_videos_path.append( re.compile(r'sd_src_no_ratelimit:"(.*?)"').findall( html_facebook)[0]) all_datas_videos_quality.append('HD') all_datas_videos_path.append( re.compile(r'hd_src_no_ratelimit:"(.*?)"').findall( html_facebook)[0]) seleted_item = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Choose video quality'), all_datas_videos_quality) return all_datas_videos_path[seleted_item].encode('utf-8') elif DESIRED_QUALITY == 'BEST': return re.compile(r'hd_src_no_ratelimit:"(.*?)"').findall( html_facebook)[0] else: return re.compile(r'sd_src_no_ratelimit:"(.*?)"').findall( html_facebook)[0] else: return re.compile(r'sd_src_no_ratelimit:"(.*?)"').findall( html_facebook)[0]
def ytdl_resolver(url_stream): YDStreamExtractor = __import__('YDStreamExtractor') quality = 0 if DESIRED_QUALITY == "DIALOG": all_quality = ['SD', '720p', '1080p', 'Highest available'] seleted_item = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Choose video quality'), all_quality) if seleted_item > -1: selected_quality_string = all_quality[seleted_item] quality_string = { 'SD': 0, '720p': 1, '1080p': 2, 'Highest available': 3 } quality = quality_string[selected_quality_string] else: return None elif DESIRED_QUALITY == "BEST": quality = 3 vid = YDStreamExtractor.getVideoInfo(url_stream, quality=quality, resolve_redirects=True) if vid is None: # TODO catch the error (geo-blocked, deleted, etc ...) utils.send_notification(common.ADDON.get_localized_string(30716)) return None else: return vid.streamURL()
def root(params): """Add modes in the listing""" modes = [] category_title = common.GETTEXT('All videos') modes.append({ 'label': category_title, 'url': common.PLUGIN.get_url( module_path=params.module_path, module_name=params.module_name, action='website_entry', next='list_videos_1', title=category_title, page='1', window_title=category_title ) }) return common.PLUGIN.create_listing( modes, sort_methods=( common.sp.xbmcplugin.SORT_METHOD_LABEL, common.sp.xbmcplugin.SORT_METHOD_UNSORTED ), category=common.get_window_title(params) )
def get_video_url(params): """Get video URL and start video player""" if params.next == 'play_l': return params.url_live elif params.channel_name == 'rmcdecouverte' and params.next == 'play_r': url_video_datas = utils.get_webcontent(URL_VIDEO_HTML_RMCDECOUVERTE % (params.video_id)) video_datas_soup = bs(url_video_datas, 'html.parser') video_datas = video_datas_soup.find('div', class_='next-player') data_account = video_datas['data-account'] data_video_id = video_datas['data-video-id'] data_player = video_datas['data-player'] return resolver.get_brightcove_video_json(data_account, data_player, data_video_id) elif params.channel_name == 'rmcdecouverte' and \ params.next == 'download_video': return URL_VIDEO_HTML_RMCDECOUVERTE % (params.video_id) elif params.channel_name != 'rmcdecouverte' and \ (params.next == 'play_r' or params.next == 'download_video'): file_medias = utils.get_webcontent( URL_VIDEO % (params.channel_name, get_token( params.channel_name), params.video_id)) json_parser = json.loads(file_medias) if params.next == 'download_video': return json_parser['video']['long_url'].encode('utf-8') video_streams = json_parser['video']['medias'] desired_quality = common.PLUGIN.get_setting('quality') if desired_quality == "DIALOG": all_datas_videos_quality = [] all_datas_videos_path = [] for datas in video_streams: all_datas_videos_quality.append("Video Height : " + str(datas['frame_height']) + " (Encoding : " + str(datas['encoding_rate']) + ")") all_datas_videos_path.append(datas['video_url']) seleted_item = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Choose video quality'), all_datas_videos_quality) return all_datas_videos_path[seleted_item].encode('utf-8') elif desired_quality == 'BEST': # GET LAST NODE (VIDEO BEST QUALITY) url_best_quality = '' for datas in video_streams: url_best_quality = datas['video_url'].encode('utf-8') return url_best_quality else: # DEFAULT VIDEO return json_parser['video']['video_url'].encode('utf-8')
def get_stream_youtube(video_id, isDownloadVideo): url_youtube = URL_YOUTUBE % video_id if isDownloadVideo is True: return url_youtube YDStreamExtractor = __import__('YDStreamExtractor') quality = 0 if DESIRED_QUALITY == "DIALOG": all_quality = ['SD', '720p', '1080p', 'Highest available'] seleted_item = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Choose video quality'), all_quality) if seleted_item == -1: quality = 3 selected_quality_string = all_quality[seleted_item] quality_string = { 'SD': 0, '720p': 1, '1080p': 2, 'Highest available': 3 } quality = quality_string[selected_quality_string] elif DESIRED_QUALITY == "BEST": quality = 3 vid = YDStreamExtractor.getVideoInfo(url_youtube, quality=quality, resolve_redirects=True) if vid is None: # TODO catch the error (geo-blocked, deleted, etc ...) return None else: return vid.streamURL()
def select_ovpn(): ovpnfiles = {} with common.PLUGIN.get_storage() as storage: try: ovpnfiles = storage['ovpnfiles'] except KeyError: storage['ovpnfiles'] = ovpnfiles if len(ovpnfiles) == 0: return None else: response = vpnlib.is_running(ip, port) common.PLUGIN.log_debug('Response from is_running: [%s] [%s] [%s]' % (response[0], response[1], response[2])) if response[0]: # Le VPN est connecté print 'VPN Encore connecté, pas normal, je vais le déco' disconnect_openvpn() configs = [] ovpnfileslist = [] for name, configfilepath in ovpnfiles.iteritems(): configs.append(name) ovpnfileslist.append(configfilepath) idx = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Select OpenVPN configuration to run'), configs) if idx >= 0: common.PLUGIN.log_debug('Select: [%s]' % ovpnfileslist[idx]) return ovpnfileslist[idx] else: return ''
def get_video_url(params): """Get video URL and start video player""" video_json = utils.get_webcontent(URL_JSON_VIDEO % (params.video_id), random_ua=True) json_parser = json.loads(video_json) print 'COUCOU' print '\n\n' + video_json + '\n\n' video_assets = json_parser['clips'][0]['assets'] if video_assets is None: utils.send_notification(common.ADDON.get_localized_string(30712)) return '' # "type":"primetime_phls_h264" => Video protected by DRM (m3u8) # "type":"usp_hls_h264" => Video not protected by DRM (m3u8) # "type":"usp_dashcenc_h264" => No supported by Kodi (MDP) # "type":"usp_hlsfp_h264" => Video protected by DRM (m3u8) # "type":"http_h264" => Video not proted by DRM (mp4) (Quality SD "video_quality":"sd", HD "video_quality":"hq", HD "video_quality":"hd", HD "video_quality":"lq", 3G) # "type":"http_subtitle_vtt_sm" => Subtitle (in English TVShows) desired_quality = common.PLUGIN.get_setting('quality') all_datas_videos_quality = [] all_datas_videos_path = [] for asset in video_assets: if 'http_h264' in asset["type"]: all_datas_videos_quality.append(asset["video_quality"]) all_datas_videos_path.append( asset['full_physical_path'].encode('utf-8')) elif 'h264' in asset["type"]: manifest = utils.get_webcontent( asset['full_physical_path'].encode('utf-8'), random_ua=True) if 'drm' not in manifest: all_datas_videos_quality.append(asset["video_quality"]) all_datas_videos_path.append( asset['full_physical_path'].encode('utf-8')) if len(all_datas_videos_quality) == 0: utils.send_notification(common.ADDON.get_localized_string(30702)) return '' elif len(all_datas_videos_quality) == 1: return all_datas_videos_path[0] else: if desired_quality == "DIALOG": seleted_item = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Choose video quality'), all_datas_videos_quality) if seleted_item == -1: return '' return all_datas_videos_path[seleted_item] elif desired_quality == "BEST": url_best = '' i = 0 for data_video in all_datas_videos_quality: if 'lq' not in data_video: url_best = all_datas_videos_path[i] i = i + 1 return url_best else: return all_datas_videos_path[0]
def list_videos(params): """Build videos listing""" videos = [] videos_html = utils.get_webcontent(URL_VIDEOS % params.title) xml_elements = ET.XML(videos_html) for video_datas in xml_elements.findall("video"): video_title = video_datas.find('show').text.encode('utf-8') video_duration = 0 video_url = video_datas.find('videourl').text.encode('utf-8') video_img = video_datas.find('screenshot').text.encode('utf-8') video_plot = video_datas.find('description').text.encode('utf-8') info = { 'video': { 'title': video_title, # 'aired': aired, # 'date': date, 'duration': video_duration, 'plot': video_plot, # 'year': year, 'mediatype': 'tvshow' } } download_video = (common.GETTEXT('Download'), 'XBMC.RunPlugin(' + common.PLUGIN.get_url(action='download_video', module_path=params.module_path, module_name=params.module_name, video_url=video_url) + ')') context_menu = [] context_menu.append(download_video) videos.append({ 'label': video_title, 'thumb': video_img, 'url': common.PLUGIN.get_url(module_path=params.module_path, module_name=params.module_name, action='replay_entry', next='play_r', video_url=video_url), 'is_playable': True, 'info': info, 'context_menu': context_menu }) return common.PLUGIN.create_listing( videos, sort_methods=(common.sp.xbmcplugin.SORT_METHOD_UNSORTED), content='tvshows', category=common.get_window_title(params))
def get_video_url(params): """Get video URL and start video player""" if params.next == 'play_r' or params.next == 'download_video': video_html = utils.get_webcontent(params.video_url) video_id = re.compile(r'www.wat.tv/embedframe/(.*?)[\"\?]').findall( video_html)[0] url_wat_embed = URL_WAT_BY_ID % video_id wat_embed_html = utils.get_webcontent(url_wat_embed) stream_id = re.compile('UVID=(.*?)&').findall(wat_embed_html)[0] url_json = URL_VIDEO_STREAM % stream_id htlm_json = utils.get_webcontent(url_json, random_ua=True) json_parser = json.loads(htlm_json) # Check DRM in the m3u8 file manifest = utils.get_webcontent(json_parser["hls"], random_ua=True) if 'drm' in manifest: utils.send_notification(common.ADDON.get_localized_string(30702)) return '' root = os.path.dirname(json_parser["hls"]) manifest = utils.get_webcontent( json_parser["hls"].split('&max_bitrate=')[0]) lines = manifest.splitlines() if DESIRED_QUALITY == "DIALOG": all_datas_videos_quality = [] all_datas_videos_path = [] for k in range(0, len(lines) - 1): if 'RESOLUTION=' in lines[k]: if len(re.compile(r'RESOLUTION=(.*?),').findall( lines[k])) > 0: all_datas_videos_quality.append( re.compile(r'RESOLUTION=(.*?),').findall( lines[k])[0]) else: all_datas_videos_quality.append( lines[k].split('RESOLUTION=')[1]) all_datas_videos_path.append(root + '/' + lines[k + 1]) seleted_item = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Choose video quality'), all_datas_videos_quality) if seleted_item > -1: return all_datas_videos_path[seleted_item].encode('utf-8') else: return None elif DESIRED_QUALITY == 'BEST': # Last video in the Best for k in range(0, len(lines) - 1): if 'RESOLUTION=' in lines[k]: url = root + '/' + lines[k + 1] return url else: for k in range(0, len(lines) - 1): if 'RESOLUTION=' in lines[k]: url = root + '/' + lines[k + 1] break return url
def list_shows(params): """Build categories listing""" shows = [] if params.next == 'list_shows_1': category_name = common.GETTEXT('All videos') category_url = URL_VIDEOS shows.append({ 'label': category_name, 'url': common.PLUGIN.get_url( module_path=params.module_path, module_name=params.module_name, action='replay_entry', category_url=category_url, category_name=category_name, next='list_videos_1', page='0', window_title=category_name ) }) replay_categories_html = utils.get_webcontent(URL_EMISSIONS) replay_categories_soup = bs(replay_categories_html, 'html.parser') categories = replay_categories_soup.find_all( 'article', class_=re.compile("emmissionsboxtop")) for category in categories: category_name = category.find( 'img').get('alt') category_img = category.find( 'img').get('src') category_url = URL_ROOT + '/' + category.find( "a").get("href") shows.append({ 'label': category_name, 'thumb': category_img, 'url': common.PLUGIN.get_url( module_path=params.module_path, module_name=params.module_name, action='replay_entry', category_url=category_url, category_name=category_name, next='list_videos_1', page='0', window_title=category_name ) }) return common.PLUGIN.create_listing( shows, sort_methods=( common.sp.xbmcplugin.SORT_METHOD_UNSORTED, common.sp.xbmcplugin.SORT_METHOD_LABEL ), category=common.get_window_title(params) )
def root(params): """Add modes in the listing""" modes = [] for category_name, category_url in CATEGORIES.iteritems(): if 'series' in category_url or 'films' in category_url: next_value = 'list_shows_films_series_1' else: next_value = 'list_shows_emissions_1' modes.append({ 'label': category_name, 'url': common.PLUGIN.get_url( module_path=params.module_path, module_name=params.module_name, action='website_entry', category_url=category_url, category_name=category_name, next=next_value, window_title=category_name ) }) # Search videos modes.append({ 'label': common.GETTEXT('Search videos'), 'url': common.PLUGIN.get_url( module_path=params.module_path, module_name=params.module_name, action='website_entry', next='search', window_title=common.GETTEXT('Search videos'), is_folder=False ) }) return common.PLUGIN.create_listing( modes, sort_methods=( common.sp.xbmcplugin.SORT_METHOD_LABEL, common.sp.xbmcplugin.SORT_METHOD_UNSORTED ), category=common.get_window_title(params) )
def clear_cache(): for file in os.listdir(cache_path): file_path = os.path.join(cache_path, file) try: if os.path.isfile(file_path): os.remove(file_path) except Exception as e: print(e) send_notification(common.GETTEXT('Cache cleared'))
def list_shows(params): """Build categories listing""" shows = [] if params.channel_name == 'rmcdecouverte': all_video = common.ADDON.get_localized_string(30701) shows.append({ 'label': common.GETTEXT('All videos'), 'url': common.PLUGIN.get_url(module_path=params.module_path, module_name=params.module_name, action='replay_entry', next='list_videos_1', all_video=all_video, window_title=all_video) }) else: if params.next == 'list_shows_1': file_path = utils.download_catalog( URL_REPLAY % (params.channel_name, get_token(params.channel_name)), '%s.json' % (params.channel_name)) file_categories = open(file_path).read() json_categories = json.loads(file_categories) json_categories = json_categories['page']['contents'][0] json_categories = json_categories['elements'][0]['items'] for categories in json_categories: title = categories['title'].encode('utf-8') image_url = categories['image_url'].encode('utf-8') category = categories['categories'].encode('utf-8') shows.append({ 'label': title, 'thumb': image_url, 'url': common.PLUGIN.get_url(module_path=params.module_path, module_name=params.module_name, action='replay_entry', category=category, next='list_videos_1', title=title, page='1', window_title=title) }) return common.PLUGIN.create_listing( shows, sort_methods=(common.sp.xbmcplugin.SORT_METHOD_UNSORTED, common.sp.xbmcplugin.SORT_METHOD_LABEL), category=common.get_window_title(params))
def get_video_url(params): """Get video URL and start video player""" url_selected = '' all_datas_videos_quality = [] all_datas_videos_path = [] videos_html = utils.get_webcontent(params.video_url) videos_soup = bs(videos_html, 'html.parser') list_videos = videos_soup.find('ul', class_='nav nav-tabs').find_all('a') for video in list_videos: if '#video-' in video.get('href'): # Find a better solution to strip all_datas_videos_quality.append(video.get_text().strip()) # Get link value_jwplayer_id = video.get('data-jwplayer-id') # Case mp4 if value_jwplayer_id != '': list_streams = videos_soup.find_all('div', class_='jwplayer') for stream in list_streams: if stream.get('id') == value_jwplayer_id: url = stream.get('data-source') # Cas Yt else: video_id = re.compile('youtube.com/embed/(.*?)\?').findall( videos_html)[0] url = resolver.get_stream_youtube(video_id, False) all_datas_videos_path.append(url) # Get link from FranceTV elif '#ftv-player-' in video.get('href'): # Find a better solution to strip all_datas_videos_quality.append(video.get_text().strip()) # Get link value_ftvlayer_id = video.get('data-ftvplayer-id') list_streams = videos_soup.find_all('iframe', class_='embed-responsive-item') for stream in list_streams: if stream.get('id') == value_ftvlayer_id: url_id = stream.get('src') ydl = YoutubeDL() ydl.add_default_info_extractors() with ydl: result = ydl.extract_info(url_id, download=False) for format_video in result['formats']: url = format_video['url'] all_datas_videos_path.append(url) if len(all_datas_videos_quality) > 1: seleted_item = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Choose video quality'), all_datas_videos_quality) if seleted_item == -1: return '' url_selected = all_datas_videos_path[seleted_item] return url_selected else: return all_datas_videos_path[0]
def get_video_url(params): """Get video URL and start video player""" desired_quality = common.PLUGIN.get_setting('quality') file_prgm = utils.get_webcontent(SHOW_INFO % (params.id_diffusion)) json_parser = json.loads(file_prgm) url_selected = '' if desired_quality == "DIALOG": all_datas_videos_quality = [] all_datas_videos_path = [] for video in json_parser['videos']: if 'hls' in video['format']: if video['format'] == 'hls_v5_os': all_datas_videos_quality.append("HD") else: all_datas_videos_quality.append("SD") all_datas_videos_path.append( (video['url'], video['drm'])) seleted_item = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Choose video quality'), all_datas_videos_quality) if seleted_item == -1: return None url_selected = all_datas_videos_path[seleted_item][0] drm = all_datas_videos_path[seleted_item][1] elif desired_quality == "BEST": for video in json_parser['videos']: if video['format'] == 'hls_v5_os': url_selected = video['url'] drm = video['drm'] else: url_selected = video['url'] drm = video['drm'] else: for video in json_parser['videos']: if video['format'] == 'm3u8-download': url_selected = video['url'] drm = video['drm'] else: url_selected = video['url'] drm = video['drm'] if drm: utils.send_notification( common.ADDON.get_localized_string(30702)) return None else: return url_selected
def disconnect_openvpn(): storage = common.sp.MemStorage('vpn') common.PLUGIN.log_debug('Disconnecting OpenVPN') try: storage['status'] = "disconnecting" response = vpnlib.is_running(ip, port) if response[0]: vpnlib.disconnect(ip, port) if response[1] is not None: utils.send_notification( common.GETTEXT('Stopped VPN connection'), title="OpenVPN", time=3000) storage['status'] = "disconnected" common.PLUGIN.log_debug('Disconnect OpenVPN successful') except vpnlib.OpenVPNError as exception: common.sp.xbmcgui.Dialog().ok( 'OpenVPN', common.GETTEXT( 'An error has occurred whilst trying to connect OpenVPN')) storage['status'] = "failed"
def import_ovpn(): path = common.sp.xbmcgui.Dialog().browse( 1, common.GETTEXT('Import OpenVPN configuration file'), 'files', mask='.ovpn|.conf', enableMultiple=False) if path and os.path.exists(path) and os.path.isfile(path): common.PLUGIN.log_debug('Import: [%s]' % path) keyboard = common.sp.xbmc.Keyboard( default='', heading=common.GETTEXT('Choose a name for OpenVPN configuration'), hidden=False) keyboard.doModal() if keyboard.isConfirmed() and len(keyboard.getText()) > 0: name = keyboard.getText() ovpnfiles = {} with common.PLUGIN.get_storage() as storage: ovpnfiles = storage['ovpnfiles'] if name in ovpnfiles and not common.sp.xbmcgui.Dialog().yesno( 'OpenVPN', common.GETTEXT('This OpenVPN configuration ' 'name already exists. Overwrite?')): common.sp.xbmcgui.Dialog().ok( 'OpenVPN', common.GETTEXT('Import cancelled')) else: ovpnfiles[name] = path with common.PLUGIN.get_storage() as storage: storage['ovpnfiles'] = ovpnfiles else: common.sp.xbmcgui.Dialog().ok( 'OpenVPN', common.GETTEXT('Import failed. You must specify a ' 'name for the OpenVPN configuration'))
def root(params): """Add modes in the listing""" modes = [] category_title = common.GETTEXT('All videos') category_url = URL_ROOT + '/search?types=video&page=%s&sort=-origin_date' modes.append({ 'label': category_title, 'url': common.PLUGIN.get_url(module_path=params.module_path, module_name=params.module_name, action='website_entry', next='list_videos_1', title=category_title, category_url=category_url, page='1', window_title=category_title) }) categories_html = utils.get_webcontent(URL_ROOT + '/search?types=video') categories_soup = bs(categories_html, 'html.parser') categories = categories_soup.find( 'div', class_='facet-group facet-group--tags open').find_all('label') for category in categories: category_title = category.get_text().strip().encode('utf-8') category_id = category.find('input').get('value') category_url = URL_ROOT + '/search?types=video' + \ '&tags=%s&sort=-origin_date' % category_id + \ '&page=%s' modes.append({ 'label': category_title, 'url': common.PLUGIN.get_url(module_path=params.module_path, module_name=params.module_name, action='website_entry', next='list_videos_1', title=category_title, category_url=category_url, page='1', window_title=category_title) }) return common.PLUGIN.create_listing( modes, sort_methods=(common.sp.xbmcplugin.SORT_METHOD_UNSORTED), category=common.get_window_title(params))
def list_shows(params): """Build shows listing""" shows = [] if params.next == 'list_shows_1': all_video = common.ADDON.get_localized_string(30701) shows.append({ 'label': common.GETTEXT('All videos'), 'url': common.PLUGIN.get_url(module_path=params.module_path, module_name=params.module_name, action='replay_entry', next='list_videos_cat', category_id=0, all_video=all_video, window_title=all_video) }) file_path = utils.download_catalog( URL_CATEGORIES_NHK % (params.channel_name, get_api_key(params)), '%s_categories.json' % (params.channel_name)) file_categories = open(file_path).read() json_parser = json.loads(file_categories) for category in json_parser["vod_categories"]: name_category = category["name"].encode('utf-8') category_id = category["category_id"] shows.append({ 'label': name_category, 'url': common.PLUGIN.get_url(module_path=params.module_path, module_name=params.module_name, action='replay_entry', next='list_videos_cat', category_id=category_id, name_category=name_category, window_title=name_category) }) return common.PLUGIN.create_listing( shows, sort_methods=(common.sp.xbmcplugin.SORT_METHOD_UNSORTED, common.sp.xbmcplugin.SORT_METHOD_LABEL), category=common.get_window_title(params))
def root(params): modes = [] if params.channel_name == 'skynews': next_value = 'list_videos_youtube' elif params.channel_name == 'skysports': next_value = 'list_shows_sports' if params.next == "replay_entry": params['next'] = next_value params['page'] = '1' return channel_entry(params) # Add Replay modes.append({ 'label': 'Replay', 'url': common.PLUGIN.get_url( module_path=params.module_path, module_name=params.module_name, action='replay_entry', next=next_value, page='1', category='%s Replay' % params.channel_name.upper(), window_title='%s Replay' % params.channel_name.upper()), }) # Add Live if params.channel_name == 'skynews': modes.append({ 'label': common.GETTEXT('Live TV'), 'url': common.PLUGIN.get_url( module_path=params.module_path, module_name=params.module_name, action='replay_entry', next='live_cat', category='%s Live TV' % params.channel_name.upper(), window_title='%s Live TV' % params.channel_name.upper()), }) return common.PLUGIN.create_listing( modes, sort_methods=(common.sp.xbmcplugin.SORT_METHOD_UNSORTED, common.sp.xbmcplugin.SORT_METHOD_LABEL), category=common.get_window_title(params))
def get_video_url(params): """Get video URL and start video player""" info_video_html = utils.get_webcontent(params.video_url) video_id = re.compile( 'player=7&pod=(.*?)[\"\&]').findall( info_video_html)[0] info_video_json = utils.get_webcontent(INFO_VIDEO % video_id) info_video_json = json.loads(info_video_json) stream_id = re.compile( 'images/(.*).jpg').findall( info_video_json["thumbnail_url_static"])[0].split('/')[1] desired_quality = common.PLUGIN.get_setting('quality') all_datas_videos_quality = [] all_datas_videos_path = [] for quality in QUALITIES_STREAM: all_datas_videos_quality.append(quality) all_datas_videos_path.append( INFO_STREAM % (quality, stream_id)) if desired_quality == "DIALOG": seleted_item = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Choose video quality'), all_datas_videos_quality) if seleted_item == -1: return '' return all_datas_videos_path[seleted_item] elif desired_quality == "BEST": url_best = '' for data_video in all_datas_videos_path: url_best = data_video return url_best else: return all_datas_videos_path[0]
def list_videos(params): """Build videos listing""" videos = [] paged = 1 url_replay_paged = params.url + '&paged=' + str(paged) file_path = utils.download_catalog( url_replay_paged, '%s_%s_%s.html' % (params.channel_name, params.category_name, str(paged))) program_html = open(file_path).read() program_soup = bs(program_html, 'html.parser') videos_soup = program_soup.find_all('div', class_='program sticky video') while len(videos_soup) != 0: for video in videos_soup: info_video = video.find_all('p') video_title = video.find('h3').find( 'a').get_text().encode('utf-8').replace('\n', ' ').replace( '\r', ' ').rstrip('\r\n') + ' - ' + video.find( 'p', class_="red").get_text().encode('utf-8').replace( '\n', ' ').replace('\r', ' ').rstrip('\r\n') video_img = video.find('img')['src'].encode('utf-8') video_id = video.find( 'div', class_="player")['data-id-video'].encode('utf-8') video_duration = 0 video_duration_list = str(info_video[3]).replace( "<p><strong>", '').replace("</strong></p>", '').split(':') if len(video_duration_list) > 2: video_duration = int(video_duration_list[0]) * 3600 + \ int(video_duration_list[1]) * 60 + \ int(video_duration_list[2]) else: video_duration = int(video_duration_list[0]) * 60 + \ int(video_duration_list[1]) # get month and day on the page date_list = str(info_video[2]).replace("<p>", '').replace("</p>", '').split(' ') day = '00' mounth = '00' year = '2017' if len(date_list) > 3: day = date_list[2] try: mounth = CORRECT_MONTH[date_list[3]] except Exception: mounth = '00' # get year ? date = '.'.join((day, mounth, year)) aired = '-'.join((year, mounth, day)) info = { 'video': { 'title': video_title, 'aired': aired, 'date': date, 'duration': video_duration, 'year': year, 'mediatype': 'tvshow' } } download_video = ( common.GETTEXT('Download'), 'XBMC.RunPlugin(' + common.PLUGIN.get_url(action='download_video', module_path=params.module_path, module_name=params.module_name, video_id=video_id) + ')') context_menu = [] context_menu.append(download_video) videos.append({ 'label': video_title, 'thumb': video_img, 'fanart': video_img, 'url': common.PLUGIN.get_url(module_path=params.module_path, module_name=params.module_name, action='replay_entry', next='play_r', video_id=video_id), 'is_playable': True, 'info': info, 'context_menu': context_menu }) paged = paged + 1 url_replay_paged = params.url + '&paged=' + str(paged) file_path = utils.download_catalog( url_replay_paged, '%s_%s_%s.html' % (params.channel_name, params.category_name, str(paged))) program_html = open(file_path).read() program_soup = bs(program_html, 'html.parser') videos_soup = program_soup.find_all('div', class_='program sticky video') return common.PLUGIN.create_listing( videos, sort_methods=(common.sp.xbmcplugin.SORT_METHOD_UNSORTED, common.sp.xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE), content='tvshows', category=common.get_window_title(params))
def list_videos(params): """Build videos listing""" videos = [] if params.next == 'list_videos_1': file_path = utils.get_webcontent(URL_REPLAY) replay_episodes_soup = bs(file_path, 'html.parser') episodes = replay_episodes_soup.find_all( 'div', class_='modal fade replaytv_modal') for episode in episodes: video_title = episode.find('h4', class_='m-t-30').get_text().strip() video_duration = 0 video_plot = episode.find('p').get_text().strip() video_url = episode.find('div', class_='replaytv_video').get('video-src') video_img = '' info = { 'video': { 'title': video_title, # 'aired': aired, # 'date': date, 'duration': video_duration, 'plot': video_plot, # 'year': year, 'mediatype': 'tvshow' } } download_video = ( common.GETTEXT('Download'), 'XBMC.RunPlugin(' + common.PLUGIN.get_url(action='download_video', module_path=params.module_path, module_name=params.module_name, video_url=video_url) + ')') context_menu = [] context_menu.append(download_video) videos.append({ 'label': video_title, 'thumb': video_img, 'fanart': video_img, 'url': common.PLUGIN.get_url(module_path=params.module_path, module_name=params.module_name, action='replay_entry', next='play_r', video_url=video_url), 'is_playable': True, 'info': info, 'context_menu': context_menu }) return common.PLUGIN.create_listing( videos, sort_methods=(common.sp.xbmcplugin.SORT_METHOD_UNSORTED, common.sp.xbmcplugin.SORT_METHOD_DURATION, common.sp.xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE, common.sp.xbmcplugin.SORT_METHOD_GENRE, common.sp.xbmcplugin.SORT_METHOD_UNSORTED), content='tvshows', category=common.get_window_title())
def list_videos(params): """Build videos listing""" videos = [] if 'previous_listing' in params: videos = ast.literal_eval(params['previous_listing']) if params.next == 'list_videos_1': list_videos_html = utils.get_webcontent(params.category_url + '?lim_un=%s' % params.page) list_videos_soup = bs(list_videos_html, 'html.parser') videos_data = list_videos_soup.find_all( 'article', class_=re.compile("emmissionsboxtop")) for video in videos_data: title = video.find('h3').get_text() plot = '' duration = 0 img = video.find('img').get('src') video_url = video.find('a').get('href') info = { 'video': { 'title': title, 'plot': plot, # 'aired': aired, # 'date': date, 'duration': duration, # 'year': year, 'mediatype': 'tvshow' } } download_video = ( common.GETTEXT('Download'), 'XBMC.RunPlugin(' + common.PLUGIN.get_url(action='download_video', module_path=params.module_path, module_name=params.module_name, video_url=video_url) + ')') context_menu = [] context_menu.append(download_video) videos.append({ 'label': title, 'thumb': img, 'url': common.PLUGIN.get_url( module_path=params.module_path, module_name=params.module_name, action='replay_entry', next='play_r', video_url=video_url, ), 'is_playable': True, 'info': info, 'context_menu': context_menu }) # More videos... videos.append({ 'label': common.ADDON.get_localized_string(30700), 'url': common.PLUGIN.get_url(module_path=params.module_path, module_name=params.module_name, action='replay_entry', next='list_videos_1', category_url=params.category_url, page=str(int(params.page) + 12), update_listing=True, previous_listing=str(videos)) }) return common.PLUGIN.create_listing( videos, sort_methods=(common.sp.xbmcplugin.SORT_METHOD_UNSORTED), content='tvshows', update_listing='update_listing' in params, category=common.get_window_title(params))
def get_video_url(params): """Get video URL and start video player""" if params.next == 'play_l': session_requests = requests.session() lives_datas_json = session_requests.get(URL_LIVE_DATAS % params.channel_name) lives_datas_jsonparser = json.loads(lives_datas_json.text) root = '' if lives_datas_jsonparser["locations"][0]["ask"] is not None: lives_stream_json = session_requests.post( URL_LIVE_STREAM % lives_datas_jsonparser["locations"][0]["ask"]) lives_stream_jsonparser = json.loads(lives_stream_json.text) url_stream_without_hash = lives_stream_jsonparser["stream_manifest"] lives_hash_json = session_requests.post( URL_LIVE_HASH, data='{"gcp": "%s"}' % (lives_datas_jsonparser["locations"][0]["gcp"]), headers={'Connection': 'keep-alive', 'Content-type': 'application/json'}) lives_hash_jsonparser = json.loads(lives_hash_json.text) if 'message' in lives_hash_jsonparser: if 'geoblocked' in lives_hash_jsonparser['message']: utils.send_notification( common.ADDON.get_localized_string(30713)) return None m3u8_video_auto = session_requests.get(url_stream_without_hash + '&' + lives_hash_jsonparser["suffix"]) else: lives_stream_json = session_requests.post( URL_LIVE_HASH, data='{"gcp": "%s"}' % (lives_datas_jsonparser["locations"][0]["gcp"]), headers={'Connection': 'keep-alive', 'Content-type': 'application/json'}) lives_stream_jsonparser = json.loads(lives_stream_json.text) if 'message' in lives_stream_jsonparser: if 'geoblocked' in lives_stream_jsonparser['message']: utils.send_notification( common.ADDON.get_localized_string(30713)) return None m3u8_video_auto = session_requests.get(lives_stream_jsonparser["stream"]) root = lives_stream_jsonparser["stream"].split('master.m3u8')[0] lines = m3u8_video_auto.text.splitlines() if DESIRED_QUALITY == "DIALOG": all_datas_videos_quality = [] all_datas_videos_path = [] for k in range(0, len(lines) - 1): if 'RESOLUTION=' in lines[k]: all_datas_videos_quality.append( lines[k].split('RESOLUTION=')[1]) if 'http' in lines[k + 1]: all_datas_videos_path.append( lines[k + 1]) else: all_datas_videos_path.append( root + '/' + lines[k + 1]) seleted_item = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Choose video quality'), all_datas_videos_quality) if seleted_item > -1: return all_datas_videos_path[seleted_item].encode( 'utf-8') else: return None elif DESIRED_QUALITY == 'BEST': # Last video in the Best for k in range(0, len(lines) - 1): if 'RESOLUTION=' in lines[k]: if 'http' in lines[k + 1]: url = lines[k + 1] else: url = root + '/' + lines[k + 1] return url else: for k in range(0, len(lines) - 1): if 'RESOLUTION=' in lines[k]: if 'http' in lines[k + 1]: url = lines[k + 1] else: url = root + '/' + lines[k + 1] break return url