Repository: Zulko/moviepy (python)

Issue:
Providing filename instead of txt to TextClip results in filename being written instead of the actual content of the file
#### Expected Behavior
Providing a filename to TextClip instead of txt parameter should produce an image with the text in the provided file being set on the image, for example the following two snippets should produce the same output:
```python
text_clip = TextClip(
    filename=temp.txt,
    font="Roboto-Bold",
    size=(300, 135),
    color="#4390C8",
    bg_color="#323232",
    method="caption",
    remove_temp=False,
    print_cmd=True,
)
```

```python
text_clip = TextClip(
    txt="Hello",
    font="Roboto-Bold",
    size=(300, 135),
    color="#4390C8",
    bg_color="#323232",
    method="caption",
    remove_temp=False,
    print_cmd=True,
)
```
Where file temp.txt contains *Hello* in it.
Both snippets should produce an image like this one:
![tmpsrd22otw](https://user-images.githubusercontent.com/19710525/171849838-989b294d-dc64-42b8-a1c3-1d32c95e6d3f.png)

#### Actual Behavior
The first one produces the following image:
![tmpam1o1mzg](https://user-images.githubusercontent.com/19710525/171849595-16942cc9-e333-4a87-8745-3e3f63c16e0e.png)
Where the second one produces the following image:
![tmpsrd22otw](https://user-images.githubusercontent.com/19710525/171849838-989b294d-dc64-42b8-a1c3-1d32c95e6d3f.png)


#### Steps to Reproduce the Problem
<!-- Please include code that demonstrates this problem so that we can reproduce it. For advice on how to do this, see https://stackoverflow.com/help/mcve -->
Run the above snippets after importing from editor
```python
from moviepy.editor import *
```
and check the temp file generated, it will be printed

#### Specifications

  - Python Version: 3.8.10 (default, Mar 15 2022, 12:22:08) \n[GCC 9.4.0]
  - Moviepy Version: 1.0.3
  - Platform Name: Ubuntu
  - Platform Version: 20.04.4 LTS 64bit

#### Solution
LIne: moviepy/video/VideoClip.py:1101
is responsible of this bug, just deleting the `%` in parameter value will fix the problem, tested on multiple files, and also you can sse this is the correct way by looking at line: 1098 and also to check imagemagick [docs](https://imagemagick.org/Usage/text/#caption_paragraphs) 


Pull request:
Fix textclip filename parameter in wrong format
<!--
Please tick when you have done these. They don't need to all be completed before the PR is submitted.
Delete them if they are not appropriate for this pull request.
-->
- [x] I have provided code that clearly demonstrates the bug and that only works correctly when applying this fix
- [x] I have added suitable tests demonstrating a fixed bug or new/changed feature to the test suite in `tests/`
- [x] I have properly documented new or changed features in the documentation or in the docstrings
- [x] I have properly explained unusual or unexpected code in the comments around it

closes #1787

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 995d3e6..423c2ec 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Fixed scroll FX not being scrolling [\#1591](https://github.com/Zulko/moviepy/pull/1591)
 - Fixed parsing FFMPEG streams with square brackets [\#1781](https://github.com/Zulko/moviepy/pull/1781)
 - Fixed audio processing for streams with missing `audio_bitrate` [\#1783](https://github.com/Zulko/moviepy/pull/1783)
+- Fixed parsing language from stream output with square brackets [\#1837](https://github.com/Zulko/moviepy/pull/1837)
 
 
 ## [v2.0.0.dev2](https://github.com/zulko/moviepy/tree/v2.0.0.dev2) (2020-10-05)
diff --git a/examples/moving_letters.py b/examples/moving_letters.py
index ece4220..19c85b2 100644
--- a/examples/moving_letters.py
+++ b/examples/moving_letters.py
@@ -61,7 +61,7 @@ letters = find_objects(cvc)  # a list of ImageClips
 
 def moveLetters(letters, funcpos):  # noqa D103
     return [
-        letter.set_pos(funcpos(letter.screenpos, i, len(letters)))
+        letter.with_position(funcpos(letter.screenpos, i, len(letters)))
         for i, letter in enumerate(letters)
     ]
 
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index ac56893..07b0487 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -1256,7 +1256,7 @@ class TextClip(ImageClip):
             text = "@" + temptxt
         else:
             # use a file instead of a text.
-            text = "@%" + filename
+            text = "@" + filename
 
         if size is not None:
             size = (
diff --git a/moviepy/video/io/ffmpeg_reader.py b/moviepy/video/io/ffmpeg_reader.py
index c94e058..616deff 100644
--- a/moviepy/video/io/ffmpeg_reader.py
+++ b/moviepy/video/io/ffmpeg_reader.py
@@ -422,7 +422,8 @@ class FFmpegInfosParser:
 
                 # get input number, stream number, language and type
                 main_info_match = re.search(
-                    r"^Stream\s#(\d+):(\d+)[\[(]?(\w+)?[\])]?:\s(\w+):", line.lstrip()
+                    r"^Stream\s#(\d+):(\d+)(?:\[\w+\])?\(?(\w+)?\)?:\s(\w+):",
+                    line.lstrip(),
                 )
                 (
                     input_number,
@@ -434,9 +435,8 @@ class FFmpegInfosParser:
                 stream_number = int(stream_number)
                 stream_type_lower = stream_type.lower()
 
-                if language is not None:
-                    if language == "und" or language.startswith("0x"):
-                        language = None
+                if language == "und":
+                    language = None
 
                 # start builiding the current stream
                 self._current_stream = {


Test patch:
diff --git a/scripts/get-latest-imagemagick-win.py b/scripts/get-latest-imagemagick-win.py
index c51620d..9683e4d 100644
--- a/scripts/get-latest-imagemagick-win.py
+++ b/scripts/get-latest-imagemagick-win.py
@@ -4,7 +4,7 @@ import sys
 from urllib.request import urlopen
 
 
-BINARIES_URL = "https://download.imagemagick.org/ImageMagick/download/binaries/"
+BINARIES_URL = "https://imagemagick.org/archive/binaries/"
 
 content = urlopen(BINARIES_URL).read().decode("utf-8")
 
diff --git a/tests/test_TextClip.py b/tests/test_TextClip.py
index c670375..e30aca0 100644
--- a/tests/test_TextClip.py
+++ b/tests/test_TextClip.py
@@ -1,5 +1,9 @@
 """TextClip tests."""
 
+import os
+
+import numpy as np
+
 import pytest
 
 from moviepy.video.fx.blink import blink
@@ -35,21 +39,42 @@ def test_duration(util):
     assert clip2.duration == 5
 
 
-# Moved from tests.py. Maybe we can remove these?
-def test_if_textclip_crashes_in_caption_mode(util):
-    TextClip(
-        text="foo",
-        color="white",
-        size=(640, 480),
-        method="caption",
-        align="center",
-        font_size=25,
-        font=util.FONT,
-    ).close()
-
-
-def test_if_textclip_crashes_in_label_mode(util):
-    TextClip(text="foo", method="label", font=util.FONT).close()
+def test_text_filename_arguments_consistence(util):
+    """Passing ``text`` or ``filename`` we obtain the same result."""
+    clip_from_text = (
+        TextClip(
+            text="Hello",
+            size=(20, 20),
+            color="#000",
+            bg_color="#FFF",
+            method="caption",
+            font=util.FONT,
+        )
+        .with_fps(1)
+        .with_duration(1)
+    )
+
+    with open(os.path.join(util.TMP_DIR, "text-for-clip.txt"), "w") as f:
+        f.write("Hello")
+
+    clip_from_file = (
+        TextClip(
+            text="Hello",
+            size=(20, 20),
+            color="#000",
+            bg_color="#FFF",
+            method="caption",
+            font=util.FONT,
+        )
+        .with_fps(1)
+        .with_duration(1)
+    )
+
+    frames_from_text = list(clip_from_text.iter_frames())
+    frames_from_file = list(clip_from_file.iter_frames())
+    assert len(frames_from_text) == 1
+    assert len(frames_from_file) == 1
+    assert np.equal(frames_from_text[0], frames_from_file[0]).all()
 
 
 if __name__ == "__main__":
diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.py
index fad0507..e566bc5 100644
--- a/tests/test_ffmpeg_reader.py
+++ b/tests/test_ffmpeg_reader.py
@@ -527,6 +527,22 @@ At least one output file must be specified"""
     assert d["inputs"][0]["streams"][1]["language"] is None
 
 
+def test_stream_square_brackets_and_language():
+    infos = """
+Input #0, mpeg, from 'clip.mp4':
+  Duration: 00:02:15.00, start: 52874.498178, bitrate: 266 kb/s
+    Stream #0:0[0x1e0](eng): Video: ..., 25 tbr, 90k tbn, 50 tbc
+    Stream #0:1[0x1c0](und): Audio: mp2, 0 channels, s16p
+At least one output file must be specified"""
+
+    d = FFmpegInfosParser(infos, "clip.mp4").parse()
+
+    assert d
+    assert len(d["inputs"][0]["streams"]) == 2
+    assert d["inputs"][0]["streams"][0]["language"] == "eng"
+    assert d["inputs"][0]["streams"][1]["language"] is None
+
+
 def test_stream_missing_audio_bitrate():
     infos = """
 Input #0, mpeg, from 'clip.mp4':