Video editing with Python
Fix TextClip.list("color") returning an incorrect list of byte objects, not strings (#1119)
Tom Burrows4106b4c4acb2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 96b7502c..d7cf7f75 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed <!-- for any bug fixes -->- When using `VideoClip.write_videofile()` with `write_logfile=True`, errors would not be properly reported [#890]+- `TextClip.list("color")` now returns a list of bytes, not strings [#1119]+- `TextClip.search("colorname", "color")` does not crash with a TypeError [#1119]## [v1.0.2](https://github.com/zulko/moviepy/tree/v1.0.2) (2020-03-26)diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex 6021d791..7dc065a9 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -1269,8 +1269,8 @@ class TextClip(ImageClip):@staticmethoddef list(arg):- """Returns the list of all valid entries for the argument of- ``TextClip`` given (can be ``font``, ``color``, etc...) """+ """Returns a list of all valid entries for the ``font`` or ``color`` argument of+ ``TextClip``"""popen_params = {"stdout": sp.PIPE, "stderr": sp.DEVNULL, "stdin": sp.DEVNULL}@@ -1280,15 +1280,15 @@ class TextClip(ImageClip):process = sp.Popen([get_setting("IMAGEMAGICK_BINARY"), "-list", arg], **popen_params)- result = process.communicate()[0]+ result = process.communicate()[0].decode()lines = result.splitlines()if arg == "font":- return [l.decode("UTF-8")[8:] for l in lines if l.startswith(b" Font:")]+ return [l[8:] for l in lines if l.startswith(" Font:")]elif arg == "color":- return [l.split(b" ")[0] for l in lines[2:]]+ return [l.split(" ")[0] for l in lines[5:]]else:- raise Exception("Moviepy:Error! Argument must equal " "'font' or 'color'")+ raise Exception("Moviepy Error: Argument must equal 'font' or 'color'")@staticmethoddef search(string, arg):@@ -1296,7 +1296,7 @@ class TextClip(ImageClip):argument ``arg`` of ``TextClip``, for instance>>> # Find all the available fonts which contain "Courier"- >>> print ( TextClip.search('Courier', 'font') )+ >>> print(TextClip.search('Courier', 'font'))"""string = string.lower()diff --git a/tests/test_TextClip.py b/tests/test_TextClip.pyindex 17884c18..58407e7e 100644--- a/tests/test_TextClip.py+++ b/tests/test_TextClip.py@@ -9,8 +9,22 @@ from moviepy.video.VideoClip import TextClipfrom .test_helper import FONT-def test_fontlist():- TextClip.list("font")+def test_list():+ fonts = TextClip.list("font")+ assert isinstance(fonts, list)+ assert isinstance(fonts[0], str)++ colors = TextClip.list("color")+ assert isinstance(colors, list)+ assert isinstance(colors[0], str)+ assert "blue" in colors+++def test_search():+ blues = TextClip.search("blue", "color")+ assert isinstance(blues, list)+ assert isinstance(blues[0], str)+ assert "blue" in bluesdef test_duration():