Пример #1
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'
Пример #2
0
    def _migrate_v1(self):
        """
        Reads in the old naming settings from your config and generates a new config template from them.
        """

        app.NAMING_PATTERN = self._name_to_pattern()
        log.info(u"Based on your old settings I'm setting your new naming pattern to: {pattern}",
                 {'pattern': app.NAMING_PATTERN})

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

        if app.NAMING_CUSTOM_ABD:
            app.NAMING_ABD_PATTERN = self._name_to_pattern(True)
            log.info(u'Adding a custom air-by-date naming pattern to your config: {pattern}',
                     {'pattern': app.NAMING_ABD_PATTERN})
        else:
            app.NAMING_ABD_PATTERN = naming.name_abd_presets[0]

        app.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
        main_db_con = db.DBConnection()
        season_folder_shows = main_db_con.select(b'SELECT indexer_id FROM tv_shows WHERE flatten_folders = 0 LIMIT 1')

        # 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')

                    log.info(
                        u'Changed season folder format from {old_season_format} to {new_season_format}, '
                        u'prepending it to your naming config',
                        {'old_season_format': old_season_format, 'new_season_format': new_season_format}
                    )
                    app.NAMING_PATTERN = new_season_format + os.sep + app.NAMING_PATTERN

                except (TypeError, ValueError):
                    log.error(u"Can't change {old_season_format} to new season format",
                              {'old_season_format': old_season_format})

        # if no shows had it on then don't flatten any shows and don't put season folders in the config
        else:
            log.info(u"No shows were using season folders before so I'm disabling flattening on all shows")

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

        app.NAMING_FORCE_FOLDERS = naming.check_force_season_folders()
Пример #3
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=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':
                app.UNPACK = config.checkbox_to_value(unpack)
            else:
                app.UNPACK = 0
                results.append(
                    'Unpacking Not Supported, disabling unpack setting')
        else:
            app.UNPACK = config.checkbox_to_value(unpack)
        app.NO_DELETE = config.checkbox_to_value(no_delete)
        app.KEEP_PROCESSED_DIR = config.checkbox_to_value(keep_processed_dir)
        app.CREATE_MISSING_SHOW_DIRS = config.checkbox_to_value(
            create_missing_show_dirs)
        app.ADD_SHOWS_WO_DIR = config.checkbox_to_value(add_shows_wo_dir)
        app.PROCESS_METHOD = process_method
        app.DELRARCONTENTS = config.checkbox_to_value(del_rar_contents)
        app.EXTRA_SCRIPTS = [
            _.strip() for _ in extra_scripts.split('|') if _.strip()
        ]
        app.RENAME_EPISODES = config.checkbox_to_value(rename_episodes)
        app.AIRDATE_EPISODES = config.checkbox_to_value(airdate_episodes)
        app.FILE_TIMESTAMP_TIMEZONE = file_timestamp_timezone
        app.MOVE_ASSOCIATED_FILES = config.checkbox_to_value(
            move_associated_files)
        app.SYNC_FILES = [
            _.strip() for _ in sync_files.split(',') if _.strip()
        ]
        app.POSTPONE_IF_SYNC_FILES = config.checkbox_to_value(
            postpone_if_sync_files)
        app.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 app.POSTPONE_IF_NO_SUBS:
            allowed_extensions += ',srt'
            # # Auto PP must be disabled because FINDSUBTITLE thread that calls manual PP (like nzbtomedia)
            # app.PROCESS_AUTOMATICALLY = 0
        app.ALLOWED_EXTENSIONS = {
            _.strip()
            for _ in allowed_extensions.split(',') if _.strip()
        }
        app.NAMING_CUSTOM_ABD = config.checkbox_to_value(naming_custom_abd)
        app.NAMING_CUSTOM_SPORTS = config.checkbox_to_value(
            naming_custom_sports)
        app.NAMING_CUSTOM_ANIME = config.checkbox_to_value(naming_custom_anime)
        app.NAMING_STRIP_YEAR = config.checkbox_to_value(naming_strip_year)
        app.NFO_RENAME = config.checkbox_to_value(nfo_rename)

        app.METADATA_KODI = kodi_data.split('|')
        app.METADATA_KODI_12PLUS = kodi_12plus_data.split('|')
        app.METADATA_MEDIABROWSER = mediabrowser_data.split('|')
        app.METADATA_PS3 = sony_ps3_data.split('|')
        app.METADATA_WDTV = wdtv_data.split('|')
        app.METADATA_TIVO = tivo_data.split('|')
        app.METADATA_MEDE8ER = mede8er_data.split('|')

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

        if self.isNamingValid(naming_pattern,
                              naming_multi_ep,
                              anime_type=naming_anime) != 'invalid':
            app.NAMING_PATTERN = naming_pattern
            app.NAMING_MULTI_EP = int(naming_multi_ep)
            app.NAMING_ANIME = int(naming_anime)
            app.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':
            app.NAMING_ANIME_PATTERN = naming_anime_pattern
            app.NAMING_ANIME_MULTI_EP = int(naming_anime_multi_ep)
            app.NAMING_ANIME = int(naming_anime)
            app.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':
            app.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':
            app.NAMING_SPORTS_PATTERN = naming_sports_pattern
        else:
            results.append(
                'You tried saving an invalid sports naming config, not saving your sports settings'
            )

        app.instance.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',
                                     os.path.join(app.CONFIG_FILE))

        return self.redirect('/config/postProcessing/')
Пример #4
0
    def savePostProcessing(self, process_automatically=None, unpack=None, allowed_extensions=None,
                           tv_download_dir=None, naming_pattern=None, naming_multi_ep=None,
                           naming_anime=None, naming_abd_pattern=None, naming_sports_pattern=None,
                           naming_anime_pattern=None, naming_anime_multi_ep=None,
                           autopostprocessor_frequency=None):
        """[deprecated] Save Post Processing configuration."""
        # @TODO: The following validations need to be incorporated into API v2 (PATCH /api/v2/config/main)

        results = []

        if not config.change_TV_DOWNLOAD_DIR(tv_download_dir):
            results += ['Unable to create directory {dir}, '
                        'dir not changed.'.format(dir=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':
                app.UNPACK = config.checkbox_to_value(unpack)
            else:
                app.UNPACK = 0
                results.append('Unpacking Not Supported, disabling unpack setting')
        else:
            app.UNPACK = config.checkbox_to_value(unpack)

        # @TODO: postprocessor for `POSTPONE_IF_NO_SUBS` and `ALLOWED_EXTENSIONS` ?
        # If 'postpone if no subs' is enabled, we must have SRT in allowed extensions list
        if app.POSTPONE_IF_NO_SUBS:
            allowed_extensions += ',srt'
            # # Auto PP must be disabled because FINDSUBTITLE thread that calls manual PP (like nzbtomedia)
            # app.PROCESS_AUTOMATICALLY = 0

        if self.isNamingValid(naming_pattern, naming_multi_ep, anime_type=naming_anime) != 'invalid':
            app.NAMING_PATTERN = naming_pattern
            app.NAMING_MULTI_EP = int(naming_multi_ep)
            app.NAMING_ANIME = int(naming_anime)
            app.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':
            app.NAMING_ANIME_PATTERN = naming_anime_pattern
            app.NAMING_ANIME_MULTI_EP = int(naming_anime_multi_ep)
            app.NAMING_ANIME = int(naming_anime)
            app.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':
            app.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':
            app.NAMING_SPORTS_PATTERN = naming_sports_pattern
        else:
            results.append(
                'You tried saving an invalid sports naming config, not saving your sports settings')

        app.instance.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', os.path.join(app.CONFIG_FILE))

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