def __on_completion(self, values: dict, data: StepData):
        # Set state to ready
        self.__current_step = self.__steps_max

        # Set endTime and log
        self.__end_time = time.time()
        completion_time = round(self.__end_time - self.__start_time, 2)

        logger.info(
            f"{self.__log_name}  {self.id} finished in {completion_time}s")

        # Update DB logs
        self.__update_db(update_log_finish, self.__log_id,
                         self.__log_states["finished"], completion_time)

        if self.__attach_mode:
            return

        # Check and delete video
        delete_video(self.steps_config, self.__config)

        cp_request = data.get_config("on_completion")

        # IF ON Completion is in config send request
        if cp_request is not None:
            try:
                logger.info("Send completion notice...")

                # Save video name and thumbnail name to config
                video_name = os.path.basename(values["sequence"])

                data.insert_data("_conf|video_path", values["sequence"], {})
                data.insert_data("_conf|video_name", video_name, {})
                data.insert_data("_conf|video_id",
                                 os.path.splitext(video_name)[0], {})

                if isinstance(values["thumbnail"], str):
                    thumbnail_name = os.path.basename(values["thumbnail"])

                    data.insert_data("_conf|thumbnail_path",
                                     values["thumbnail"], {})
                    data.insert_data("_conf|thumbnail_name", thumbnail_name,
                                     {})
                    data.insert_data("_conf|thumbnail_id",
                                     os.path.splitext(thumbnail_name)[0], {})

                # make request
                api_request(cp_request, data, "", "_comp", True)

                logger.info("Completion report sent out!")
            except Exception:
                logger.exception("Completion report could not be sent: ")
Ejemplo n.º 2
0
def custom(values: dict, data: StepData, config: dict):
    """Generiert eine Audiodatei mithilfe einer bestimmten TTS-API und Konfigurationen dafür.

    :param values: Werte aus der JSON-Datei
    :param data: Daten aus der API
    :param config: Daten aus der Konfigurationsdatei
    :return:
    """
    logger.info("Generate audio with custom audio config")

    _prepare_custom(config.get("prepare", None), data, config)

    for key in values:
        text = part.audio_parts(values[key]["parts"], data)

        if text[1]:

            data.data["_audio"]["text"] = text[0]
            generate = config["generate"]
            generate["include_headers"] = True
            api_request(generate, data, "audio", "_audio|gen", True)

            values[key] = _save_audio(data.get_data("_audio|gen", values),
                                      data, config)

        else:
            audio_list = []
            for item in values[key]["parts"]:
                if item["type"] == "text":
                    data.data["_audio"]["text"] = data.format(
                        item["pattern"], values)
                    generate = config["generate"]
                    generate["include_headers"] = True
                    api_request(generate, data, "audio", "_audio|gen", True)
                    audio_list.append(
                        _save_audio(data.get_data("_audio|gen", values), data,
                                    config))
                if item["type"] == "file":
                    audio_list.append(resources.get_audio_path(item["path"]))

            values[key] = _audios_to_audio(audio_list, data)
Ejemplo n.º 3
0
def custom(values: dict, data: StepData, config: dict):
    """Generiert eine Audiodatei mithilfe einer bestimmten TTS-API und Konfigurationen dafür.

    :param values: Werte aus der JSON-Datei
    :param data: Daten aus der API
    :param config: Daten aus der Konfigurationsdatei
    :return:
    """
    logger.info("Generate audio with custom audio config")

    _prepare_custom(config.get("prepare", None), data, config)

    for key in values:
        text = part.audio_parts(values[key]["parts"], data)

        data.data["_audio"]["text"] = text
        generate = config["generate"]
        generate["include_headers"] = True
        api_request(generate, data, "audio", "_audio|gen", True)

        values[key] = _save_audio(data.get_data("_audio|gen", values), data, config)
Ejemplo n.º 4
0
def _prepare_custom(values: dict, data: StepData, config: dict):
    if values is not None:
        api_request(values, data, "audio", "_audio|pre", True)