Example #1
0
    def config_spider(self):
        config = Config()
        config_dict = config.config  # type: dict
        is_config = False
        try:
            if self.app.pargs.path_download is not None:
                paths = self.app.pargs.path_download.split(',')  # type: list
                if default_path_key in paths:
                    index = paths.index(default_path_key)
                    paths.remove(default_path_key)
                    paths.insert(index, default_download_dir)

                final_paths = []
                for p in paths:
                    try:
                        # some error need pass
                        if os.path.isdir(p) is False:
                            os.mkdir(p)
                        final_paths.append(p)
                    except:
                        log.print_warn("path may be wrong and be deleted: {}".format(p))
                        pass

                if not final_paths:
                    final_paths.append(default_download_dir)

                log.print_info('path will be set as: ' + ','.join(final_paths))

                config_dict['download_path'] = final_paths
                is_config = True

            if self.app.pargs.mv_resolution is not None:
                r = int(self.app.pargs.mv_resolution)
                if r not in mv_resolutions:
                    log.print_warn("-mvr resolution config skip, value must be 240,480,720,1080")
                config_dict['mv_def_resolution'] = r
                is_config = True

            if self.app.pargs.media_tag is not None:
                config_dict['media_tag'] = True if self.app.pargs.media_tag.lower() == 'true'\
                                                   or self.app.pargs.media_tag == '1' else False
                is_config = True

            if self.app.pargs.media_tag_163 is not None:
                config_dict['media_tag_163'] = True if self.app.pargs.media_tag_163.lower() == 'true' \
                                                       or self.app.pargs.media_tag_163 == '1' else False
                is_config = True

        except:
            log.print_err("input error, pls check")
            raise
        if is_config:
            config.save_config_file()
        log.print_info("config success")
        self.config_show()
Example #2
0
    def config_mongo(self):
        config = Config()
        config_dict = config.config  # type: dict
        mongo_key = 'mongo'
        is_config = False
        try:
            if self.app.pargs.mhost is not None:
                config_dict[mongo_key]['host'] = self.app.pargs.mhost
                config_dict['no_mongo'] = False
                is_config = True

            if self.app.pargs.mport is not None:
                config_dict[mongo_key]['port'] = int(self.app.pargs.mport)
                is_config = True

            if self.app.pargs.muser is not None:
                config_dict[mongo_key]['username'] = self.app.pargs.muser
                is_config = True

            if self.app.pargs.mpassword is not None:
                config_dict[mongo_key]['password'] = self.app.pargs.mpassword
                is_config = True

            if self.app.pargs.mdbname is not None:
                config_dict[mongo_key]['name'] = self.app.pargs.mdbname
                is_config = True

            if self.app.pargs.nomongo is not None:
                config_dict['no_mongo'] = True if self.app.pargs.nomongo.lower() == 'true'\
                                                   or self.app.pargs.nomongo == '1' else False
                is_config = True
        except:
            log.print_err("input error, pls check")
            raise
        if is_config:
            config.save_config_file()
        log.print_info("config success")
        self.config_show()