Example #1
0
    def fix_subtitles_codes(self):

        sql_results = self.connection.select(
            "SELECT subtitles, episode_id FROM tv_episodes WHERE subtitles != '' AND subtitles_lastsearch < ?;",
            [datetime.datetime(2015, 7, 15, 17, 20, 44, 326380).strftime(dateTimeFormat)]
        )

        if not sql_results:
            return

        for sql_result in sql_results:
            langs = []

            log.debug(u'Checking subtitle codes for episode_id: {0!s},'
                      u' codes: {1!s}', sql_result['episode_id'],
                      sql_result['subtitles'])

            for subcode in sql_result['subtitles'].split(','):
                if not len(subcode) == 3 or subcode not in subtitles.subtitle_code_filter():
                    log.debug(u'Fixing subtitle codes for episode_id: {0!s},'
                              u' invalid code: {1!s}',
                              sql_result['episode_id'], subcode)
                    continue

                langs.append(subcode)

            self.connection.action('UPDATE tv_episodes SET subtitles = ?, subtitles_lastsearch = ? WHERE episode_id = ?;',
                                   [','.join(langs), datetime.datetime.now().strftime(dateTimeFormat), sql_result['episode_id']])
Example #2
0
    def fix_subtitles_codes(self):

        sql_results = self.connection.select(
            "SELECT subtitles, episode_id FROM tv_episodes WHERE subtitles != '' AND subtitles_lastsearch < ?;",
            [datetime.datetime(2015, 7, 15, 17, 20, 44, 326380).strftime(dateTimeFormat)]
        )

        if not sql_results:
            return

        for sql_result in sql_results:
            langs = []

            log.debug(u'Checking subtitle codes for episode_id: {0!s},'
                      u' codes: {1!s}', sql_result['episode_id'],
                      sql_result['subtitles'])

            for subcode in sql_result['subtitles'].split(','):
                if not len(subcode) == 3 or subcode not in subtitles.subtitle_code_filter():
                    log.debug(u'Fixing subtitle codes for episode_id: {0!s},'
                              u' invalid code: {1!s}',
                              sql_result['episode_id'], subcode)
                    continue

                langs.append(subcode)

            self.connection.action('UPDATE tv_episodes SET subtitles = ?, subtitles_lastsearch = ? WHERE episode_id = ?;',
                                   [','.join(langs), datetime.datetime.now().strftime(dateTimeFormat), sql_result['episode_id']])
Example #3
0
def config_subtitles():
    return {
        'enabled':
        bool(app.USE_SUBTITLES),
        'languages':
        app.SUBTITLES_LANGUAGES,
        'wantedLanguages': [{
            'id': code,
            'name': name_from_code(code)
        } for code in wanted_languages()],
        'codeFilter': [{
            'id': code,
            'name': name_from_code(code)
        } for code in subtitle_code_filter()],
        'services':
        app.SUBTITLE_SERVICES,
        'stopAtFirst':
        bool(app.SUBTITLES_STOP_AT_FIRST),
        'eraseCache':
        bool(app.SUBTITLES_ERASE_CACHE),
        'location':
        app.SUBTITLES_DIR,
        'finderFrequency':
        int(app.SUBTITLES_FINDER_FREQUENCY),
        'perfectMatch':
        bool(app.SUBTITLES_PERFECT_MATCH),
        'logHistory':
        bool(app.SUBTITLES_HISTORY),
        'multiLanguage':
        bool(app.SUBTITLES_MULTI),
        'keepOnlyWanted':
        bool(app.SUBTITLES_KEEP_ONLY_WANTED),
        'ignoreEmbeddedSubs':
        bool(app.IGNORE_EMBEDDED_SUBS),
        'acceptUnknownEmbeddedSubs':
        bool(app.ACCEPT_UNKNOWN_EMBEDDED_SUBS),
        'hearingImpaired':
        bool(app.SUBTITLES_HEARING_IMPAIRED),
        'preScripts':
        app.SUBTITLES_PRE_SCRIPTS,
        'extraScripts':
        app.SUBTITLES_EXTRA_SCRIPTS,
        'wikiUrl':
        app.SUBTITLES_URL,
        'providerLogins': {
            'addic7ed': {
                'user': app.ADDIC7ED_USER,
                'pass': app.ADDIC7ED_PASS
            },
            'legendastv': {
                'user': app.LEGENDASTV_USER,
                'pass': app.LEGENDASTV_PASS
            },
            'opensubtitles': {
                'user': app.OPENSUBTITLES_USER,
                'pass': app.OPENSUBTITLES_PASS
            }
        }
    }
Example #4
0
    def resource_search_missing_subtitles(self):
        """
        Search missing subtitles for multiple episodes at once.

        example: Pass the following structure:
            language: 'all', // Or a three letter language code.
            shows: [
                {
                    'slug': 'tvdb1234',
                    'episodes': ['s01e01', 's02e03', 's10e10']
                },
            ]
        """
        data = json_decode(self.request.body)
        language = data.get('language', 'all')
        shows = data.get('shows', [])

        if language != 'all' and language not in subtitle_code_filter():
            return self._bad_request(
                'You need to provide a valid subtitle code')

        for show in shows:
            # Loop through the shows. Each show should have an array of episode slugs
            series_identifier = SeriesIdentifier.from_slug(show.get('slug'))
            if not series_identifier:
                log.warning(
                    'Could not create a show identifier with slug {slug}',
                    {'slug': show.get('slug')})
                continue

            series = Series.find_by_identifier(series_identifier)
            if not series:
                log.warning(
                    'Could not match to a show in the library with slug {slug}',
                    {'slug': show.get('slug')})
                continue

            for episode_slug in show.get('episodes', []):
                episode_number = EpisodeNumber.from_slug(episode_slug)
                if not episode_number:
                    log.warning('Bad episode number from slug {slug}',
                                {'slug': episode_slug})
                    continue

                episode = Episode.find_by_series_and_episode(
                    series, episode_number)
                if not episode:
                    log.warning('Episode not found with slug {slug}',
                                {'slug': episode_slug})

                episode.download_subtitles(
                    lang=language if language != 'all' else None)

        return self._ok()
Example #5
0
    def saveSubtitles(self,
                      use_subtitles=None,
                      subtitles_plugins=None,
                      subtitles_languages=None,
                      subtitles_dir=None,
                      subtitles_perfect_match=None,
                      service_order=None,
                      subtitles_history=None,
                      subtitles_finder_frequency=None,
                      subtitles_erase_cache=None,
                      subtitles_multi=None,
                      embedded_subtitles_all=None,
                      subtitles_extra_scripts=None,
                      subtitles_pre_scripts=None,
                      subtitles_hearing_impaired=None,
                      addic7ed_user=None,
                      addic7ed_pass=None,
                      legendastv_user=None,
                      legendastv_pass=None,
                      opensubtitles_user=None,
                      opensubtitles_pass=None,
                      subtitles_keep_only_wanted=None,
                      embedded_subtitles_unknown_lang=None,
                      subtitles_stop_at_first=None):
        """
        Save Subtitle Search related settings
        """
        results = []

        config.change_SUBTITLES_FINDER_FREQUENCY(subtitles_finder_frequency)
        config.change_USE_SUBTITLES(use_subtitles)
        app.SUBTITLES_ERASE_CACHE = config.checkbox_to_value(
            subtitles_erase_cache)
        app.SUBTITLES_LANGUAGES = [
            code.strip() for code in subtitles_languages.split(',')
            if code.strip() in subtitles.subtitle_code_filter()
        ] if subtitles_languages else []
        app.SUBTITLES_DIR = subtitles_dir
        app.SUBTITLES_PERFECT_MATCH = config.checkbox_to_value(
            subtitles_perfect_match)
        app.SUBTITLES_HISTORY = config.checkbox_to_value(subtitles_history)
        app.IGNORE_EMBEDDED_SUBS = config.checkbox_to_value(
            embedded_subtitles_all)
        app.ACCEPT_UNKNOWN_EMBEDDED_SUBS = config.checkbox_to_value(
            embedded_subtitles_unknown_lang)
        app.SUBTITLES_STOP_AT_FIRST = config.checkbox_to_value(
            subtitles_stop_at_first)
        app.SUBTITLES_HEARING_IMPAIRED = config.checkbox_to_value(
            subtitles_hearing_impaired)
        app.SUBTITLES_MULTI = 1 if len(
            app.SUBTITLES_LANGUAGES) > 1 else config.checkbox_to_value(
                subtitles_multi)
        app.SUBTITLES_KEEP_ONLY_WANTED = config.checkbox_to_value(
            subtitles_keep_only_wanted)
        app.SUBTITLES_EXTRA_SCRIPTS = [
            x.strip() for x in subtitles_extra_scripts.split('|') if x.strip()
        ]
        app.SUBTITLES_PRE_SCRIPTS = [
            x.strip() for x in subtitles_pre_scripts.split('|') if x.strip()
        ]

        # Subtitles services
        services_str_list = service_order.split()
        subtitles_services_list = []
        subtitles_services_enabled = []
        for cur_service_str in services_str_list:
            cur_service, cur_enabled = cur_service_str.split(':')
            subtitles_services_list.append(cur_service)
            subtitles_services_enabled.append(int(cur_enabled))

        app.SUBTITLES_SERVICES_LIST = subtitles_services_list
        app.SUBTITLES_SERVICES_ENABLED = subtitles_services_enabled

        app.ADDIC7ED_USER = addic7ed_user or ''
        app.ADDIC7ED_PASS = addic7ed_pass or ''
        app.LEGENDASTV_USER = legendastv_user or ''
        app.LEGENDASTV_PASS = legendastv_pass or ''
        app.OPENSUBTITLES_USER = opensubtitles_user or ''
        app.OPENSUBTITLES_PASS = opensubtitles_pass or ''

        app.instance.save_config()
        # Reset provider pool so next time we use the newest settings
        subtitles.get_provider_pool.invalidate()

        if results:
            for x in results:
                logger.log(x, logger.ERROR)
            ui.notifications.error('Error(s) Saving Configuration',
                                   '<br>\n'.join(results))
        else:
            ui.notifications.message('Configuration Saved',
                                     os.path.join(app.CONFIG_FILE))

        return self.redirect('/config/subtitles/')
Example #6
0
    def saveSubtitles(self, use_subtitles=None, subtitles_plugins=None, subtitles_languages=None, subtitles_dir=None, subtitles_perfect_match=None,
                      service_order=None, subtitles_history=None, subtitles_finder_frequency=None, subtitles_erase_cache=None,
                      subtitles_multi=None, embedded_subtitles_all=None, subtitles_extra_scripts=None, subtitles_pre_scripts=None, subtitles_hearing_impaired=None,
                      addic7ed_user=None, addic7ed_pass=None, itasa_user=None, itasa_pass=None, legendastv_user=None, legendastv_pass=None, opensubtitles_user=None, opensubtitles_pass=None,
                      subtitles_keep_only_wanted=None, embedded_subtitles_unknown_lang=None, subtitles_stop_at_first=None):
        """
        Save Subtitle Search related settings
        """
        results = []

        config.change_SUBTITLES_FINDER_FREQUENCY(subtitles_finder_frequency)
        config.change_USE_SUBTITLES(use_subtitles)
        app.SUBTITLES_ERASE_CACHE = config.checkbox_to_value(subtitles_erase_cache)
        app.SUBTITLES_LANGUAGES = [code.strip() for code in subtitles_languages.split(',') if code.strip() in subtitles.subtitle_code_filter()] if subtitles_languages else []
        app.SUBTITLES_DIR = subtitles_dir
        app.SUBTITLES_PERFECT_MATCH = config.checkbox_to_value(subtitles_perfect_match)
        app.SUBTITLES_HISTORY = config.checkbox_to_value(subtitles_history)
        app.IGNORE_EMBEDDED_SUBS = config.checkbox_to_value(embedded_subtitles_all)
        app.ACCEPT_UNKNOWN_EMBEDDED_SUBS = config.checkbox_to_value(embedded_subtitles_unknown_lang)
        app.SUBTITLES_STOP_AT_FIRST = config.checkbox_to_value(subtitles_stop_at_first)
        app.SUBTITLES_HEARING_IMPAIRED = config.checkbox_to_value(subtitles_hearing_impaired)
        app.SUBTITLES_MULTI = 1 if len(app.SUBTITLES_LANGUAGES) > 1 else config.checkbox_to_value(subtitles_multi)
        app.SUBTITLES_KEEP_ONLY_WANTED = config.checkbox_to_value(subtitles_keep_only_wanted)
        app.SUBTITLES_EXTRA_SCRIPTS = [x.strip() for x in subtitles_extra_scripts.split('|') if x.strip()]
        app.SUBTITLES_PRE_SCRIPTS = [x.strip() for x in subtitles_pre_scripts.split('|') if x.strip()]

        # Subtitles services
        services_str_list = service_order.split()
        subtitles_services_list = []
        subtitles_services_enabled = []
        for cur_service_str in services_str_list:
            cur_service, cur_enabled = cur_service_str.split(':')
            subtitles_services_list.append(cur_service)
            subtitles_services_enabled.append(int(cur_enabled))

        app.SUBTITLES_SERVICES_LIST = subtitles_services_list
        app.SUBTITLES_SERVICES_ENABLED = subtitles_services_enabled

        app.ADDIC7ED_USER = addic7ed_user or ''
        app.ADDIC7ED_PASS = addic7ed_pass or ''
        app.ITASA_USER = itasa_user or ''
        app.ITASA_PASS = itasa_pass or ''
        app.LEGENDASTV_USER = legendastv_user or ''
        app.LEGENDASTV_PASS = legendastv_pass or ''
        app.OPENSUBTITLES_USER = opensubtitles_user or ''
        app.OPENSUBTITLES_PASS = opensubtitles_pass or ''

        app.instance.save_config()
        # Reset provider pool so next time we use the newest settings
        subtitles.get_provider_pool.invalidate()

        if results:
            for x in results:
                logger.log(x, logger.ERROR)
            ui.notifications.error('Error(s) Saving Configuration',
                                   '<br>\n'.join(results))
        else:
            ui.notifications.message('Configuration Saved', os.path.join(app.CONFIG_FILE))

        return self.redirect('/config/subtitles/')