Repository: ManimCommunity/manim
File: manim/utils/ipython_magic.py (Python)

Code before:
                    # Close OpenGL window here instead of waiting for the main thread to
                    # finish causing the window to stay open and freeze
                    if renderer is not None and renderer.window is not None:
                        renderer.window.close()

                if config["output_file"] is None:
                    logger.info("No output file produced")
                    return

                local_path = Path(config["output_file"]).relative_to(Path.cwd())
                tmpfile = (
                    Path(config["media_dir"])
                    / "jupyter"
                    / f"{_generate_file_name()}{local_path.suffix}"
                )

                if local_path in self.rendered_files:
                    self.rendered_files[local_path].unlink()
                self.rendered_files[local_path] = tmpfile
                os.makedirs(tmpfile.parent, exist_ok=True)
                shutil.copy(local_path, tmpfile)

                file_type = mimetypes.guess_type(config["output_file"])[0]
                embed = config["media_embed"]
                if file_type.startswith("image"):
                    result = Image(filename=config["output_file"], embed=embed)
                else:
                    if embed is None and "google.colab" in str(get_ipython()):
                        # videos need to be embedded when running in google colab.  Do
                        # this unless suppressed explicitly by config.embed
                        embed = True

                    result = Video(
                        tmpfile,
                        html_attributes=f'controls autoplay loop style="max-width: {config["media_width"]};"',
                        embed=embed,
                    )

                display(result)

        def add_additional_args(self, args: List[str]) -> List[str]:
            additional_args = ["--jupyter"]
            # Use webm to support transparency
            if "-t" in args and "--format" not in args:
                additional_args += ["--format", "webm"]
            return additional_args + args[:-1] + [""] + [args[-1]]


def _generate_file_name() -> str:
    return config["scene_names"][0] + "@" + datetime.now().strftime("%Y-%m-%d@%H-%M-%S")


Review comment (suggestion):
Wouldn't it be better to add the fix for colab right here? I.e.,

```suggestion
                embed = config["media_embed"]
                if embed is None and "google.colab" in str(get_ipython()):
                    embed = True
                elif embed is None:
                    embed = False
```

I've added an additional branch to make sure that `None` is never passed to `embed` in `Image` and `Video`.

Code after:
                    shader_program_cache.clear()

                    # Close OpenGL window here instead of waiting for the main thread to
                    # finish causing the window to stay open and freeze
                    if renderer is not None and renderer.window is not None:
                        renderer.window.close()

                if config["output_file"] is None:
                    logger.info("No output file produced")
                    return

                local_path = Path(config["output_file"]).relative_to(Path.cwd())
                tmpfile = (
                    Path(config["media_dir"])
                    / "jupyter"
                    / f"{_generate_file_name()}{local_path.suffix}"
                )

                if local_path in self.rendered_files:
                    self.rendered_files[local_path].unlink()
                self.rendered_files[local_path] = tmpfile
                os.makedirs(tmpfile.parent, exist_ok=True)
                shutil.copy(local_path, tmpfile)

                file_type = mimetypes.guess_type(config["output_file"])[0]
                embed = config["media_embed"]
                if embed is None:
                    # videos need to be embedded when running in google colab.
                    # do this automatically in case config.media_embed has not been
                    # set explicitly.
                    embed = "google.colab" in str(get_ipython())

                if file_type.startswith("image"):
                    result = Image(filename=config["output_file"], embed=embed)
                else:
                    result = Video(
                        tmpfile,
                        html_attributes=f'controls autoplay loop style="max-width: {config["media_width"]};"',
                        embed=embed,
                    )

                display(result)

        def add_additional_args(self, args: list[str]) -> list[str]:
            additional_args = ["--jupyter"]
            # Use webm to support transparency
            if "-t" in args and "--format" not in args:
                additional_args += ["--format", "webm"]
            return additional_args + args[:-1] + [""] + [args[-1]]