コード例 #1
0
 def clear_token(self):
     """ Remove the cached JWT. """
     _LOGGER.debug('Clearing token cache')
     path = os.path.join(self._token_path, self.TOKEN_FILE)
     if kodiutils.exists(path):
         kodiutils.delete(path)
     self._account = AccountStorage()
コード例 #2
0
    def _delay_subtitles(self, subtitles, json_manifest):
        """ Modify the subtitles timings to account for ad breaks.
        :type subtitles: list[string]
        :type json_manifest: dict
        :rtype list[str]
        """
        # Clean up old subtitles
        temp_dir = os.path.join(kodiutils.addon_profile(), 'temp', '')
        _, files = kodiutils.listdir(temp_dir)
        if files:
            for item in files:
                if kodiutils.to_unicode(item).endswith('.vtt'):
                    kodiutils.delete(temp_dir + kodiutils.to_unicode(item))

        # Return if there are no subtitles available
        if not subtitles:
            return None

        import re
        if not kodiutils.exists(temp_dir):
            kodiutils.mkdirs(temp_dir)

        ad_breaks = list()
        delayed_subtitles = list()
        webvtt_timing_regex = re.compile(
            r'\n(\d{2}:\d{2}:\d{2}\.\d{3}) --> (\d{2}:\d{2}:\d{2}\.\d{3})\s')

        # Get advertising breaks info from json manifest
        cues = json_manifest.get('interstitials').get('cues')
        for cue in cues:
            ad_breaks.append(
                dict(start=cue.get('start'),
                     duration=cue.get('break_duration')))

        for subtitle in subtitles:
            output_file = temp_dir + subtitle.get('name') + '.' + subtitle.get(
                'url').split('.')[-1]
            webvtt_content = util.http_get(subtitle.get('url')).text
            webvtt_content = webvtt_timing_regex.sub(
                lambda match: self._delay_webvtt_timing(match, ad_breaks),
                webvtt_content)
            with kodiutils.open_file(output_file, 'w') as webvtt_output:
                webvtt_output.write(kodiutils.from_unicode(webvtt_content))
            delayed_subtitles.append(output_file)
        return delayed_subtitles
コード例 #3
0
    def clean():
        """ Clear metadata (called from settings) """
        cache_path = kodiutils.get_cache_path()
        _, files = kodiutils.listdir(cache_path)
        for filename in files:
            if not kodiutils.delete(os.path.join(cache_path, filename)):
                return kodiutils.ok_dialog(message=kodiutils.localize(
                    30721))  # Clearing local metadata failed

        kodiutils.set_setting('metadata_last_updated', '0')
        return kodiutils.ok_dialog(
            message=kodiutils.localize(30714))  # Local metadata is cleared
コード例 #4
0
    def _download_subtitles(subtitles):
        # Clean up old subtitles
        temp_dir = os.path.join(kodiutils.addon_profile(), 'temp', '')
        _, files = kodiutils.listdir(temp_dir)
        if files:
            for item in files:
                kodiutils.delete(temp_dir + kodiutils.to_unicode(item))

        # Return if there are no subtitles available
        if not subtitles:
            return None

        if not kodiutils.exists(temp_dir):
            kodiutils.mkdirs(temp_dir)

        downloaded_subtitles = list()
        for subtitle in subtitles:
            output_file = temp_dir + subtitle.get('name')
            webvtt_content = util.http_get(subtitle.get('url')).text
            with kodiutils.open_file(output_file, 'w') as webvtt_output:
                webvtt_output.write(kodiutils.from_unicode(webvtt_content))
            downloaded_subtitles.append(output_file)
        return downloaded_subtitles