def _show_only_forced_subtitle(self):
     # Forced stream not found, then fix Kodi bug if user chose to apply the workaround
     # Kodi bug???:
     # If the kodi player is set with "forced only" subtitle setting, Kodi use this behavior:
     # 1) try to select forced subtitle that matches audio language
     # 2) if missing the forced subtitle in language, then
     #    Kodi try to select: The first "forced" subtitle or the first "regular" subtitle
     #    that can respect the chosen language or not, depends on the available streams
     # So can cause a wrong subtitle language or in a permanent display of subtitles!
     # This does not reflect the setting chosen in the Kodi player and is very annoying!
     # There is no other solution than to disable the subtitles manually.
     audio_language = common.get_kodi_audio_language()
     if self.legacy_kodi_version:
         # --- ONLY FOR KODI VERSION 18 ---
         # NOTE: With Kodi 18 it is not possible to read the properties of the streams
         # so the only possible way is to read the data from the manifest file
         manifest_data = json.loads(common.load_file('manifest.json'))
         common.fix_locale_languages(manifest_data['timedtexttracks'])
         if not any(
                 text_track.get('isForcedNarrative', False) is True
                 and text_track['language'] == audio_language
                 for text_track in manifest_data['timedtexttracks']):
             self.sc_settings.update({'subtitleenabled': False})
     else:
         # --- ONLY FOR KODI VERSION 19 ---
         # Check the current stream
         player_stream = self.player_state.get(
             STREAMS['subtitle']['current'])
         if not player_stream[
                 'isforced'] or player_stream['language'] != audio_language:
             self.sc_settings.update({'subtitleenabled': False})
 def __init__(self):
     # pylint: disable=broad-except
     try:
         msl_data = json.loads(common.load_file('msl_data.json'))
         self.request_builder = MSLRequestBuilder(msl_data)
         common.debug('Loaded MSL data from disk')
     except Exception:
         import traceback
         common.debug(traceback.format_exc())
         common.debug('Stored MSL data expired or not available')
         self.request_builder = MSLRequestBuilder()
         if self.perform_key_handshake():
             self.request_builder = MSLRequestBuilder(
                 json.loads(common.load_file('msl_data.json')))
             common.debug('Loaded renewed MSL data from disk')
     common.register_slot(signal=common.Signals.ESN_CHANGED,
                          callback=self.perform_key_handshake)
Example #3
0
 def _init_msl_handler(self):
     self.msl_requests = None
     try:
         msl_data = json.loads(common.load_file(MSL_DATA_FILENAME))
         common.info('Loaded MSL data from disk')
     except Exception:  # pylint: disable=broad-except
         msl_data = None
     self.msl_requests = MSLRequests(msl_data)
     self.switch_events_handler()
Example #4
0
def _show_only_forced_subtitle():
    # When we have "forced only" subtitle setting in Kodi Player, Kodi use this behavior:
    # 1) try to select forced subtitle that matches audio language
    # 2) when missing, try to select the first "regular" subtitle that matches audio language
    # This Kodi behavior is totally non sense.
    # If forced is selected you must not view the regular subtitles
    # There is no other solution than to disable the subtitles manually.
    manifest_data = json.loads(common.load_file('manifest.json'))
    common.fix_locale_languages(manifest_data['timedtexttracks'])
    audio_language = common.get_kodi_audio_language()
    if not any(
            text_track.get('isForcedNarrative', False) is True
            and text_track['language'] == audio_language
            for text_track in manifest_data['timedtexttracks']):
        xbmc.Player().showSubtitles(False)
Example #5
0
    def __init__(self):
        super(MSLHandler, self).__init__()
        self.msl_requests = None
        try:
            msl_data = json.loads(common.load_file('msl_data.json'))
            common.info('Loaded MSL data from disk')
        except Exception:  # pylint: disable=broad-except
            msl_data = None

        self.msl_requests = MSLRequests(msl_data)

        EventsHandler(self.msl_requests.chunked_request).start()

        common.register_slot(signal=common.Signals.ESN_CHANGED,
                             callback=self.msl_requests.perform_key_handshake)
        common.register_slot(signal=common.Signals.RELEASE_LICENSE,
                             callback=self.release_license)
Example #6
0
 def __init__(self):
     # pylint: disable=broad-except
     self.request_builder = None
     try:
         msl_data = json.loads(common.load_file('msl_data.json'))
         common.info('Loaded MSL data from disk')
     except Exception:
         msl_data = None
     try:
         self.request_builder = MSLRequestBuilder(msl_data)
         # Addon just installed, the service starts but there is no esn
         if g.get_esn():
             self.check_mastertoken_validity()
     except Exception:
         import traceback
         common.error(traceback.format_exc())
     common.register_slot(signal=common.Signals.ESN_CHANGED,
                          callback=self.perform_key_handshake)
 def check_mastertoken_validity(self):
     """Return the mastertoken validity and executes a new key handshake when necessary"""
     if self.request_builder.crypto.mastertoken:
         time_now = time.time()
         renewable = self.request_builder.crypto.renewal_window < time_now
         expired = self.request_builder.crypto.expiration <= time_now
     else:
         renewable = False
         expired = True
     if expired:
         if not self.request_builder.crypto.mastertoken:
             common.debug('Stored MSL data not available, a new key handshake will be performed')
             self.request_builder = MSLRequestBuilder()
         else:
             common.debug('Stored MSL data is expired, a new key handshake will be performed')
         if self.perform_key_handshake():
             self.request_builder = MSLRequestBuilder(json.loads(
                 common.load_file('msl_data.json')))
         return self.check_mastertoken_validity()
     return {'renewable': renewable, 'expired': expired}
 def import_videoid_from_existing_strm(self, folder_path, folder_name):
     """
     Get a VideoId from an existing STRM file that was exported
     """
     for filename in common.list_dir(folder_path)[1]:
         filename = G.py2_decode(filename)
         if not filename.endswith('.strm'):
             continue
         file_path = common.join_folders_paths(folder_path, filename)
         # Only get a VideoId from the first file in each folder.
         # For tv shows all episodes will result in the same VideoId, the movies only contain one file.
         file_content = common.load_file(file_path)
         if not file_content:
             common.warn('Import error: folder "{}" skipped, STRM file empty or corrupted', folder_name)
             return None
         if 'action=play_video' in file_content:
             common.debug('Trying to import (v0.13.x): {}', file_path)
             return self._import_videoid_old(file_content, folder_name)
         common.debug('Trying to import: {}', file_path)
         return self._import_videoid(file_content, folder_name)
Example #9
0
 def _check_mastertoken_validity(self):
     """Return the mastertoken validity and executes a new key handshake when necessary"""
     if self.crypto.mastertoken:
         time_now = time()
         renewable = self.crypto.renewal_window < time_now
         expired = self.crypto.expiration <= time_now
     else:
         renewable = False
         expired = True
     if expired:
         if not self.crypto.mastertoken:
             debug_msg = 'Stored MSL data not available, a new key handshake will be performed'
         else:
             debug_msg = 'Stored MSL data is expired, a new key handshake will be performed'
         common.debug(debug_msg)
         if self.perform_key_handshake():
             msl_data = json.loads(common.load_file(MSL_DATA_FILENAME))
             self.crypto.load_msl_data(msl_data)
             self.crypto.load_crypto_session(msl_data)
         return self._check_mastertoken_validity()
     return {'renewable': renewable, 'expired': expired}
Example #10
0
 def _mastertoken_checks(self):
     """Perform checks to the MasterToken and executes a new key handshake when necessary"""
     is_handshake_required = False
     if self.crypto.mastertoken:
         if self.crypto.is_current_mastertoken_expired():
             common.debug('Stored MSL MasterToken is expired, a new key handshake will be performed')
             is_handshake_required = True
         else:
             # Check if the current ESN is same of ESN bound to MasterToken
             if g.get_esn() != self.crypto.bound_esn:
                 common.debug('Stored MSL MasterToken is bound to a different ESN, '
                              'a new key handshake will be performed')
                 is_handshake_required = True
     else:
         common.debug('MSL MasterToken is not available, a new key handshake will be performed')
         is_handshake_required = True
     if is_handshake_required:
         if self.perform_key_handshake():
             msl_data = json.loads(common.load_file(MSL_DATA_FILENAME))
             self.crypto.load_msl_data(msl_data)
             self.crypto.load_crypto_session(msl_data)