<commit_before># -*- coding: utf-8 -*-
"""
    Copyright (C) 2017 <NAME> (plugin.video.netflix)
    Functions for starting the service

    SPDX-License-Identifier: MIT
    See LICENSES/MIT.md for more information.
"""
from __future__ import absolute_import, division, unicode_literals

import threading

from xbmcgui import Window

# Global cache must not be used within these modules, because stale values may
# be used and cause inconsistencies!
from resources.lib.common import (info, error, select_port, get_local_string,
                                  get_current_kodi_profile_name)
from resources.lib.globals import g
from resources.lib.upgrade_controller import check_service_upgrade

try:  # Python 2
    unicode
except NameError:  # Python 3
    unicode = str  # pylint: disable=redefined-builtin


class NetflixService(object):
    """
    Netflix addon service
    """
    from resources.lib.services.msl.http_server import MSLTCPServer
    from resources.lib.services.nfsession.http_server import NetflixTCPServer
    # Do not change the init order of the servers,
    # MSLTCPServer must always be initialized first to get the DRM info
    SERVERS = [
        {
            'name': 'MSL',
            'class': MSLTCPServer,
            'instance': None,
            'thread': None},
        {
            'name': 'NS',
            'class': NetflixTCPServer,
            'instance': None,
            'thread': None},
    ]

    def __init__(self):
        self.window_cls = Window(10000)  # Kodi home window
        # If you use multiple Kodi profiles you need to distinguish the property of current profile
        self.prop_nf_service_status = g.py2_encode('nf_service_status_' + get_current_kodi_profile_name())
        for server in self.SERVERS:
            self.init_server(server)
        self.controller = None
        self.library_updater = None
        self.settings_monitor = None

    def init_server(self, server):
        server['class'].allow_reuse_address = True
        server['instance'] = server['class'](
            ('localhost', select_port(server['name'])))
        server['thread'] = threading.Thread(
            target=server['instance'].serve_forever)

    def start_services(self):
        """
        Start the background services
        """
        from resources.lib.services.playback.controller import PlaybackController
        from resources.lib.services.library_updater import LibraryUpdateService
        from resources.lib.services.settings_monitor import SettingsMonitor
        for server in self.SERVERS:
            server['instance'].server_activate()
            server['instance'].timeout = 1
            server['thread'].start()
            info('[{}] Thread started'.format(server['name']))
        self.controller = PlaybackController()
        self.library_updater = LibraryUpdateService()
        self.settings_monitor = SettingsMonitor()
        # Mark the service as active
        self.window_cls.setProperty(self.prop_nf_service_status, 'running')
        if not g.ADDON.getSettingBool('disable_startup_notification'):
            from resources.lib.kodi.ui import show_notification
            show_notification(get_local_string(30110))
<commit_msg>Revert "Use localhost instead force IPv4 loopback"<commit_after># -*- coding: utf-8 -*-
"""
    Copyright (C) 2017 <NAME> (plugin.video.netflix)
    Functions for starting the service

    SPDX-License-Identifier: MIT
    See LICENSES/MIT.md for more information.
"""
from __future__ import absolute_import, division, unicode_literals

import threading

from xbmcgui import Window

# Global cache must not be used within these modules, because stale values may
# be used and cause inconsistencies!
from resources.lib.common import (info, error, select_port, get_local_string,
                                  get_current_kodi_profile_name)
from resources.lib.globals import g
from resources.lib.upgrade_controller import check_service_upgrade

try:  # Python 2
    unicode
except NameError:  # Python 3
    unicode = str  # pylint: disable=redefined-builtin


class NetflixService(object):
    """
    Netflix addon service
    """
    from resources.lib.services.msl.http_server import MSLTCPServer
    from resources.lib.services.nfsession.http_server import NetflixTCPServer
    # Do not change the init order of the servers,
    # MSLTCPServer must always be initialized first to get the DRM info
    SERVERS = [
        {
            'name': 'MSL',
            'class': MSLTCPServer,
            'instance': None,
            'thread': None},
        {
            'name': 'NS',
            'class': NetflixTCPServer,
            'instance': None,
            'thread': None},
    ]

    def __init__(self):
        self.window_cls = Window(10000)  # Kodi home window
        # If you use multiple Kodi profiles you need to distinguish the property of current profile
        self.prop_nf_service_status = g.py2_encode('nf_service_status_' + get_current_kodi_profile_name())
        for server in self.SERVERS:
            self.init_server(server)
        self.controller = None
        self.library_updater = None
        self.settings_monitor = None

    def init_server(self, server):
        server['class'].allow_reuse_address = True
        server['instance'] = server['class'](
            ('127.0.0.1', select_port(server['name'])))
        server['thread'] = threading.Thread(
            target=server['instance'].serve_forever)

    def start_services(self):
        """
        Start the background services
        """
        from resources.lib.services.playback.controller import PlaybackController
        from resources.lib.services.library_updater import LibraryUpdateService
        from resources.lib.services.settings_monitor import SettingsMonitor
        for server in self.SERVERS:
            server['instance'].server_activate()
            server['instance'].timeout = 1
            server['thread'].start()
            info('[{}] Thread started'.format(server['name']))
        self.controller = PlaybackController()
        self.library_updater = LibraryUpdateService()
        self.settings_monitor = SettingsMonitor()
        # Mark the service as active
        self.window_cls.setProperty(self.prop_nf_service_status, 'running')
        if not g.ADDON.getSettingBool('disable_startup_notification'):
            from resources.lib.kodi.ui import show_notification
            show_notification(get_local_string(30110))

{'fraction_non_alphanumeric': 0.0899830220713073, 'fraction_numerical': 0.0069455162833770645, 'mean_word_length': 2.7850467289719627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3839360', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1714, 'n_words': 458}