diff --git a/CHANGES.md b/CHANGES.md index 0aa4ae0..7d00d1f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,9 @@ -### 0.25.11 (2021-10-12 17:00:00 UTC) +### 0.25.12 (2021-10-17 20:30:00 UTC) + +* Fix large sickbeard db's that occured from using subtitle settings + + +### 0.25.11 (2021-10-12 17:00:00 UTC) * Fix edit-show alert "set master" malfunction on shows with no master to edit diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index 6c70c12..cd67f86 100755 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -1295,6 +1295,12 @@ def init_stage_1(console_logging): SUBTITLES_SERVICES_AUTH = [k.split(':::') for k in check_setting_str(CFG, 'Subtitles', 'subtitles_services_auth', ':::').split('|||') if k] + try: + # unlikely to happen, but did happen once, so added here as defensive + dct_cfg = sg_helpers.ast_eval(check_setting_str(CFG, 'Subtitles', 'subtitles_services_auth', ':::'), {}) + SUBTITLES_SERVICES_AUTH = [[dct_cfg['os_user'], dct_cfg['os_pass']]] + except (BaseException, Exception): + pass SUBTITLES_DEFAULT = bool(check_setting_int(CFG, 'Subtitles', 'subtitles_default', 0)) SUBTITLES_HISTORY = bool(check_setting_int(CFG, 'Subtitles', 'subtitles_history', 0)) SUBTITLES_FINDER_INTERVAL = check_setting_int(CFG, 'Subtitles', 'subtitles_finder_interval', 1) diff --git a/sickbeard/databases/mainDB.py b/sickbeard/databases/mainDB.py index ce6eaf9..15e6f1a 100644 --- a/sickbeard/databases/mainDB.py +++ b/sickbeard/databases/mainDB.py @@ -18,6 +18,7 @@ import datetime import os.path +import re from .. import db, common, logger from ..name_parser.parser import NameParser, InvalidNameException, InvalidShowException @@ -43,6 +44,41 @@ class MainSanityCheck(db.DBSanityCheck): self.fix_orphan_not_found_show() self.fix_fallback_mapping() self.fix_indexer_mapping_tvdb() + self.fix_episode_subtitles() + + def fix_episode_subtitles(self): + if not self.connection.has_flag('fix_episode_subtitles'): + cleaned = False + cl = [] + + ep_result = self.connection.select( + 'SELECT episode_id' + ' FROM tv_episodes' + ' WHERE subtitles LIKE "%,%"') + + for cur_ep in ep_result: + if not cleaned: + logger.log('Removing duplicate subtitles data in TV Episodes table, this WILL take some time') + cleaned = True + + sql_result = self.connection.select( + 'SELECT SUBSTR(REPLACE(subtitles, ",,", ""), -2000) AS truncated_langs' + ' FROM tv_episodes' + ' WHERE episode_id = ? LIMIT 1', [cur_ep['episode_id']]) + + for cur_result in sql_result: + raw_langs = re.sub(r',+', '', cur_result['truncated_langs']) + subt_value = ','.join(re.findall('[a-z]{2}', raw_langs)) + cl.append(['UPDATE tv_episodes SET subtitles = ? WHERE episode_id = ?', + [(subt_value, '')[bool(len(raw_langs) % 2)], cur_ep['episode_id']]]) + + if 0 < len(cl): + self.connection.mass_action(cl) + + logger.log(u'Performing a vacuum on the database.', logger.DEBUG) + self.connection.action('VACUUM') + + self.connection.set_flag('fix_episode_subtitles') def fix_indexer_mapping_tvdb(self): if not self.connection.has_flag('fix_indexer_mapping_tvdb'): diff --git a/sickbeard/tv.py b/sickbeard/tv.py index ff6ff1f..b9e9dfa 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -4086,7 +4086,11 @@ class TVEpisode(TVEpisodeBase): self._runtime = show_result['runtime'] self._season = season self._status = self._status if None is show_result['status'] else int(show_result['status']) - self._subtitles = show_result['subtitles'] and show_result['subtitles'] or show_result['subtitles'].split(',') + subt_value = show_result['subtitles'] + if ',,' in subt_value: # a defensive fix for a data issue + subt_value = re.sub(r',+', '', subt_value) + subt_value = ('', subt_value)[2 == len(subt_value)] + self._subtitles = subt_value and subt_value.split(',') or [] self._subtitles_lastsearch = show_result['subtitles_lastsearch'] self._subtitles_searchcount = show_result['subtitles_searchcount'] self._timestamp = show_result['timestamp'] or self._make_timestamp()