Repository: streamlink/streamlink

Issue:
plugins.mitele: Unable to validate value of key 'stream'
### Checklist

- [X] This is a bug report and not a different kind of issue
- [X] [I have read the contribution guidelines](https://github.com/streamlink/streamlink/blob/master/CONTRIBUTING.md#contributing-to-streamlink)
- [X] [I have checked the list of open and recently closed bug reports](https://github.com/streamlink/streamlink/issues?q=is%3Aissue+label%3A%22bug%22)
- [x] [I have checked the commit log of the master branch](https://github.com/streamlink/streamlink/commits/master)

### Streamlink version

Latest stable release

### Description

Only this error with one url (bemad).

### Debug log

```text
[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.10.7
[cli][debug] Streamlink: 5.0.0
[cli][debug] Dependencies:
[cli][debug]  isodate: 0.6.1
[cli][debug]  lxml: 4.9.1
[cli][debug]  pycountry: 22.3.5
[cli][debug]  pycryptodome: 3.15.0
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.28.1
[cli][debug]  websocket-client: 1.4.1
[cli][debug] Arguments:
[cli][debug]  url=https://mitele.es/directo/bemad
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][debug]  --ffmpeg-ffmpeg=C:\Program Files\Streamlink\ffmpeg\ffmpeg.exe
[cli][info] Found matching plugin mitele for URL https://mitele.es/directo/bemad
error: Unable to validate response text: ValidationError(AnySchema):
  ValidationError(dict):
    Key 'code' not found in <{'cerbero': 'https://cerbero.pro.3d99a4cb092e6d20ff56d8...>
  ValidationError(dict):
    Unable to validate value of key 'dls'
    Context(AnySchema):
      ValidationError(dict):
        Unable to validate value of key 'stream'
        Context(url):
          <'\u2002https://directos.mitele.es/orilinear02/live/line...> is not a valid URL
```



Discussion:
> `<'\u2002https://directos.mitele.es/orilinear02/live/line...)> is not a valid URL`

Why is there a `U+2002` character at the beginning of one of the stream URLs?!?! weird...
https://www.fileformat.info/info/unicode/char/2002/index.htm

That diff should fix the validation error

```diff
diff --git a/src/streamlink/plugins/mitele.py b/src/streamlink/plugins/mitele.py
index 0a9f2f39..d59cfaa0 100644
--- a/src/streamlink/plugins/mitele.py
+++ b/src/streamlink/plugins/mitele.py
@@ -45,7 +45,11 @@ class Mitele(Plugin):
                             [{
                                 "drm": bool,
                                 "format": str,
-                                "stream": validate.url(),
+                                "stream": validate.all(
+                                    validate.transform(str.lstrip),
+                                    validate.url(),
+                                ),
                                 "lid": validate.all(int, validate.transform(str)),
                                 validate.optional("assetKey"): str,
                             }],
```

but the site is responding with error code `40313` when trying to acquire the streaming token afterwards. This might be an issue with geo-blocking. My VPN unfortunately gets blocked by the site, so if you could apply the diff and report back if it's working, that would be appreciated, so I can open a PR with the fix.
> > `<'\u2002https://directos.mitele.es/orilinear02/live/line...)> is not a valid URL`
> 
> Why is there a `U+2002` character at the beginning of one of the stream URLs?!?! weird... https://www.fileformat.info/info/unicode/char/2002/index.htm
> 
> That diff should fix the validation error
> 
> ```diff
> diff --git a/src/streamlink/plugins/mitele.py b/src/streamlink/plugins/mitele.py
> index 0a9f2f39..d59cfaa0 100644
> --- a/src/streamlink/plugins/mitele.py
> +++ b/src/streamlink/plugins/mitele.py
> @@ -45,7 +45,11 @@ class Mitele(Plugin):
>                              [{
>                                  "drm": bool,
>                                  "format": str,
> -                                "stream": validate.url(),
> +                                "stream": validate.all(
> +                                    validate.transform(str.lstrip),
> +                                    validate.url(),
> +                                ),
>                                  "lid": validate.all(int, validate.transform(str)),
>                                  validate.optional("assetKey"): str,
>                              }],
> ```
> 
> but the site is responding with error code `40313` when trying to acquire the streaming token afterwards. This might be an issue with geo-blocking. My VPN unfortunately gets blocked by the site, so if you could apply the diff and report back if it's working, that would be appreciated, so I can open a PR with the fix.

From Spain works correctly, thanks.

Resolving patch:
diff --git a/src/streamlink/plugins/mitele.py b/src/streamlink/plugins/mitele.py
--- a/src/streamlink/plugins/mitele.py
+++ b/src/streamlink/plugins/mitele.py
@@ -45,11 +45,17 @@ def _get_streams(self):
                             [{
                                 "drm": bool,
                                 "format": str,
-                                "stream": validate.url(),
-                                "lid": validate.all(int, validate.transform(str)),
+                                "stream": validate.all(
+                                    validate.transform(str.strip),
+                                    validate.url(),
+                                ),
+                                "lid": validate.all(
+                                    int,
+                                    validate.transform(str),
+                                ),
                                 validate.optional("assetKey"): str,
                             }],
-                            validate.filter(lambda obj: obj["format"] == "hls")
+                            validate.filter(lambda obj: obj["format"] == "hls"),
                         ),
                     },
                 ),
@@ -86,7 +92,7 @@ def _get_streams(self):
                     {"code": int},
                     validate.all(
                         {"tokens": {str: {"cdn": str}}},
-                        validate.get("tokens")
+                        validate.get("tokens"),
                     ),
                 ),
             ),


Test patch: