def render_guide_div_template( self, is_server_secure, authorization_required, client_ip_address, client_uuid, guide_number_of_days, guide_provider, guide_group, active_providers_map_class, ): client_ip_address_type = Utility.determine_ip_address_type( client_ip_address) yield self._environment.get_template('guide_div_header.html').render() for rendered_guide_li_template in self._render_guide_lis_template( is_server_secure, authorization_required, client_ip_address_type, client_uuid, guide_number_of_days, guide_provider, guide_group, active_providers_map_class, ): yield rendered_guide_li_template yield self._environment.get_template('guide_div_footer.html').render()
def generate_playlist_m3u8(cls, is_server_secure, client_ip_address, client_uuid, requested_query_string_parameters, providers): http_token = requested_query_string_parameters.get('http_token') playlist_protocol = requested_query_string_parameters.get('protocol') playlist_type = requested_query_string_parameters.get('type') try: client_ip_address_type = Utility.determine_ip_address_type( client_ip_address) server_hostname = Configuration.get_configuration_parameter( 'SERVER_HOSTNAME_{0}'.format(client_ip_address_type.value)) server_port = Configuration.get_configuration_parameter( 'SERVER_HTTP{0}_PORT'.format('S' if is_server_secure else '')) playlist_m3u8 = [ '#EXTM3U x-tvg-url="{0}://{1}:{2}/live/epg.xml"\n'.format( 'https' if is_server_secure else 'http', server_hostname, server_port) ] for (provider_name, provider) in sorted(list(providers.items())): provider_protocol = playlist_protocol provider_type = playlist_type try: provider_protocol = requested_query_string_parameters[ '{0}_protocol'.format(provider_name)] except KeyError: pass try: provider_type = requested_query_string_parameters[ '{0}_type'.format(provider_name)] except KeyError: pass generate_playlist_m3u8_tracks_mapping = dict( client_uuid=client_uuid, http_token=http_token, is_server_secure=is_server_secure, playlist_protocol=provider_protocol, playlist_type=provider_type, server_hostname=server_hostname, server_port=server_port) playlist_m3u8.append(''.join( provider.api_class().generate_playlist_m3u8_tracks( generate_playlist_m3u8_tracks_mapping))) logger.debug('Generated live IPTVProxy playlist.m3u8') return ''.join(playlist_m3u8) except (KeyError, ValueError): (status, value_, traceback_) = sys.exc_info() logger.error('\n'.join( traceback.format_exception(status, value_, traceback_)))
def generate_xmltv(cls, is_server_secure, authorization_required, client_ip_address, providers_map_class, number_of_days, style): current_date_time_in_utc = datetime.now(pytz.utc) yield '<?xml version="1.0" encoding="utf-8"?>\n<tv date="{0}" generator-info-name="IPTVProxy {1}">\n'.format( current_date_time_in_utc.strftime('%Y%m%d%H%M%S %z'), VERSION) client_ip_address_type = Utility.determine_ip_address_type(client_ip_address) server_password = Configuration.get_configuration_parameter('SERVER_PASSWORD') server_hostname = Configuration.get_configuration_parameter( 'SERVER_HOSTNAME_{0}'.format(client_ip_address_type.value)) server_port = Configuration.get_configuration_parameter( 'SERVER_HTTP{0}_PORT'.format('S' if is_server_secure else '')) cutoff_date_time_in_local = datetime.now(tzlocal.get_localzone()).replace( hour=0, minute=0, second=0, microsecond=0) + timedelta(days=int(number_of_days) + 1) cutoff_date_time_in_utc = cutoff_date_time_in_local.astimezone(pytz.utc) for provider_map_class in providers_map_class.values(): with provider_map_class.database_class().get_access_lock().shared_lock: db_session = provider_map_class.database_class().create_session() try: if style.capitalize() == EPGStyle.COMPLETE.value: query_channels_xmltv = provider_map_class.database_access_class().query_channels_complete_xmltv query_programs_xmltv = provider_map_class.database_access_class().query_programs_complete_xmltv else: query_channels_xmltv = provider_map_class.database_access_class().query_channels_minimal_xmltv query_programs_xmltv = provider_map_class.database_access_class().query_programs_minimal_xmltv for channel_row in query_channels_xmltv(db_session): yield channel_row.xmltv.format( 's' if is_server_secure else '', server_hostname, server_port, '?http_token={0}'.format(server_password) if authorization_required else '') for program_row in query_programs_xmltv(db_session, cutoff_date_time_in_utc): yield program_row.xmltv finally: db_session.close() yield '</tv>\n'
def generate_vod_index_playlist_m3u8(cls, is_server_secure, client_ip_address, client_uuid, http_token): playlist_m3u8 = [] client_ip_address_type = Utility.determine_ip_address_type( client_ip_address) server_hostname = Configuration.get_configuration_parameter( 'SERVER_HOSTNAME_{0}'.format(client_ip_address_type.value)) server_port = Configuration.get_configuration_parameter( 'SERVER_HTTP{0}_PORT'.format('S' if is_server_secure else '')) db_session = Database.create_session() try: for persistent_recording in DatabaseAccess.query_persisted_recordings( db_session): playlist_m3u8.append( '#EXTINF:-1,{0} - [{1} - {2}]\n' '{3}\n'.format( persistent_recording.program_title, persistent_recording.start_date_time_in_utc.astimezone( tzlocal.get_localzone()).strftime( '%Y-%m-%d %H:%M:%S%z'), persistent_recording.end_date_time_in_utc.astimezone( tzlocal.get_localzone()).strftime( '%Y-%m-%d %H:%M:%S%z'), cls.generate_vod_recording_playlist_url( is_server_secure, server_hostname, server_port, client_uuid, persistent_recording.id, http_token, ), )) finally: db_session.close() if playlist_m3u8: playlist_m3u8 = '#EXTM3U\n{0}'.format(''.join(playlist_m3u8)) logger.debug('Generated VOD playlist.m3u8') else: logger.debug( 'No persistent recordings found. VOD playlist.m3u8 will not be generated' ) return playlist_m3u8
def render_index_template( self, is_server_secure, authorization_required, client_ip_address, client_uuid, guide_number_of_days, guide_provider, guide_group, streaming_protocol, active_providers_map_class, ): client_ip_address_type = Utility.determine_ip_address_type( client_ip_address) server_hostname = self._configuration['SERVER_HOSTNAME_{0}'.format( client_ip_address_type.value)] server_http_port = self._configuration['SERVER_HTTP_PORT'] server_https_port = self._configuration['SERVER_HTTPS_PORT'] yield self._environment.get_template('index_header.html').render() yield self._render_head_template(authorization_required, guide_number_of_days, streaming_protocol) yield self._environment.get_template('body_header.html').render() yield self._render_navigation_bar_div_template( guide_provider, guide_group, active_providers_map_class) yield self._render_settings_div_template(guide_number_of_days, streaming_protocol) yield self._environment.get_template('loading_div.html').render() yield self._environment.get_template( 'content_div_header.html').render() yield self._environment.get_template('guide_div_header.html').render() for rendered_guide_li_template in self._render_guide_lis_template( is_server_secure, authorization_required, client_ip_address_type, client_uuid, guide_number_of_days, guide_provider, guide_group, active_providers_map_class, ): yield rendered_guide_li_template yield self._environment.get_template('guide_div_footer.html').render() yield self._environment.get_template('video_div.html').render() yield self._render_recordings_div_template( is_server_secure, authorization_required, client_uuid, server_hostname, server_https_port if is_server_secure else server_http_port, ) yield self._render_configuration_div_template( active_providers_map_class) yield self._environment.get_template('monitor_div.html').render() yield self._render_about_div_template() yield self._environment.get_template( 'content_div_footer.html').render() yield self._environment.get_template('body_footer.html').render() yield self._environment.get_template('index_footer.html').render()