Example #1
0
    def isNamingValid(pattern=None,
                      multi=None,
                      abd=False,
                      sports=False,
                      anime_type=None):
        if not pattern:
            return "invalid"

        # air by date shows just need one check, we don't need to worry about season folders
        if abd:
            is_valid = naming.check_valid_abd_naming(pattern)
            require_season_folders = False

        # sport shows just need one check, we don't need to worry about season folders
        elif sports:
            is_valid = naming.check_valid_sports_naming(pattern)
            require_season_folders = False

        else:
            # check validity of single and multi ep cases for the whole path
            is_valid = naming.check_valid_naming(pattern, try_int(multi, None),
                                                 try_int(anime_type, None))

            # check validity of single and multi ep cases for only the file name
            require_season_folders = naming.check_force_season_folders(
                pattern, try_int(multi, None), try_int(anime_type, None))

        if is_valid and not require_season_folders:
            return "valid"
        elif is_valid and require_season_folders:
            return "seasonfolders"
        else:
            return "invalid"
Example #2
0
    def _migrate_v1(self):
        """
        Reads in the old naming settings from your config and generates a new config template from them.
        """

        sickbeard.NAMING_PATTERN = self._name_to_pattern()
        logger.log(
            "Based on your old settings I'm setting your new naming pattern to: "
            + sickbeard.NAMING_PATTERN)

        sickbeard.NAMING_CUSTOM_ABD = bool(
            check_setting_int(self.config_obj, 'General', 'naming_dates', 0))

        if sickbeard.NAMING_CUSTOM_ABD:
            sickbeard.NAMING_ABD_PATTERN = self._name_to_pattern(True)
            logger.log(
                "Adding a custom air-by-date naming pattern to your config: " +
                sickbeard.NAMING_ABD_PATTERN)
        else:
            sickbeard.NAMING_ABD_PATTERN = naming.name_abd_presets[0]

        sickbeard.NAMING_MULTI_EP = int(
            check_setting_int(self.config_obj, 'General',
                              'naming_multi_ep_type', 1))

        # see if any of their shows used season folders
        myDB = db.DBConnection()
        season_folder_shows = myDB.select(
            "SELECT * FROM tv_shows WHERE flatten_folders = 0")

        # if any shows had season folders on then prepend season folder to the pattern
        if season_folder_shows:

            old_season_format = check_setting_str(self.config_obj, 'General',
                                                  'season_folders_format',
                                                  'Season %02d')

            new_season_format = old_season_format % 9
            new_season_format = new_season_format.replace('09', '%0S')
            new_season_format = new_season_format.replace('9', '%S')
            logger.log(u"Changed season folder format from " +
                       old_season_format + " to " + new_season_format +
                       ", prepending it to your naming config")

            sickbeard.NAMING_PATTERN = new_season_format + os.sep + sickbeard.NAMING_PATTERN

        # if no shows had it on then don't flatten any shows and don't put season folders in the config
        else:

            logger.log(
                u"No shows were using season folders before so I'm disabling flattening on all shows"
            )

            # don't flatten any shows at all
            myDB.action("UPDATE tv_shows SET flatten_folders = 0")

        sickbeard.NAMING_FORCE_FOLDERS = naming.check_force_season_folders()
Example #3
0
    def _migrate_v1(self):
        """
        Reads in the old naming settings from your config and generates a new config template from them.
        """

        sickbeard.NAMING_PATTERN = self._name_to_pattern()
        logger.log("Based on your old settings I'm setting your new naming pattern to: " + sickbeard.NAMING_PATTERN)

        sickbeard.NAMING_CUSTOM_ABD = bool(check_setting_int(self.config_obj, "General", "naming_dates", 0))

        if sickbeard.NAMING_CUSTOM_ABD:
            sickbeard.NAMING_ABD_PATTERN = self._name_to_pattern(True)
            logger.log("Adding a custom air-by-date naming pattern to your config: " + sickbeard.NAMING_ABD_PATTERN)
        else:
            sickbeard.NAMING_ABD_PATTERN = naming.name_abd_presets[0]

        sickbeard.NAMING_MULTI_EP = int(check_setting_int(self.config_obj, "General", "naming_multi_ep_type", 1))

        # see if any of their shows used season folders
        myDB = db.DBConnection()
        season_folder_shows = myDB.select("SELECT * FROM tv_shows WHERE flatten_folders = 0")

        # if any shows had season folders on then prepend season folder to the pattern
        if season_folder_shows:

            old_season_format = check_setting_str(self.config_obj, "General", "season_folders_format", "Season %02d")

            if old_season_format:
                try:
                    new_season_format = old_season_format % 9
                    new_season_format = str(new_season_format).replace("09", "%0S")
                    new_season_format = new_season_format.replace("9", "%S")

                    logger.log(
                        u"Changed season folder format from "
                        + old_season_format
                        + " to "
                        + new_season_format
                        + ", prepending it to your naming config"
                    )
                    sickbeard.NAMING_PATTERN = new_season_format + os.sep + sickbeard.NAMING_PATTERN

                except (TypeError, ValueError):
                    logger.log(u"Can't change " + old_season_format + " to new season format", logger.ERROR)

        # if no shows had it on then don't flatten any shows and don't put season folders in the config
        else:

            logger.log(u"No shows were using season folders before so I'm disabling flattening on all shows")

            # don't flatten any shows at all
            myDB.action("UPDATE tv_shows SET flatten_folders = 0")

        sickbeard.NAMING_FORCE_FOLDERS = naming.check_force_season_folders()
Example #4
0
    def _migrate_v1(self):
        """
        Reads in the old naming settings from your config and generates a new config template from them.
        """

        sickbeard.NAMING_PATTERN = self._name_to_pattern()
        logger.log('Based on your old settings I am setting your new naming pattern to: %s' % sickbeard.NAMING_PATTERN)

        sickbeard.NAMING_CUSTOM_ABD = bool(check_setting_int(self.config_obj, 'General', 'naming_dates', 0))

        if sickbeard.NAMING_CUSTOM_ABD:
            sickbeard.NAMING_ABD_PATTERN = self._name_to_pattern(True)
            logger.log('Adding a custom air-by-date naming pattern to your config: %s' % sickbeard.NAMING_ABD_PATTERN)
        else:
            sickbeard.NAMING_ABD_PATTERN = naming.name_abd_presets[0]

        sickbeard.NAMING_MULTI_EP = int(check_setting_int(self.config_obj, 'General', 'naming_multi_ep_type', 1))

        # see if any of their shows used season folders
        myDB = db.DBConnection()
        season_folder_shows = myDB.select('SELECT * FROM tv_shows WHERE flatten_folders = 0')

        # if any shows had season folders on then prepend season folder to the pattern
        if season_folder_shows:

            old_season_format = check_setting_str(self.config_obj, 'General', 'season_folders_format', 'Season %02d')

            if old_season_format:
                try:
                    new_season_format = old_season_format % 9
                    new_season_format = str(new_season_format).replace('09', '%0S')
                    new_season_format = new_season_format.replace('9', '%S')

                    logger.log(u'Changed season folder format from %s to %s, prepending it to your naming config' %
                               (old_season_format, new_season_format))
                    sickbeard.NAMING_PATTERN = new_season_format + os.sep + sickbeard.NAMING_PATTERN

                except (TypeError, ValueError):
                    logger.log(u'Can not change %s to new season format' % old_season_format, logger.ERROR)

        # if no shows had it on then don't flatten any shows and don't put season folders in the config
        else:

            logger.log(u'No shows were using season folders before so I am disabling flattening on all shows')

            # don't flatten any shows at all
            myDB.action('UPDATE tv_shows SET flatten_folders = 0')

        sickbeard.NAMING_FORCE_FOLDERS = naming.check_force_season_folders()
Example #5
0
    def _migrate_v1(self):
        """
        Reads in the old naming settings from your config and generates a new config template from them.
        """

        sickbeard.NAMING_PATTERN = self._name_to_pattern()
        logger.log('Based on your old settings I am setting your new naming pattern to: %s' % sickbeard.NAMING_PATTERN)

        sickbeard.NAMING_CUSTOM_ABD = bool(check_setting_int(self.config_obj, 'General', 'naming_dates', 0))

        if sickbeard.NAMING_CUSTOM_ABD:
            sickbeard.NAMING_ABD_PATTERN = self._name_to_pattern(True)
            logger.log('Adding a custom air-by-date naming pattern to your config: %s' % sickbeard.NAMING_ABD_PATTERN)
        else:
            sickbeard.NAMING_ABD_PATTERN = naming.name_abd_presets[0]

        sickbeard.NAMING_MULTI_EP = int(check_setting_int(self.config_obj, 'General', 'naming_multi_ep_type', 1))

        # see if any of their shows used season folders
        myDB = db.DBConnection()
        season_folder_shows = myDB.select('SELECT * FROM tv_shows WHERE flatten_folders = 0')

        # if any shows had season folders on then prepend season folder to the pattern
        if season_folder_shows:

            old_season_format = check_setting_str(self.config_obj, 'General', 'season_folders_format', 'Season %02d')

            if old_season_format:
                try:
                    new_season_format = old_season_format % 9
                    new_season_format = str(new_season_format).replace('09', '%0S')
                    new_season_format = new_season_format.replace('9', '%S')

                    logger.log(u'Changed season folder format from %s to %s, prepending it to your naming config' %
                               (old_season_format, new_season_format))
                    sickbeard.NAMING_PATTERN = new_season_format + os.sep + sickbeard.NAMING_PATTERN

                except (TypeError, ValueError):
                    logger.log(u'Can not change %s to new season format' % old_season_format, logger.ERROR)

        # if no shows had it on then don't flatten any shows and don't put season folders in the config
        else:

            logger.log(u'No shows were using season folders before so I am disabling flattening on all shows')

            # don't flatten any shows at all
            myDB.action('UPDATE tv_shows SET flatten_folders = 0')

        sickbeard.NAMING_FORCE_FOLDERS = naming.check_force_season_folders()
Example #6
0
    def _migrate_v1(self):
        """
        Reads in the old naming settings from your config and generates a new config template from them.
        """

        sickbeard.NAMING_PATTERN = self._name_to_pattern()
        logger.log("Based on your old settings I'm setting your new naming pattern to: " + sickbeard.NAMING_PATTERN)

        sickbeard.NAMING_CUSTOM_ABD = bool(check_setting_int(self.config_obj, 'General', 'naming_dates', 0))

        if sickbeard.NAMING_CUSTOM_ABD:
            sickbeard.NAMING_ABD_PATTERN = self._name_to_pattern(True)
            logger.log("Adding a custom air-by-date naming pattern to your config: " + sickbeard.NAMING_ABD_PATTERN)
        else:
            sickbeard.NAMING_ABD_PATTERN = naming.name_abd_presets[0]

        sickbeard.NAMING_MULTI_EP = int(check_setting_int(self.config_obj, 'General', 'naming_multi_ep_type', 1))

        # see if any of their shows used season folders
        season_folder_shows = db_peewee.TvShow.select().where(
            db_peewee.TvShow.flatten_folders == False).count()

        # if any shows had season folders on then prepend season folder to the pattern
        if season_folder_shows:

            old_season_format = check_setting_str(self.config_obj, 'General', 'season_folders_format', 'Season %02d')

            if old_season_format:
                try:
                    new_season_format = old_season_format % 9
                    new_season_format = new_season_format.replace('09', '%0S')
                    new_season_format = new_season_format.replace('9', '%S')

                    logger.log(u"Changed season folder format from " + old_season_format + " to " + new_season_format + ", prepending it to your naming config")
                    sickbeard.NAMING_PATTERN = new_season_format + os.sep + sickbeard.NAMING_PATTERN

                except (TypeError, ValueError):
                    logger.log(u"Can't change " + old_season_format + " to new season format", logger.ERROR)

        # if no shows had it on then don't flatten any shows and don't put season folders in the config
        else:

            logger.log(u"No shows were using season folders before so I'm disabling flattening on all shows")

            # don't flatten any shows at all
            db_peewee.TvShow.update(flatten_folders=False)

        sickbeard.NAMING_FORCE_FOLDERS = naming.check_force_season_folders()
Example #7
0
    def isNamingValid(pattern=None, multi=None, abd=False, sports=False, anime_type=None):
        """
        Validate episode naming pattern
        """
        if pattern is None:
            return 'invalid'

        if multi is not None:
            multi = int(multi)

        if anime_type is not None:
            anime_type = int(anime_type)

        # air by date shows just need one check, we don't need to worry about season folders
        if abd:
            is_valid = naming.check_valid_abd_naming(pattern)
            require_season_folders = False

        # sport shows just need one check, we don't need to worry about season folders
        elif sports:
            is_valid = naming.check_valid_sports_naming(pattern)
            require_season_folders = False

        else:
            # check validity of single and multi ep cases for the whole path
            is_valid = naming.check_valid_naming(pattern, multi, anime_type)

            # check validity of single and multi ep cases for only the file name
            require_season_folders = naming.check_force_season_folders(pattern, multi, anime_type)

        if is_valid and not require_season_folders:
            return 'valid'
        elif is_valid and require_season_folders:
            return 'seasonfolders'
        else:
            return 'invalid'
Example #8
0
    def savePostProcessing(self,
                           kodi_data=None,
                           kodi_12plus_data=None,
                           mediabrowser_data=None,
                           sony_ps3_data=None,
                           wdtv_data=None,
                           tivo_data=None,
                           mede8er_data=None,
                           keep_processed_dir=None,
                           process_method=None,
                           processor_follow_symlinks=None,
                           del_rar_contents=None,
                           process_automatically=None,
                           no_delete=None,
                           rename_episodes=None,
                           airdate_episodes=None,
                           file_timestamp_timezone=None,
                           unpack=None,
                           unpack_dir=None,
                           unrar_tool=None,
                           alt_unrar_tool=None,
                           move_associated_files=None,
                           delete_non_associated_files=None,
                           sync_files=None,
                           postpone_if_sync_files=None,
                           allowed_extensions=None,
                           tv_download_dir=None,
                           create_missing_show_dirs=None,
                           add_shows_wo_dir=None,
                           extra_scripts=None,
                           nfo_rename=None,
                           naming_pattern=None,
                           naming_multi_ep=None,
                           naming_custom_abd=None,
                           naming_anime=None,
                           naming_abd_pattern=None,
                           naming_strip_year=None,
                           naming_custom_sports=None,
                           naming_sports_pattern=None,
                           naming_custom_anime=None,
                           naming_anime_pattern=None,
                           naming_anime_multi_ep=None,
                           autopostprocessor_frequency=None,
                           use_icacls=None):

        results = []

        if not config.change_tv_download_dir(tv_download_dir):
            results += [
                "Unable to create directory " +
                ek(os.path.normpath, tv_download_dir) + ", dir not changed."
            ]

        config.change_postprocessor_frequency(autopostprocessor_frequency)
        config.change_process_automatically(process_automatically)
        sickbeard.USE_ICACLS = config.checkbox_to_value(use_icacls)

        config.change_unrar_tool(unrar_tool, alt_unrar_tool)

        unpack = try_int(unpack)
        if unpack == sickbeard.UNPACK_PROCESS_CONTENTS:
            sickbeard.UNPACK = int(self.isRarSupported() != 'not supported')
            if sickbeard.UNPACK != sickbeard.UNPACK_PROCESS_CONTENTS:
                results.append(
                    _("Unpacking Not Supported, disabling unpack setting"))
        elif unpack in sickbeard.unpackStrings:
            sickbeard.UNPACK = unpack

        if not config.change_unpack_dir(unpack_dir):
            results += [
                "Unable to change unpack directory to " +
                ek(os.path.normpath, unpack_dir) + ", check the logs."
            ]

        sickbeard.NO_DELETE = config.checkbox_to_value(no_delete)
        sickbeard.KEEP_PROCESSED_DIR = config.checkbox_to_value(
            keep_processed_dir)
        sickbeard.CREATE_MISSING_SHOW_DIRS = config.checkbox_to_value(
            create_missing_show_dirs)
        sickbeard.ADD_SHOWS_WO_DIR = config.checkbox_to_value(add_shows_wo_dir)
        sickbeard.PROCESS_METHOD = process_method
        sickbeard.PROCESSOR_FOLLOW_SYMLINKS = config.checkbox_to_value(
            processor_follow_symlinks)
        sickbeard.DELRARCONTENTS = config.checkbox_to_value(del_rar_contents)
        sickbeard.EXTRA_SCRIPTS = [
            x.strip() for x in extra_scripts.split('|') if x.strip()
        ]
        sickbeard.RENAME_EPISODES = config.checkbox_to_value(rename_episodes)
        sickbeard.AIRDATE_EPISODES = config.checkbox_to_value(airdate_episodes)
        sickbeard.FILE_TIMESTAMP_TIMEZONE = file_timestamp_timezone
        sickbeard.MOVE_ASSOCIATED_FILES = config.checkbox_to_value(
            move_associated_files)
        sickbeard.DELETE_NON_ASSOCIATED_FILES = config.checkbox_to_value(
            delete_non_associated_files)
        sickbeard.SYNC_FILES = sync_files
        sickbeard.POSTPONE_IF_SYNC_FILES = config.checkbox_to_value(
            postpone_if_sync_files)

        sickbeard.ALLOWED_EXTENSIONS = ','.join(
            {x.strip()
             for x in allowed_extensions.split(',') if x.strip()})
        sickbeard.NAMING_CUSTOM_ABD = config.checkbox_to_value(
            naming_custom_abd)
        sickbeard.NAMING_CUSTOM_SPORTS = config.checkbox_to_value(
            naming_custom_sports)
        sickbeard.NAMING_CUSTOM_ANIME = config.checkbox_to_value(
            naming_custom_anime)
        sickbeard.NAMING_STRIP_YEAR = config.checkbox_to_value(
            naming_strip_year)
        sickbeard.NFO_RENAME = config.checkbox_to_value(nfo_rename)

        sickbeard.METADATA_KODI = kodi_data
        sickbeard.METADATA_KODI_12PLUS = kodi_12plus_data
        sickbeard.METADATA_MEDIABROWSER = mediabrowser_data
        sickbeard.METADATA_PS3 = sony_ps3_data
        sickbeard.METADATA_WDTV = wdtv_data
        sickbeard.METADATA_TIVO = tivo_data
        sickbeard.METADATA_MEDE8ER = mede8er_data

        sickbeard.metadata_provider_dict['KODI'].set_config(
            sickbeard.METADATA_KODI)
        sickbeard.metadata_provider_dict['KODI 12+'].set_config(
            sickbeard.METADATA_KODI_12PLUS)
        sickbeard.metadata_provider_dict['MediaBrowser'].set_config(
            sickbeard.METADATA_MEDIABROWSER)
        sickbeard.metadata_provider_dict['Sony PS3'].set_config(
            sickbeard.METADATA_PS3)
        sickbeard.metadata_provider_dict['WDTV'].set_config(
            sickbeard.METADATA_WDTV)
        sickbeard.metadata_provider_dict['TIVO'].set_config(
            sickbeard.METADATA_TIVO)
        sickbeard.metadata_provider_dict['Mede8er'].set_config(
            sickbeard.METADATA_MEDE8ER)

        if self.isNamingValid(naming_pattern,
                              naming_multi_ep,
                              anime_type=naming_anime) != "invalid":
            sickbeard.NAMING_PATTERN = naming_pattern
            sickbeard.NAMING_MULTI_EP = try_int(
                naming_multi_ep, NAMING_LIMITED_EXTEND_E_PREFIXED)
            sickbeard.NAMING_FORCE_FOLDERS = naming.check_force_season_folders(
            )
        else:
            results.append(
                _("You tried saving an invalid normal naming config, not saving your naming settings"
                  ))

        if self.isNamingValid(naming_anime_pattern,
                              naming_anime_multi_ep,
                              anime_type=naming_anime) != "invalid":
            sickbeard.NAMING_ANIME_PATTERN = naming_anime_pattern
            sickbeard.NAMING_ANIME_MULTI_EP = try_int(
                naming_anime_multi_ep, NAMING_LIMITED_EXTEND_E_PREFIXED)
            sickbeard.NAMING_ANIME = try_int(naming_anime, 3)
            sickbeard.NAMING_FORCE_FOLDERS = naming.check_force_season_folders(
            )
        else:
            results.append(
                _("You tried saving an invalid anime naming config, not saving your naming settings"
                  ))

        if self.isNamingValid(naming_abd_pattern, None, abd=True) != "invalid":
            sickbeard.NAMING_ABD_PATTERN = naming_abd_pattern
        else:
            results.append(
                "You tried saving an invalid air-by-date naming config, not saving your air-by-date settings"
            )

        if self.isNamingValid(naming_sports_pattern, None,
                              sports=True) != "invalid":
            sickbeard.NAMING_SPORTS_PATTERN = naming_sports_pattern
        else:
            results.append(
                "You tried saving an invalid sports naming config, not saving your sports settings"
            )

        sickbeard.save_config()

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

        return self.redirect("/config/postProcessing/")
Example #9
0
def initialize(consoleLogging=True):

    with INIT_LOCK:

        global ACTUAL_LOG_DIR, LOG_DIR, WEB_PORT, WEB_LOG, WEB_ROOT, WEB_USERNAME, WEB_PASSWORD, WEB_HOST, WEB_IPV6, USE_API, API_KEY, ENABLE_HTTPS, HTTPS_CERT, HTTPS_KEY, \
                USE_NZBS, USE_TORRENTS, NZB_METHOD, NZB_DIR, DOWNLOAD_PROPERS, \
                SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, SAB_HOST, \
                NZBGET_USERNAME, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_HOST, currentSearchScheduler, backlogSearchScheduler, \
                USE_XBMC, XBMC_ALWAYS_ON, XBMC_NOTIFY_ONSNATCH, XBMC_NOTIFY_ONDOWNLOAD, XBMC_UPDATE_FULL, XBMC_UPDATE_ONLYFIRST, \
                XBMC_UPDATE_LIBRARY, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, \
                USE_TRAKT, TRAKT_USERNAME, TRAKT_PASSWORD, TRAKT_API, \
                USE_PLEX, PLEX_NOTIFY_ONSNATCH, PLEX_NOTIFY_ONDOWNLOAD, PLEX_UPDATE_LIBRARY, \
                PLEX_SERVER_HOST, PLEX_HOST, PLEX_USERNAME, PLEX_PASSWORD, \
                showUpdateScheduler, __INITIALIZED__, LAUNCH_BROWSER, showList, loadingShowList, \
                NEWZNAB_DATA, NZBS, NZBS_UID, NZBS_HASH, EZRSS, HDBITS, HDBITS_USERNAME, HDBITS_PASSKEY, TVTORRENTS, TVTORRENTS_DIGEST, TVTORRENTS_HASH, BTN, BTN_API_KEY, TORRENTLEECH, TORRENTLEECH_KEY, \
                TORRENT_DIR, USENET_RETENTION, SOCKET_TIMEOUT, \
                SEARCH_FREQUENCY, DEFAULT_SEARCH_FREQUENCY, BACKLOG_SEARCH_FREQUENCY, \
                QUALITY_DEFAULT, FLATTEN_FOLDERS_DEFAULT, STATUS_DEFAULT, \
                GROWL_NOTIFY_ONSNATCH, GROWL_NOTIFY_ONDOWNLOAD, TWITTER_NOTIFY_ONSNATCH, TWITTER_NOTIFY_ONDOWNLOAD, \
                USE_GROWL, GROWL_HOST, GROWL_PASSWORD, USE_PROWL, PROWL_NOTIFY_ONSNATCH, PROWL_NOTIFY_ONDOWNLOAD, PROWL_API, PROWL_PRIORITY, PROG_DIR, \
                USE_PYTIVO, PYTIVO_NOTIFY_ONSNATCH, PYTIVO_NOTIFY_ONDOWNLOAD, PYTIVO_UPDATE_LIBRARY, PYTIVO_HOST, PYTIVO_SHARE_NAME, PYTIVO_TIVO_NAME, \
                USE_NMA, NMA_NOTIFY_ONSNATCH, NMA_NOTIFY_ONDOWNLOAD, NMA_API, NMA_PRIORITY, \
                versionCheckScheduler, VERSION_NOTIFY, PROCESS_AUTOMATICALLY, \
                KEEP_PROCESSED_DIR, TV_DOWNLOAD_DIR, TVDB_BASE_URL, MIN_SEARCH_FREQUENCY, \
                showQueueScheduler, searchQueueScheduler, ROOT_DIRS, CACHE_DIR, ACTUAL_CACHE_DIR, TVDB_API_PARMS, \
                NAMING_PATTERN, NAMING_MULTI_EP, NAMING_FORCE_FOLDERS, NAMING_ABD_PATTERN, NAMING_CUSTOM_ABD, \
                RENAME_EPISODES, properFinderScheduler, PROVIDER_ORDER, autoPostProcesserScheduler, \
                WOMBLE, OMGWTFNZBS, OMGWTFNZBS_USERNAME, OMGWTFNZBS_APIKEY, providerList, newznabProviderList, \
                EXTRA_SCRIPTS, USE_TWITTER, TWITTER_USERNAME, TWITTER_PASSWORD, TWITTER_PREFIX, \
                USE_BOXCAR, BOXCAR_USERNAME, BOXCAR_PASSWORD, BOXCAR_NOTIFY_ONDOWNLOAD, BOXCAR_NOTIFY_ONSNATCH, \
                USE_PUSHOVER, PUSHOVER_USERKEY, PUSHOVER_NOTIFY_ONDOWNLOAD, PUSHOVER_NOTIFY_ONSNATCH, \
                USE_LIBNOTIFY, LIBNOTIFY_NOTIFY_ONSNATCH, LIBNOTIFY_NOTIFY_ONDOWNLOAD, USE_NMJ, NMJ_HOST, NMJ_DATABASE, NMJ_MOUNT, USE_NMJv2, NMJv2_HOST, NMJv2_DATABASE, NMJv2_DBLOC, USE_SYNOINDEX, \
                USE_LISTVIEW, METADATA_XBMC, METADATA_XBMC_12PLUS, METADATA_MEDIABROWSER, METADATA_MEDE8ER, METADATA_PS3, metadata_provider_dict, \
                GIT_PATH, MOVE_ASSOCIATED_FILES, \
                COMING_EPS_LAYOUT, COMING_EPS_SORT, COMING_EPS_DISPLAY_PAUSED, METADATA_WDTV, METADATA_TIVO, IGNORE_WORDS, CREATE_MISSING_SHOW_DIRS, \
                ADD_SHOWS_WO_DIR, ANON_REDIRECT

        if __INITIALIZED__:
            return False

        socket.setdefaulttimeout(SOCKET_TIMEOUT)

        CheckSection(CFG, 'General')

        ACTUAL_LOG_DIR = check_setting_str(CFG, 'General', 'log_dir', 'Logs')
        # put the log dir inside the data dir, unless an absolute path
        LOG_DIR = os.path.normpath(os.path.join(DATA_DIR, ACTUAL_LOG_DIR))

        if not helpers.makeDir(LOG_DIR):
            logger.log(u"!!! No log folder, logging to screen only!", logger.ERROR)

        try:
            WEB_PORT = check_setting_int(CFG, 'General', 'web_port', 8081)
        except:
            WEB_PORT = 8081

        if WEB_PORT < 21 or WEB_PORT > 65535:
            WEB_PORT = 8081

        WEB_HOST = check_setting_str(CFG, 'General', 'web_host', '0.0.0.0')
        WEB_IPV6 = bool(check_setting_int(CFG, 'General', 'web_ipv6', 0))
        WEB_ROOT = check_setting_str(CFG, 'General', 'web_root', '').rstrip("/")
        WEB_LOG = bool(check_setting_int(CFG, 'General', 'web_log', 0))
        WEB_USERNAME = check_setting_str(CFG, 'General', 'web_username', '')
        WEB_PASSWORD = check_setting_str(CFG, 'General', 'web_password', '')
        LAUNCH_BROWSER = bool(check_setting_int(CFG, 'General', 'launch_browser', 1))

        ANON_REDIRECT = check_setting_str(CFG, 'General', 'anon_redirect', 'http://dereferer.org/?')
        # attempt to help prevent users from breaking links by using a bad url
        if not ANON_REDIRECT.endswith('?'):
            ANON_REDIRECT = ''

        USE_API = bool(check_setting_int(CFG, 'General', 'use_api', 0))
        API_KEY = check_setting_str(CFG, 'General', 'api_key', '')

        ENABLE_HTTPS = bool(check_setting_int(CFG, 'General', 'enable_https', 0))
        HTTPS_CERT = check_setting_str(CFG, 'General', 'https_cert', 'server.crt')
        HTTPS_KEY = check_setting_str(CFG, 'General', 'https_key', 'server.key')

        ACTUAL_CACHE_DIR = check_setting_str(CFG, 'General', 'cache_dir', 'cache')
        # fix bad configs due to buggy code
        if ACTUAL_CACHE_DIR == 'None':
            ACTUAL_CACHE_DIR = 'cache'

        # unless they specify, put the cache dir inside the data dir
        if not os.path.isabs(ACTUAL_CACHE_DIR):
            CACHE_DIR = os.path.join(DATA_DIR, ACTUAL_CACHE_DIR)
        else:
            CACHE_DIR = ACTUAL_CACHE_DIR

        if not helpers.makeDir(CACHE_DIR):
            logger.log(u"!!! Creating local cache dir failed, using system default", logger.ERROR)
            CACHE_DIR = None

        ROOT_DIRS = check_setting_str(CFG, 'General', 'root_dirs', '')
        if not re.match(r'\d+\|[^|]+(?:\|[^|]+)*', ROOT_DIRS):
            ROOT_DIRS = ''

        # Set our common tvdb_api options here
        TVDB_API_PARMS = {'apikey': TVDB_API_KEY,
                          'language': 'en',
                          'useZip': True}

        if CACHE_DIR:
            TVDB_API_PARMS['cache'] = os.path.join(CACHE_DIR, 'tvdb')

        TVDB_BASE_URL = 'http://thetvdb.com/api/' + TVDB_API_KEY

        QUALITY_DEFAULT = check_setting_int(CFG, 'General', 'quality_default', SD)
        STATUS_DEFAULT = check_setting_int(CFG, 'General', 'status_default', SKIPPED)
        VERSION_NOTIFY = check_setting_int(CFG, 'General', 'version_notify', 1)
        FLATTEN_FOLDERS_DEFAULT = bool(check_setting_int(CFG, 'General', 'flatten_folders_default', 0))

        PROVIDER_ORDER = check_setting_str(CFG, 'General', 'provider_order', '').split()

        NAMING_PATTERN = check_setting_str(CFG, 'General', 'naming_pattern', '')
        NAMING_ABD_PATTERN = check_setting_str(CFG, 'General', 'naming_abd_pattern', '')
        NAMING_CUSTOM_ABD = check_setting_int(CFG, 'General', 'naming_custom_abd', 0)
        NAMING_MULTI_EP = check_setting_int(CFG, 'General', 'naming_multi_ep', 1)
        NAMING_FORCE_FOLDERS = naming.check_force_season_folders()

        USE_NZBS = bool(check_setting_int(CFG, 'General', 'use_nzbs', 1))
        USE_TORRENTS = bool(check_setting_int(CFG, 'General', 'use_torrents', 0))

        NZB_METHOD = check_setting_str(CFG, 'General', 'nzb_method', 'blackhole')
        if NZB_METHOD not in ('blackhole', 'sabnzbd', 'nzbget'):
            NZB_METHOD = 'blackhole'

        DOWNLOAD_PROPERS = bool(check_setting_int(CFG, 'General', 'download_propers', 1))
        USENET_RETENTION = check_setting_int(CFG, 'General', 'usenet_retention', 500)
        SEARCH_FREQUENCY = check_setting_int(CFG, 'General', 'search_frequency', DEFAULT_SEARCH_FREQUENCY)
        if SEARCH_FREQUENCY < MIN_SEARCH_FREQUENCY:
            SEARCH_FREQUENCY = MIN_SEARCH_FREQUENCY

        TV_DOWNLOAD_DIR = check_setting_str(CFG, 'General', 'tv_download_dir', '')
        PROCESS_AUTOMATICALLY = check_setting_int(CFG, 'General', 'process_automatically', 0)
        RENAME_EPISODES = check_setting_int(CFG, 'General', 'rename_episodes', 1)
        KEEP_PROCESSED_DIR = check_setting_int(CFG, 'General', 'keep_processed_dir', 1)
        MOVE_ASSOCIATED_FILES = check_setting_int(CFG, 'General', 'move_associated_files', 0)
        CREATE_MISSING_SHOW_DIRS = check_setting_int(CFG, 'General', 'create_missing_show_dirs', 0)
        ADD_SHOWS_WO_DIR = check_setting_int(CFG, 'General', 'add_shows_wo_dir', 0)

        EZRSS = bool(check_setting_int(CFG, 'General', 'use_torrent', 0))
        if not EZRSS:
            CheckSection(CFG, 'EZRSS')
            EZRSS = bool(check_setting_int(CFG, 'EZRSS', 'ezrss', 0))

        GIT_PATH = check_setting_str(CFG, 'General', 'git_path', '')
        IGNORE_WORDS = check_setting_str(CFG, 'General', 'ignore_words', IGNORE_WORDS)
        EXTRA_SCRIPTS = [x.strip() for x in check_setting_str(CFG, 'General', 'extra_scripts', '').split('|') if x.strip()]

        USE_LISTVIEW = bool(check_setting_int(CFG, 'General', 'use_listview', 0))

        METADATA_XBMC = check_setting_str(CFG, 'General', 'metadata_xbmc', '0|0|0|0|0|0|0|0|0|0')
        METADATA_XBMC_12PLUS = check_setting_str(CFG, 'General', 'metadata_xbmc_12plus', '0|0|0|0|0|0|0|0|0|0')
        METADATA_MEDIABROWSER = check_setting_str(CFG, 'General', 'metadata_mediabrowser', '0|0|0|0|0|0|0|0|0|0')
        METADATA_PS3 = check_setting_str(CFG, 'General', 'metadata_ps3', '0|0|0|0|0|0|0|0|0|0')
        METADATA_WDTV = check_setting_str(CFG, 'General', 'metadata_wdtv', '0|0|0|0|0|0|0|0|0|0')
        METADATA_TIVO = check_setting_str(CFG, 'General', 'metadata_tivo', '0|0|0|0|0|0|0|0|0|0')
        METADATA_MEDE8ER = check_setting_str(CFG, 'General', 'metadata_mede8er', '0|0|0|0|0|0|0|0|0|0')

        CheckSection(CFG, 'GUI')
        COMING_EPS_LAYOUT = check_setting_str(CFG, 'GUI', 'coming_eps_layout', 'banner')
        COMING_EPS_DISPLAY_PAUSED = bool(check_setting_int(CFG, 'GUI', 'coming_eps_display_paused', 0))
        COMING_EPS_SORT = check_setting_str(CFG, 'GUI', 'coming_eps_sort', 'date')

        CheckSection(CFG, 'Newznab')
        NEWZNAB_DATA = check_setting_str(CFG, 'Newznab', 'newznab_data', '')

        CheckSection(CFG, 'Blackhole')
        NZB_DIR = check_setting_str(CFG, 'Blackhole', 'nzb_dir', '')
        TORRENT_DIR = check_setting_str(CFG, 'Blackhole', 'torrent_dir', '')

        CheckSection(CFG, 'HDBITS')
        HDBITS = bool(check_setting_int(CFG, 'HDBITS', 'hdbits', 0))
        HDBITS_USERNAME = check_setting_str(CFG, 'HDBITS', 'hdbits_username', '')
        HDBITS_PASSKEY = check_setting_str(CFG, 'HDBITS', 'hdbits_passkey', '')

        CheckSection(CFG, 'TVTORRENTS')
        TVTORRENTS = bool(check_setting_int(CFG, 'TVTORRENTS', 'tvtorrents', 0))
        TVTORRENTS_DIGEST = check_setting_str(CFG, 'TVTORRENTS', 'tvtorrents_digest', '')
        TVTORRENTS_HASH = check_setting_str(CFG, 'TVTORRENTS', 'tvtorrents_hash', '')

        CheckSection(CFG, 'BTN')
        BTN = bool(check_setting_int(CFG, 'BTN', 'btn', 0))
        BTN_API_KEY = check_setting_str(CFG, 'BTN', 'btn_api_key', '')

        CheckSection(CFG, 'TorrentLeech')
        TORRENTLEECH = bool(check_setting_int(CFG, 'TorrentLeech', 'torrentleech', 0))
        TORRENTLEECH_KEY = check_setting_str(CFG, 'TorrentLeech', 'torrentleech_key', '')

        CheckSection(CFG, 'NZBs')
        NZBS = bool(check_setting_int(CFG, 'NZBs', 'nzbs', 0))
        NZBS_UID = check_setting_str(CFG, 'NZBs', 'nzbs_uid', '')
        NZBS_HASH = check_setting_str(CFG, 'NZBs', 'nzbs_hash', '')

        CheckSection(CFG, 'Womble')
        WOMBLE = bool(check_setting_int(CFG, 'Womble', 'womble', 1))

        CheckSection(CFG, 'omgwtfnzbs')
        OMGWTFNZBS = bool(check_setting_int(CFG, 'omgwtfnzbs', 'omgwtfnzbs', 0))
        OMGWTFNZBS_USERNAME = check_setting_str(CFG, 'omgwtfnzbs', 'omgwtfnzbs_username', '')
        OMGWTFNZBS_APIKEY = check_setting_str(CFG, 'omgwtfnzbs', 'omgwtfnzbs_apikey', '')

        CheckSection(CFG, 'SABnzbd')
        SAB_USERNAME = check_setting_str(CFG, 'SABnzbd', 'sab_username', '')
        SAB_PASSWORD = check_setting_str(CFG, 'SABnzbd', 'sab_password', '')
        SAB_APIKEY = check_setting_str(CFG, 'SABnzbd', 'sab_apikey', '')
        SAB_CATEGORY = check_setting_str(CFG, 'SABnzbd', 'sab_category', 'tv')
        SAB_HOST = check_setting_str(CFG, 'SABnzbd', 'sab_host', '')

        CheckSection(CFG, 'NZBget')
        NZBGET_USERNAME = check_setting_str(CFG, 'NZBget', 'nzbget_username', 'nzbget')
        NZBGET_PASSWORD = check_setting_str(CFG, 'NZBget', 'nzbget_password', 'tegbzn6789')
        NZBGET_CATEGORY = check_setting_str(CFG, 'NZBget', 'nzbget_category', 'tv')
        NZBGET_HOST = check_setting_str(CFG, 'NZBget', 'nzbget_host', '')

        CheckSection(CFG, 'XBMC')
        USE_XBMC = bool(check_setting_int(CFG, 'XBMC', 'use_xbmc', 0))
        XBMC_ALWAYS_ON = bool(check_setting_int(CFG, 'XBMC', 'xbmc_always_on', 1))
        XBMC_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'XBMC', 'xbmc_notify_onsnatch', 0))
        XBMC_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'XBMC', 'xbmc_notify_ondownload', 0))
        XBMC_UPDATE_LIBRARY = bool(check_setting_int(CFG, 'XBMC', 'xbmc_update_library', 0))
        XBMC_UPDATE_FULL = bool(check_setting_int(CFG, 'XBMC', 'xbmc_update_full', 0))
        XBMC_UPDATE_ONLYFIRST = bool(check_setting_int(CFG, 'XBMC', 'xbmc_update_onlyfirst', 0))
        XBMC_HOST = check_setting_str(CFG, 'XBMC', 'xbmc_host', '')
        XBMC_USERNAME = check_setting_str(CFG, 'XBMC', 'xbmc_username', '')
        XBMC_PASSWORD = check_setting_str(CFG, 'XBMC', 'xbmc_password', '')

        CheckSection(CFG, 'Plex')
        USE_PLEX = bool(check_setting_int(CFG, 'Plex', 'use_plex', 0))
        PLEX_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Plex', 'plex_notify_onsnatch', 0))
        PLEX_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Plex', 'plex_notify_ondownload', 0))
        PLEX_UPDATE_LIBRARY = bool(check_setting_int(CFG, 'Plex', 'plex_update_library', 0))
        PLEX_SERVER_HOST = check_setting_str(CFG, 'Plex', 'plex_server_host', '')
        PLEX_HOST = check_setting_str(CFG, 'Plex', 'plex_host', '')
        PLEX_USERNAME = check_setting_str(CFG, 'Plex', 'plex_username', '')
        PLEX_PASSWORD = check_setting_str(CFG, 'Plex', 'plex_password', '')

        CheckSection(CFG, 'Growl')
        USE_GROWL = bool(check_setting_int(CFG, 'Growl', 'use_growl', 0))
        GROWL_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Growl', 'growl_notify_onsnatch', 0))
        GROWL_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Growl', 'growl_notify_ondownload', 0))
        GROWL_HOST = check_setting_str(CFG, 'Growl', 'growl_host', '')
        GROWL_PASSWORD = check_setting_str(CFG, 'Growl', 'growl_password', '')

        CheckSection(CFG, 'Prowl')
        USE_PROWL = bool(check_setting_int(CFG, 'Prowl', 'use_prowl', 0))
        PROWL_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Prowl', 'prowl_notify_onsnatch', 0))
        PROWL_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Prowl', 'prowl_notify_ondownload', 0))
        PROWL_API = check_setting_str(CFG, 'Prowl', 'prowl_api', '')
        PROWL_PRIORITY = check_setting_str(CFG, 'Prowl', 'prowl_priority', "0")

        CheckSection(CFG, 'Twitter')
        USE_TWITTER = bool(check_setting_int(CFG, 'Twitter', 'use_twitter', 0))
        TWITTER_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Twitter', 'twitter_notify_onsnatch', 0))
        TWITTER_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Twitter', 'twitter_notify_ondownload', 0))
        TWITTER_USERNAME = check_setting_str(CFG, 'Twitter', 'twitter_username', '')
        TWITTER_PASSWORD = check_setting_str(CFG, 'Twitter', 'twitter_password', '')
        TWITTER_PREFIX = check_setting_str(CFG, 'Twitter', 'twitter_prefix', 'Sick Beard')

        CheckSection(CFG, 'Boxcar')
        USE_BOXCAR = bool(check_setting_int(CFG, 'Boxcar', 'use_boxcar', 0))
        BOXCAR_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Boxcar', 'boxcar_notify_onsnatch', 0))
        BOXCAR_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Boxcar', 'boxcar_notify_ondownload', 0))
        BOXCAR_USERNAME = check_setting_str(CFG, 'Boxcar', 'boxcar_username', '')

        CheckSection(CFG, 'Pushover')
        USE_PUSHOVER = bool(check_setting_int(CFG, 'Pushover', 'use_pushover', 0))
        PUSHOVER_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Pushover', 'pushover_notify_onsnatch', 0))
        PUSHOVER_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Pushover', 'pushover_notify_ondownload', 0))
        PUSHOVER_USERKEY = check_setting_str(CFG, 'Pushover', 'pushover_userkey', '')

        CheckSection(CFG, 'Libnotify')
        USE_LIBNOTIFY = bool(check_setting_int(CFG, 'Libnotify', 'use_libnotify', 0))
        LIBNOTIFY_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Libnotify', 'libnotify_notify_onsnatch', 0))
        LIBNOTIFY_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Libnotify', 'libnotify_notify_ondownload', 0))

        CheckSection(CFG, 'NMJ')
        USE_NMJ = bool(check_setting_int(CFG, 'NMJ', 'use_nmj', 0))
        NMJ_HOST = check_setting_str(CFG, 'NMJ', 'nmj_host', '')
        NMJ_DATABASE = check_setting_str(CFG, 'NMJ', 'nmj_database', '')
        NMJ_MOUNT = check_setting_str(CFG, 'NMJ', 'nmj_mount', '')

        CheckSection(CFG, 'NMJv2')
        USE_NMJv2 = bool(check_setting_int(CFG, 'NMJv2', 'use_nmjv2', 0))
        NMJv2_HOST = check_setting_str(CFG, 'NMJv2', 'nmjv2_host', '')
        NMJv2_DATABASE = check_setting_str(CFG, 'NMJv2', 'nmjv2_database', '')
        NMJv2_DBLOC = check_setting_str(CFG, 'NMJv2', 'nmjv2_dbloc', '')

        CheckSection(CFG, 'Synology')
        USE_SYNOINDEX = bool(check_setting_int(CFG, 'Synology', 'use_synoindex', 0))

        CheckSection(CFG, 'Trakt')
        USE_TRAKT = bool(check_setting_int(CFG, 'Trakt', 'use_trakt', 0))
        TRAKT_USERNAME = check_setting_str(CFG, 'Trakt', 'trakt_username', '')
        TRAKT_PASSWORD = check_setting_str(CFG, 'Trakt', 'trakt_password', '')
        TRAKT_API = check_setting_str(CFG, 'Trakt', 'trakt_api', '')

        CheckSection(CFG, 'pyTivo')
        USE_PYTIVO = bool(check_setting_int(CFG, 'pyTivo', 'use_pytivo', 0))
        PYTIVO_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'pyTivo', 'pytivo_notify_onsnatch', 0))
        PYTIVO_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'pyTivo', 'pytivo_notify_ondownload', 0))
        PYTIVO_UPDATE_LIBRARY = bool(check_setting_int(CFG, 'pyTivo', 'pyTivo_update_library', 0))
        PYTIVO_HOST = check_setting_str(CFG, 'pyTivo', 'pytivo_host', '')
        PYTIVO_SHARE_NAME = check_setting_str(CFG, 'pyTivo', 'pytivo_share_name', '')
        PYTIVO_TIVO_NAME = check_setting_str(CFG, 'pyTivo', 'pytivo_tivo_name', '')

        CheckSection(CFG, 'NMA')
        USE_NMA = bool(check_setting_int(CFG, 'NMA', 'use_nma', 0))
        NMA_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'NMA', 'nma_notify_onsnatch', 0))
        NMA_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'NMA', 'nma_notify_ondownload', 0))
        NMA_API = check_setting_str(CFG, 'NMA', 'nma_api', '')
        NMA_PRIORITY = check_setting_str(CFG, 'NMA', 'nma_priority', "0")

        if not os.path.isfile(CONFIG_FILE):
            logger.log(u"Unable to find '" + CONFIG_FILE + "', all settings will be default!", logger.DEBUG)
            save_config()

        # start up all the threads
        logger.sb_log_instance.initLogging(consoleLogging=consoleLogging)

        # initialize the main SB database
        db.upgradeDatabase(db.DBConnection(), mainDB.InitialSchema)

        # initialize the cache database
        db.upgradeDatabase(db.DBConnection("cache.db"), cache_db.InitialSchema)

        # fix up any db problems
        db.sanityCheckDatabase(db.DBConnection(), mainDB.MainSanityCheck)

        # migrate the config if it needs it
        migrator = ConfigMigrator(CFG)
        migrator.migrate_config()

        # initialize metadata_providers
        metadata_provider_dict = metadata.get_metadata_generator_dict()
        for cur_metadata_tuple in [(METADATA_XBMC, metadata.xbmc),
                                   (METADATA_XBMC_12PLUS, metadata.xbmc_12plus),
                                   (METADATA_MEDIABROWSER, metadata.mediabrowser),
                                   (METADATA_PS3, metadata.ps3),
                                   (METADATA_WDTV, metadata.wdtv),
                                   (METADATA_TIVO, metadata.tivo),
                                   (METADATA_MEDE8ER, metadata.mede8er)
                                   ]:

            (cur_metadata_config, cur_metadata_class) = cur_metadata_tuple
            tmp_provider = cur_metadata_class.metadata_class()
            tmp_provider.set_config(cur_metadata_config)
            metadata_provider_dict[tmp_provider.name] = tmp_provider

        # initialize newznab providers
        newznabProviderList = providers.getNewznabProviderList(NEWZNAB_DATA)
        providerList = providers.makeProviderList()

        # initialize schedulars
        currentSearchScheduler = scheduler.Scheduler(searchCurrent.CurrentSearcher(),
                                                     cycleTime=datetime.timedelta(minutes=SEARCH_FREQUENCY),
                                                     threadName="SEARCH",
                                                     runImmediately=True)

        # the interval for this is stored inside the ShowUpdater class
        showUpdaterInstance = showUpdater.ShowUpdater()
        showUpdateScheduler = scheduler.Scheduler(showUpdaterInstance,
                                               cycleTime=showUpdaterInstance.updateInterval,
                                               threadName="SHOWUPDATER",
                                               runImmediately=False)

        versionCheckScheduler = scheduler.Scheduler(versionChecker.CheckVersion(),
                                                     cycleTime=datetime.timedelta(hours=12),
                                                     threadName="CHECKVERSION",
                                                     runImmediately=True)

        showQueueScheduler = scheduler.Scheduler(show_queue.ShowQueue(),
                                               cycleTime=datetime.timedelta(seconds=3),
                                               threadName="SHOWQUEUE",
                                               silent=True)

        searchQueueScheduler = scheduler.Scheduler(search_queue.SearchQueue(),
                                               cycleTime=datetime.timedelta(seconds=3),
                                               threadName="SEARCHQUEUE",
                                               silent=True)

        properFinderInstance = properFinder.ProperFinder()
        properFinderScheduler = scheduler.Scheduler(properFinderInstance,
                                                     cycleTime=properFinderInstance.updateInterval,
                                                     threadName="FINDPROPERS",
                                                     runImmediately=False)
        if not DOWNLOAD_PROPERS:
            properFinderScheduler.silent = True

        autoPostProcesserScheduler = scheduler.Scheduler(autoPostProcesser.PostProcesser(),
                                                     cycleTime=datetime.timedelta(minutes=10),
                                                     threadName="POSTPROCESSER",
                                                     runImmediately=True)
        if not PROCESS_AUTOMATICALLY:
            autoPostProcesserScheduler.silent = True

        backlogSearchScheduler = searchBacklog.BacklogSearchScheduler(searchBacklog.BacklogSearcher(),
                                                                      cycleTime=datetime.timedelta(minutes=get_backlog_cycle_time()),
                                                                      threadName="BACKLOG",
                                                                      runImmediately=True)
        backlogSearchScheduler.action.cycleTime = BACKLOG_SEARCH_FREQUENCY

        showList = []
        loadingShowList = {}

        __INITIALIZED__ = True
        return True
Example #10
0
def initialize(consoleLogging=True):

    with INIT_LOCK:

        global LOG_DIR, WEB_PORT, WEB_LOG, WEB_ROOT, WEB_USERNAME, WEB_PASSWORD, WEB_HOST, WEB_IPV6, USE_API, API_KEY, ENABLE_HTTPS, HTTPS_CERT, HTTPS_KEY, USE_NZBS, USE_TORRENTS, NZB_METHOD, NZB_DIR, DOWNLOAD_PROPERS, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, SAB_HOST, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_HOST, currentSearchScheduler, backlogSearchScheduler, USE_XBMC, XBMC_NOTIFY_ONSNATCH, XBMC_NOTIFY_ONDOWNLOAD, XBMC_UPDATE_FULL, XBMC_UPDATE_LIBRARY, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, USE_TRAKT, TRAKT_USERNAME, TRAKT_PASSWORD, TRAKT_API, USE_PLEX, PLEX_NOTIFY_ONSNATCH, PLEX_NOTIFY_ONDOWNLOAD, PLEX_UPDATE_LIBRARY, PLEX_SERVER_HOST, PLEX_HOST, PLEX_USERNAME, PLEX_PASSWORD, showUpdateScheduler, __INITIALIZED__, LAUNCH_BROWSER, showList, loadingShowList, NZBS, NZBS_UID, NZBS_HASH, EZRSS, TVTORRENTS, TVTORRENTS_DIGEST, TVTORRENTS_HASH, BTN, BTN_API_KEY, TORRENT_DIR, USENET_RETENTION, SOCKET_TIMEOUT, SEARCH_FREQUENCY, DEFAULT_SEARCH_FREQUENCY, BACKLOG_SEARCH_FREQUENCY, QUALITY_DEFAULT, FLATTEN_FOLDERS_DEFAULT, STATUS_DEFAULT, GROWL_NOTIFY_ONSNATCH, GROWL_NOTIFY_ONDOWNLOAD, TWITTER_NOTIFY_ONSNATCH, TWITTER_NOTIFY_ONDOWNLOAD, USE_GROWL, GROWL_HOST, GROWL_PASSWORD, USE_PROWL, PROWL_NOTIFY_ONSNATCH, PROWL_NOTIFY_ONDOWNLOAD, PROWL_API, PROWL_PRIORITY, PROG_DIR, NZBMATRIX, NZBMATRIX_USERNAME, USE_PYTIVO, PYTIVO_NOTIFY_ONSNATCH, PYTIVO_NOTIFY_ONDOWNLOAD, PYTIVO_UPDATE_LIBRARY, PYTIVO_HOST, PYTIVO_SHARE_NAME, PYTIVO_TIVO_NAME, USE_CMDNOTIFY, CMDNOTIFY_UPDATE_CMD, CMDNOTIFY_I_KNOW_WHAT_I_AM_DOING, USE_NMA, NMA_NOTIFY_ONSNATCH, NMA_NOTIFY_ONDOWNLOAD, NMA_API, NMA_PRIORITY, NZBMATRIX_APIKEY, versionCheckScheduler, VERSION_NOTIFY, PROCESS_AUTOMATICALLY, KEEP_PROCESSED_DIR, TV_DOWNLOAD_DIR, TVDB_BASE_URL, MIN_SEARCH_FREQUENCY, showQueueScheduler, searchQueueScheduler, ROOT_DIRS, CACHE_DIR, ACTUAL_CACHE_DIR, TVDB_API_PARMS, NAMING_PATTERN, NAMING_MULTI_EP, NAMING_FORCE_FOLDERS, NAMING_ABD_PATTERN, NAMING_CUSTOM_ABD, RENAME_EPISODES, properFinderScheduler, PROVIDER_ORDER, autoPostProcesserScheduler, NZBSRUS, NZBSRUS_UID, NZBSRUS_HASH, WOMBLE, providerList, newznabProviderList, EXTRA_SCRIPTS, USE_TWITTER, TWITTER_USERNAME, TWITTER_PASSWORD, TWITTER_PREFIX, USE_NOTIFO, NOTIFO_USERNAME, NOTIFO_APISECRET, NOTIFO_NOTIFY_ONDOWNLOAD, NOTIFO_NOTIFY_ONSNATCH, USE_BOXCAR, BOXCAR_USERNAME, BOXCAR_PASSWORD, BOXCAR_NOTIFY_ONDOWNLOAD, BOXCAR_NOTIFY_ONSNATCH, USE_PUSHOVER, PUSHOVER_USERKEY, PUSHOVER_NOTIFY_ONDOWNLOAD, PUSHOVER_NOTIFY_ONSNATCH, USE_LIBNOTIFY, LIBNOTIFY_NOTIFY_ONSNATCH, LIBNOTIFY_NOTIFY_ONDOWNLOAD, USE_NMJ, NMJ_HOST, NMJ_DATABASE, NMJ_MOUNT, USE_SYNOINDEX, USE_BANNER, USE_LISTVIEW, METADATA_XBMC, METADATA_MEDIABROWSER, METADATA_PS3, METADATA_SYNOLOGY, metadata_provider_dict, NEWZBIN, NEWZBIN_USERNAME, NEWZBIN_PASSWORD, GIT_PATH, MOVE_ASSOCIATED_FILES, COMING_EPS_LAYOUT, COMING_EPS_SORT, COMING_EPS_DISPLAY_PAUSED, METADATA_WDTV, METADATA_TIVO, IGNORE_WORDS, CREATE_MISSING_SHOW_DIRS, ADD_SHOWS_WO_DIR

        if __INITIALIZED__:
            return False

        socket.setdefaulttimeout(SOCKET_TIMEOUT)

        CheckSection(CFG, "General")
        LOG_DIR = check_setting_str(CFG, "General", "log_dir", "Logs")
        if not helpers.makeDir(LOG_DIR):
            logger.log(u"!!! No log folder, logging to screen only!", logger.ERROR)

        try:
            WEB_PORT = check_setting_int(CFG, "General", "web_port", 8081)
        except:
            WEB_PORT = 8081

        if WEB_PORT < 21 or WEB_PORT > 65535:
            WEB_PORT = 8081

        WEB_HOST = check_setting_str(CFG, "General", "web_host", "0.0.0.0")
        WEB_IPV6 = bool(check_setting_int(CFG, "General", "web_ipv6", 0))
        WEB_ROOT = check_setting_str(CFG, "General", "web_root", "").rstrip("/")
        WEB_LOG = bool(check_setting_int(CFG, "General", "web_log", 0))
        WEB_USERNAME = check_setting_str(CFG, "General", "web_username", "")
        WEB_PASSWORD = check_setting_str(CFG, "General", "web_password", "")
        LAUNCH_BROWSER = bool(check_setting_int(CFG, "General", "launch_browser", 1))

        USE_API = bool(check_setting_int(CFG, "General", "use_api", 0))
        API_KEY = check_setting_str(CFG, "General", "api_key", "")

        ENABLE_HTTPS = bool(check_setting_int(CFG, "General", "enable_https", 0))
        HTTPS_CERT = check_setting_str(CFG, "General", "https_cert", "server.crt")
        HTTPS_KEY = check_setting_str(CFG, "General", "https_key", "server.key")

        ACTUAL_CACHE_DIR = check_setting_str(CFG, "General", "cache_dir", "cache")
        # fix bad configs due to buggy code
        if ACTUAL_CACHE_DIR == "None":
            ACTUAL_CACHE_DIR = "cache"

        # unless they specify, put the cache dir inside the data dir
        if not os.path.isabs(ACTUAL_CACHE_DIR):
            CACHE_DIR = os.path.join(DATA_DIR, ACTUAL_CACHE_DIR)
        else:
            CACHE_DIR = ACTUAL_CACHE_DIR

        if not helpers.makeDir(CACHE_DIR):
            logger.log(u"!!! Creating local cache dir failed, using system default", logger.ERROR)
            CACHE_DIR = None

        ROOT_DIRS = check_setting_str(CFG, "General", "root_dirs", "")
        if not re.match(r"\d+\|[^|]+(?:\|[^|]+)*", ROOT_DIRS):
            ROOT_DIRS = ""

        proxies = urllib.getproxies()
        proxy_url = None  # @UnusedVariable
        if "http" in proxies:
            proxy_url = proxies["http"]  # @UnusedVariable
        elif "ftp" in proxies:
            proxy_url = proxies["ftp"]  # @UnusedVariable

        # Set our common tvdb_api options here
        TVDB_API_PARMS = {"apikey": TVDB_API_KEY, "language": "en", "useZip": True}

        if CACHE_DIR:
            TVDB_API_PARMS["cache"] = os.path.join(CACHE_DIR, "tvdb")

        TVDB_BASE_URL = "http://www.thetvdb.com/api/" + TVDB_API_KEY

        QUALITY_DEFAULT = check_setting_int(CFG, "General", "quality_default", SD)
        STATUS_DEFAULT = check_setting_int(CFG, "General", "status_default", SKIPPED)
        VERSION_NOTIFY = check_setting_int(CFG, "General", "version_notify", 1)
        FLATTEN_FOLDERS_DEFAULT = bool(check_setting_int(CFG, "General", "flatten_folders_default", 0))

        PROVIDER_ORDER = check_setting_str(CFG, "General", "provider_order", "").split()

        NAMING_PATTERN = check_setting_str(CFG, "General", "naming_pattern", "")
        NAMING_ABD_PATTERN = check_setting_str(CFG, "General", "naming_abd_pattern", "")
        NAMING_CUSTOM_ABD = check_setting_int(CFG, "General", "naming_custom_abd", 0)
        NAMING_MULTI_EP = check_setting_int(CFG, "General", "naming_multi_ep", 1)
        NAMING_FORCE_FOLDERS = naming.check_force_season_folders()

        USE_NZBS = bool(check_setting_int(CFG, "General", "use_nzbs", 1))
        USE_TORRENTS = bool(check_setting_int(CFG, "General", "use_torrents", 0))

        NZB_METHOD = check_setting_str(CFG, "General", "nzb_method", "blackhole")
        if NZB_METHOD not in ("blackhole", "sabnzbd", "nzbget"):
            NZB_METHOD = "blackhole"

        DOWNLOAD_PROPERS = bool(check_setting_int(CFG, "General", "download_propers", 1))
        USENET_RETENTION = check_setting_int(CFG, "General", "usenet_retention", 500)
        SEARCH_FREQUENCY = check_setting_int(CFG, "General", "search_frequency", DEFAULT_SEARCH_FREQUENCY)
        if SEARCH_FREQUENCY < MIN_SEARCH_FREQUENCY:
            SEARCH_FREQUENCY = MIN_SEARCH_FREQUENCY

        TV_DOWNLOAD_DIR = check_setting_str(CFG, "General", "tv_download_dir", "")
        PROCESS_AUTOMATICALLY = check_setting_int(CFG, "General", "process_automatically", 0)
        RENAME_EPISODES = check_setting_int(CFG, "General", "rename_episodes", 1)
        KEEP_PROCESSED_DIR = check_setting_int(CFG, "General", "keep_processed_dir", 1)
        MOVE_ASSOCIATED_FILES = check_setting_int(CFG, "General", "move_associated_files", 0)
        CREATE_MISSING_SHOW_DIRS = check_setting_int(CFG, "General", "create_missing_show_dirs", 0)
        ADD_SHOWS_WO_DIR = check_setting_int(CFG, "General", "add_shows_wo_dir", 0)

        EZRSS = bool(check_setting_int(CFG, "General", "use_torrent", 0))
        if not EZRSS:
            CheckSection(CFG, "EZRSS")
            EZRSS = bool(check_setting_int(CFG, "EZRSS", "ezrss", 0))

        GIT_PATH = check_setting_str(CFG, "General", "git_path", "")
        IGNORE_WORDS = check_setting_str(CFG, "General", "ignore_words", IGNORE_WORDS)
        EXTRA_SCRIPTS = [x for x in check_setting_str(CFG, "General", "extra_scripts", "").split("|") if x]

        USE_BANNER = bool(check_setting_int(CFG, "General", "use_banner", 0))
        USE_LISTVIEW = bool(check_setting_int(CFG, "General", "use_listview", 0))
        METADATA_TYPE = check_setting_str(CFG, "General", "metadata_type", "")

        metadata_provider_dict = metadata.get_metadata_generator_dict()

        # if this exists it's legacy, use the info to upgrade metadata to the new settings
        if METADATA_TYPE:

            old_metadata_class = None

            if METADATA_TYPE == "xbmc":
                old_metadata_class = metadata.xbmc.metadata_class
            elif METADATA_TYPE == "mediabrowser":
                old_metadata_class = metadata.mediabrowser.metadata_class
            elif METADATA_TYPE == "ps3":
                old_metadata_class = metadata.ps3.metadata_class

            if old_metadata_class:

                METADATA_SHOW = bool(check_setting_int(CFG, "General", "metadata_show", 1))
                METADATA_EPISODE = bool(check_setting_int(CFG, "General", "metadata_episode", 1))

                ART_POSTER = bool(check_setting_int(CFG, "General", "art_poster", 1))
                ART_FANART = bool(check_setting_int(CFG, "General", "art_fanart", 1))
                ART_THUMBNAILS = bool(check_setting_int(CFG, "General", "art_thumbnails", 1))
                ART_SEASON_THUMBNAILS = bool(check_setting_int(CFG, "General", "art_season_thumbnails", 1))

                new_metadata_class = old_metadata_class(
                    METADATA_SHOW, METADATA_EPISODE, ART_POSTER, ART_FANART, ART_THUMBNAILS, ART_SEASON_THUMBNAILS
                )

                metadata_provider_dict[new_metadata_class.name] = new_metadata_class

        # this is the normal codepath for metadata config
        else:
            METADATA_XBMC = check_setting_str(CFG, "General", "metadata_xbmc", "0|0|0|0|0|0")
            METADATA_MEDIABROWSER = check_setting_str(CFG, "General", "metadata_mediabrowser", "0|0|0|0|0|0")
            METADATA_PS3 = check_setting_str(CFG, "General", "metadata_ps3", "0|0|0|0|0|0")
            METADATA_WDTV = check_setting_str(CFG, "General", "metadata_wdtv", "0|0|0|0|0|0")
            METADATA_TIVO = check_setting_str(CFG, "General", "metadata_tivo", "0|0|0|0|0|0")
            METADATA_SYNOLOGY = check_setting_str(CFG, "General", "metadata_synology", "0|0|0|0|0|0")

            for cur_metadata_tuple in [
                (METADATA_XBMC, metadata.xbmc),
                (METADATA_MEDIABROWSER, metadata.mediabrowser),
                (METADATA_PS3, metadata.ps3),
                (METADATA_WDTV, metadata.wdtv),
                (METADATA_TIVO, metadata.tivo),
                (METADATA_SYNOLOGY, metadata.synology),
            ]:

                (cur_metadata_config, cur_metadata_class) = cur_metadata_tuple
                tmp_provider = cur_metadata_class.metadata_class()
                tmp_provider.set_config(cur_metadata_config)
                metadata_provider_dict[tmp_provider.name] = tmp_provider

        CheckSection(CFG, "GUI")
        COMING_EPS_LAYOUT = check_setting_str(CFG, "GUI", "coming_eps_layout", "banner")
        COMING_EPS_DISPLAY_PAUSED = bool(check_setting_int(CFG, "GUI", "coming_eps_display_paused", 0))
        COMING_EPS_SORT = check_setting_str(CFG, "GUI", "coming_eps_sort", "date")

        CheckSection(CFG, "Newznab")
        newznabData = check_setting_str(CFG, "Newznab", "newznab_data", "")
        newznabProviderList = providers.getNewznabProviderList(newznabData)
        providerList = providers.makeProviderList()

        CheckSection(CFG, "Blackhole")
        NZB_DIR = check_setting_str(CFG, "Blackhole", "nzb_dir", "")
        TORRENT_DIR = check_setting_str(CFG, "Blackhole", "torrent_dir", "")

        CheckSection(CFG, "TVTORRENTS")
        TVTORRENTS = bool(check_setting_int(CFG, "TVTORRENTS", "tvtorrents", 0))
        TVTORRENTS_DIGEST = check_setting_str(CFG, "TVTORRENTS", "tvtorrents_digest", "")
        TVTORRENTS_HASH = check_setting_str(CFG, "TVTORRENTS", "tvtorrents_hash", "")

        CheckSection(CFG, "BTN")
        BTN = bool(check_setting_int(CFG, "BTN", "btn", 0))
        BTN_API_KEY = check_setting_str(CFG, "BTN", "btn_api_key", "")

        CheckSection(CFG, "NZBs")
        NZBS = bool(check_setting_int(CFG, "NZBs", "nzbs", 0))
        NZBS_UID = check_setting_str(CFG, "NZBs", "nzbs_uid", "")
        NZBS_HASH = check_setting_str(CFG, "NZBs", "nzbs_hash", "")

        CheckSection(CFG, "NZBsRUS")
        NZBSRUS = bool(check_setting_int(CFG, "NZBsRUS", "nzbsrus", 0))
        NZBSRUS_UID = check_setting_str(CFG, "NZBsRUS", "nzbsrus_uid", "")
        NZBSRUS_HASH = check_setting_str(CFG, "NZBsRUS", "nzbsrus_hash", "")

        CheckSection(CFG, "NZBMatrix")
        NZBMATRIX = bool(check_setting_int(CFG, "NZBMatrix", "nzbmatrix", 0))
        NZBMATRIX_USERNAME = check_setting_str(CFG, "NZBMatrix", "nzbmatrix_username", "")
        NZBMATRIX_APIKEY = check_setting_str(CFG, "NZBMatrix", "nzbmatrix_apikey", "")

        CheckSection(CFG, "Newzbin")
        NEWZBIN = bool(check_setting_int(CFG, "Newzbin", "newzbin", 0))
        NEWZBIN_USERNAME = check_setting_str(CFG, "Newzbin", "newzbin_username", "")
        NEWZBIN_PASSWORD = check_setting_str(CFG, "Newzbin", "newzbin_password", "")

        CheckSection(CFG, "Womble")
        WOMBLE = bool(check_setting_int(CFG, "Womble", "womble", 1))

        CheckSection(CFG, "SABnzbd")
        SAB_USERNAME = check_setting_str(CFG, "SABnzbd", "sab_username", "")
        SAB_PASSWORD = check_setting_str(CFG, "SABnzbd", "sab_password", "")
        SAB_APIKEY = check_setting_str(CFG, "SABnzbd", "sab_apikey", "")
        SAB_CATEGORY = check_setting_str(CFG, "SABnzbd", "sab_category", "tv")
        SAB_HOST = check_setting_str(CFG, "SABnzbd", "sab_host", "")

        CheckSection(CFG, "NZBget")
        NZBGET_PASSWORD = check_setting_str(CFG, "NZBget", "nzbget_password", "tegbzn6789")
        NZBGET_CATEGORY = check_setting_str(CFG, "NZBget", "nzbget_category", "tv")
        NZBGET_HOST = check_setting_str(CFG, "NZBget", "nzbget_host", "")

        CheckSection(CFG, "XBMC")
        USE_XBMC = bool(check_setting_int(CFG, "XBMC", "use_xbmc", 0))
        XBMC_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, "XBMC", "xbmc_notify_onsnatch", 0))
        XBMC_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, "XBMC", "xbmc_notify_ondownload", 0))
        XBMC_UPDATE_LIBRARY = bool(check_setting_int(CFG, "XBMC", "xbmc_update_library", 0))
        XBMC_UPDATE_FULL = bool(check_setting_int(CFG, "XBMC", "xbmc_update_full", 0))
        XBMC_HOST = check_setting_str(CFG, "XBMC", "xbmc_host", "")
        XBMC_USERNAME = check_setting_str(CFG, "XBMC", "xbmc_username", "")
        XBMC_PASSWORD = check_setting_str(CFG, "XBMC", "xbmc_password", "")

        CheckSection(CFG, "Cmdnotify")
        USE_CMDNOTIFY = bool(check_setting_int(CFG, "Cmdnotify", "use_cmdnotify", 0))
        CMDNOTIFY_UPDATE_CMD = check_setting_str(CFG, "Cmdnotify", "cmdnotify_update_cmd", "")
        CMDNOTIFY_I_KNOW_WHAT_I_AM_DOING = bool(
            check_setting_int(CFG, "Cmdnotify", "cmdnotify_I_KNOW_WHAT_I_AM_DOING", 0)
        )

        CheckSection(CFG, "Plex")
        USE_PLEX = bool(check_setting_int(CFG, "Plex", "use_plex", 0))
        PLEX_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, "Plex", "plex_notify_onsnatch", 0))
        PLEX_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, "Plex", "plex_notify_ondownload", 0))
        PLEX_UPDATE_LIBRARY = bool(check_setting_int(CFG, "Plex", "plex_update_library", 0))
        PLEX_SERVER_HOST = check_setting_str(CFG, "Plex", "plex_server_host", "")
        PLEX_HOST = check_setting_str(CFG, "Plex", "plex_host", "")
        PLEX_USERNAME = check_setting_str(CFG, "Plex", "plex_username", "")
        PLEX_PASSWORD = check_setting_str(CFG, "Plex", "plex_password", "")

        CheckSection(CFG, "Growl")
        USE_GROWL = bool(check_setting_int(CFG, "Growl", "use_growl", 0))
        GROWL_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, "Growl", "growl_notify_onsnatch", 0))
        GROWL_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, "Growl", "growl_notify_ondownload", 0))
        GROWL_HOST = check_setting_str(CFG, "Growl", "growl_host", "")
        GROWL_PASSWORD = check_setting_str(CFG, "Growl", "growl_password", "")

        CheckSection(CFG, "Prowl")
        USE_PROWL = bool(check_setting_int(CFG, "Prowl", "use_prowl", 0))
        PROWL_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, "Prowl", "prowl_notify_onsnatch", 0))
        PROWL_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, "Prowl", "prowl_notify_ondownload", 0))
        PROWL_API = check_setting_str(CFG, "Prowl", "prowl_api", "")
        PROWL_PRIORITY = check_setting_str(CFG, "Prowl", "prowl_priority", "0")

        CheckSection(CFG, "Twitter")
        USE_TWITTER = bool(check_setting_int(CFG, "Twitter", "use_twitter", 0))
        TWITTER_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, "Twitter", "twitter_notify_onsnatch", 0))
        TWITTER_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, "Twitter", "twitter_notify_ondownload", 0))
        TWITTER_USERNAME = check_setting_str(CFG, "Twitter", "twitter_username", "")
        TWITTER_PASSWORD = check_setting_str(CFG, "Twitter", "twitter_password", "")
        TWITTER_PREFIX = check_setting_str(CFG, "Twitter", "twitter_prefix", "Sick Beard")

        CheckSection(CFG, "Notifo")
        USE_NOTIFO = bool(check_setting_int(CFG, "Notifo", "use_notifo", 0))
        NOTIFO_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, "Notifo", "notifo_notify_onsnatch", 0))
        NOTIFO_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, "Notifo", "notifo_notify_ondownload", 0))
        NOTIFO_USERNAME = check_setting_str(CFG, "Notifo", "notifo_username", "")
        NOTIFO_APISECRET = check_setting_str(CFG, "Notifo", "notifo_apisecret", "")

        CheckSection(CFG, "Boxcar")
        USE_BOXCAR = bool(check_setting_int(CFG, "Boxcar", "use_boxcar", 0))
        BOXCAR_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, "Boxcar", "boxcar_notify_onsnatch", 0))
        BOXCAR_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, "Boxcar", "boxcar_notify_ondownload", 0))
        BOXCAR_USERNAME = check_setting_str(CFG, "Boxcar", "boxcar_username", "")

        CheckSection(CFG, "Pushover")
        USE_PUSHOVER = bool(check_setting_int(CFG, "Pushover", "use_pushover", 0))
        PUSHOVER_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, "Pushover", "pushover_notify_onsnatch", 0))
        PUSHOVER_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, "Pushover", "pushover_notify_ondownload", 0))
        PUSHOVER_USERKEY = check_setting_str(CFG, "Pushover", "pushover_userkey", "")

        CheckSection(CFG, "Libnotify")
        USE_LIBNOTIFY = bool(check_setting_int(CFG, "Libnotify", "use_libnotify", 0))
        LIBNOTIFY_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, "Libnotify", "libnotify_notify_onsnatch", 0))
        LIBNOTIFY_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, "Libnotify", "libnotify_notify_ondownload", 0))

        CheckSection(CFG, "NMJ")
        USE_NMJ = bool(check_setting_int(CFG, "NMJ", "use_nmj", 0))
        NMJ_HOST = check_setting_str(CFG, "NMJ", "nmj_host", "")
        NMJ_DATABASE = check_setting_str(CFG, "NMJ", "nmj_database", "")
        NMJ_MOUNT = check_setting_str(CFG, "NMJ", "nmj_mount", "")

        CheckSection(CFG, "Synology")
        USE_SYNOINDEX = bool(check_setting_int(CFG, "Synology", "use_synoindex", 0))

        CheckSection(CFG, "Trakt")
        USE_TRAKT = bool(check_setting_int(CFG, "Trakt", "use_trakt", 0))
        TRAKT_USERNAME = check_setting_str(CFG, "Trakt", "trakt_username", "")
        TRAKT_PASSWORD = check_setting_str(CFG, "Trakt", "trakt_password", "")
        TRAKT_API = check_setting_str(CFG, "Trakt", "trakt_api", "")

        CheckSection(CFG, "pyTivo")
        USE_PYTIVO = bool(check_setting_int(CFG, "pyTivo", "use_pytivo", 0))
        PYTIVO_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, "pyTivo", "pytivo_notify_onsnatch", 0))
        PYTIVO_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, "pyTivo", "pytivo_notify_ondownload", 0))
        PYTIVO_UPDATE_LIBRARY = bool(check_setting_int(CFG, "pyTivo", "pyTivo_update_library", 0))
        PYTIVO_HOST = check_setting_str(CFG, "pyTivo", "pytivo_host", "")
        PYTIVO_SHARE_NAME = check_setting_str(CFG, "pyTivo", "pytivo_share_name", "")
        PYTIVO_TIVO_NAME = check_setting_str(CFG, "pyTivo", "pytivo_tivo_name", "")

        CheckSection(CFG, "NMA")
        USE_NMA = bool(check_setting_int(CFG, "NMA", "use_nma", 0))
        NMA_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, "NMA", "nma_notify_onsnatch", 0))
        NMA_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, "NMA", "nma_notify_ondownload", 0))
        NMA_API = check_setting_str(CFG, "NMA", "nma_api", "")
        NMA_PRIORITY = check_setting_str(CFG, "NMA", "nma_priority", "0")

        # start up all the threads
        logger.sb_log_instance.initLogging(consoleLogging=consoleLogging)

        # initialize the main SB database
        db.upgradeDatabase(db.DBConnection(), mainDB.InitialSchema)

        # initialize the cache database
        db.upgradeDatabase(db.DBConnection("cache.db"), cache_db.InitialSchema)

        # fix up any db problems
        db.sanityCheckDatabase(db.DBConnection(), mainDB.MainSanityCheck)

        # migrate the config if it needs it
        migrator = ConfigMigrator(CFG)
        migrator.migrate_config()

        currentSearchScheduler = scheduler.Scheduler(
            searchCurrent.CurrentSearcher(),
            cycleTime=datetime.timedelta(minutes=SEARCH_FREQUENCY),
            threadName="SEARCH",
            runImmediately=True,
        )

        # the interval for this is stored inside the ShowUpdater class
        showUpdaterInstance = showUpdater.ShowUpdater()
        showUpdateScheduler = scheduler.Scheduler(
            showUpdaterInstance,
            cycleTime=showUpdaterInstance.updateInterval,
            threadName="SHOWUPDATER",
            runImmediately=False,
        )

        versionCheckScheduler = scheduler.Scheduler(
            versionChecker.CheckVersion(),
            cycleTime=datetime.timedelta(hours=12),
            threadName="CHECKVERSION",
            runImmediately=True,
        )

        showQueueScheduler = scheduler.Scheduler(
            show_queue.ShowQueue(), cycleTime=datetime.timedelta(seconds=3), threadName="SHOWQUEUE", silent=True
        )

        searchQueueScheduler = scheduler.Scheduler(
            search_queue.SearchQueue(), cycleTime=datetime.timedelta(seconds=3), threadName="SEARCHQUEUE", silent=True
        )

        properFinderInstance = properFinder.ProperFinder()
        properFinderScheduler = scheduler.Scheduler(
            properFinderInstance,
            cycleTime=properFinderInstance.updateInterval,
            threadName="FINDPROPERS",
            runImmediately=False,
        )

        autoPostProcesserScheduler = scheduler.Scheduler(
            autoPostProcesser.PostProcesser(),
            cycleTime=datetime.timedelta(minutes=10),
            threadName="POSTPROCESSER",
            runImmediately=True,
        )

        backlogSearchScheduler = searchBacklog.BacklogSearchScheduler(
            searchBacklog.BacklogSearcher(),
            cycleTime=datetime.timedelta(minutes=get_backlog_cycle_time()),
            threadName="BACKLOG",
            runImmediately=True,
        )
        backlogSearchScheduler.action.cycleTime = BACKLOG_SEARCH_FREQUENCY

        showList = []
        loadingShowList = {}

        __INITIALIZED__ = True
        return True
Example #11
0
    def savePostProcessing(self, kodi_data=None, kodi_12plus_data=None,
                           mediabrowser_data=None, sony_ps3_data=None,
                           wdtv_data=None, tivo_data=None, mede8er_data=None,
                           keep_processed_dir=None, process_method=None,
                           del_rar_contents=None, process_automatically=None,
                           no_delete=None, rename_episodes=None, airdate_episodes=None,
                           file_timestamp_timezone=None, unpack=None,
                           move_associated_files=None, sync_files=None,
                           postpone_if_sync_files=None, postpone_if_no_subs=None,
                           allowed_extensions=None, tv_download_dir=None,
                           create_missing_show_dirs=None, add_shows_wo_dir=None,
                           extra_scripts=None, nfo_rename=None,
                           naming_pattern=None, naming_multi_ep=None,
                           naming_custom_abd=None, naming_anime=None,
                           naming_abd_pattern=None, naming_strip_year=None,
                           naming_custom_sports=None, naming_sports_pattern=None,
                           naming_custom_anime=None, naming_anime_pattern=None,
                           naming_anime_multi_ep=None, autopostprocessor_frequency=None):

        results = []

        if not config.change_TV_DOWNLOAD_DIR(tv_download_dir):
            results += ['Unable to create directory {dir}, '
                        'dir not changed.'.format(dir=ek(os.path.normpath, tv_download_dir))]

        config.change_AUTOPOSTPROCESSOR_FREQUENCY(autopostprocessor_frequency)
        config.change_PROCESS_AUTOMATICALLY(process_automatically)

        if unpack:
            if self.isRarSupported() != 'not supported':
                sickbeard.UNPACK = config.checkbox_to_value(unpack)
            else:
                sickbeard.UNPACK = 0
                results.append('Unpacking Not Supported, disabling unpack setting')
        else:
            sickbeard.UNPACK = config.checkbox_to_value(unpack)
        sickbeard.NO_DELETE = config.checkbox_to_value(no_delete)
        sickbeard.KEEP_PROCESSED_DIR = config.checkbox_to_value(keep_processed_dir)
        sickbeard.CREATE_MISSING_SHOW_DIRS = config.checkbox_to_value(create_missing_show_dirs)
        sickbeard.ADD_SHOWS_WO_DIR = config.checkbox_to_value(add_shows_wo_dir)
        sickbeard.PROCESS_METHOD = process_method
        sickbeard.DELRARCONTENTS = config.checkbox_to_value(del_rar_contents)
        sickbeard.EXTRA_SCRIPTS = [x.strip() for x in extra_scripts.split('|') if x.strip()]
        sickbeard.RENAME_EPISODES = config.checkbox_to_value(rename_episodes)
        sickbeard.AIRDATE_EPISODES = config.checkbox_to_value(airdate_episodes)
        sickbeard.FILE_TIMESTAMP_TIMEZONE = file_timestamp_timezone
        sickbeard.MOVE_ASSOCIATED_FILES = config.checkbox_to_value(move_associated_files)
        sickbeard.SYNC_FILES = sync_files
        sickbeard.POSTPONE_IF_SYNC_FILES = config.checkbox_to_value(postpone_if_sync_files)
        sickbeard.POSTPONE_IF_NO_SUBS = config.checkbox_to_value(postpone_if_no_subs)
        # If 'postpone if no subs' is enabled, we must have SRT in allowed extensions list
        if sickbeard.POSTPONE_IF_NO_SUBS:
            allowed_extensions += ',srt'
            # # Auto PP must be disabled because FINDSUBTITLE thread that calls manual PP (like nzbtomedia)
            # sickbeard.PROCESS_AUTOMATICALLY = 0
        sickbeard.ALLOWED_EXTENSIONS = ','.join({x.strip() for x in allowed_extensions.split(',') if x.strip()})
        sickbeard.NAMING_CUSTOM_ABD = config.checkbox_to_value(naming_custom_abd)
        sickbeard.NAMING_CUSTOM_SPORTS = config.checkbox_to_value(naming_custom_sports)
        sickbeard.NAMING_CUSTOM_ANIME = config.checkbox_to_value(naming_custom_anime)
        sickbeard.NAMING_STRIP_YEAR = config.checkbox_to_value(naming_strip_year)
        sickbeard.NFO_RENAME = config.checkbox_to_value(nfo_rename)

        sickbeard.METADATA_KODI = kodi_data
        sickbeard.METADATA_KODI_12PLUS = kodi_12plus_data
        sickbeard.METADATA_MEDIABROWSER = mediabrowser_data
        sickbeard.METADATA_PS3 = sony_ps3_data
        sickbeard.METADATA_WDTV = wdtv_data
        sickbeard.METADATA_TIVO = tivo_data
        sickbeard.METADATA_MEDE8ER = mede8er_data

        sickbeard.metadata_provider_dict['KODI'].set_config(sickbeard.METADATA_KODI)
        sickbeard.metadata_provider_dict['KODI 12+'].set_config(sickbeard.METADATA_KODI_12PLUS)
        sickbeard.metadata_provider_dict['MediaBrowser'].set_config(sickbeard.METADATA_MEDIABROWSER)
        sickbeard.metadata_provider_dict['Sony PS3'].set_config(sickbeard.METADATA_PS3)
        sickbeard.metadata_provider_dict['WDTV'].set_config(sickbeard.METADATA_WDTV)
        sickbeard.metadata_provider_dict['TIVO'].set_config(sickbeard.METADATA_TIVO)
        sickbeard.metadata_provider_dict['Mede8er'].set_config(sickbeard.METADATA_MEDE8ER)

        if self.isNamingValid(naming_pattern, naming_multi_ep, anime_type=naming_anime) != 'invalid':
            sickbeard.NAMING_PATTERN = naming_pattern
            sickbeard.NAMING_MULTI_EP = int(naming_multi_ep)
            sickbeard.NAMING_ANIME = int(naming_anime)
            sickbeard.NAMING_FORCE_FOLDERS = naming.check_force_season_folders()
        else:
            if int(naming_anime) in [1, 2]:
                results.append('You tried saving an invalid anime naming config, not saving your naming settings')
            else:
                results.append('You tried saving an invalid naming config, not saving your naming settings')

        if self.isNamingValid(naming_anime_pattern, naming_anime_multi_ep, anime_type=naming_anime) != 'invalid':
            sickbeard.NAMING_ANIME_PATTERN = naming_anime_pattern
            sickbeard.NAMING_ANIME_MULTI_EP = int(naming_anime_multi_ep)
            sickbeard.NAMING_ANIME = int(naming_anime)
            sickbeard.NAMING_FORCE_FOLDERS = naming.check_force_season_folders()
        else:
            if int(naming_anime) in [1, 2]:
                results.append('You tried saving an invalid anime naming config, not saving your naming settings')
            else:
                results.append('You tried saving an invalid naming config, not saving your naming settings')

        if self.isNamingValid(naming_abd_pattern, None, abd=True) != 'invalid':
            sickbeard.NAMING_ABD_PATTERN = naming_abd_pattern
        else:
            results.append(
                'You tried saving an invalid air-by-date naming config, not saving your air-by-date settings')

        if self.isNamingValid(naming_sports_pattern, None, sports=True) != 'invalid':
            sickbeard.NAMING_SPORTS_PATTERN = naming_sports_pattern
        else:
            results.append(
                'You tried saving an invalid sports naming config, not saving your sports settings')

        sickbeard.save_config()

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

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