Repository: streamlink/streamlink

Issue:
plugins.hiplayer: plugin broken ('NoneType' object is not subscriptable)
### Checklist

- [X] This is a plugin issue 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 plugin issues](https://github.com/streamlink/streamlink/issues?q=is%3Aissue+label%3A%22plugin+issue%22)
- [X] [I have checked the commit log of the master branch](https://github.com/streamlink/streamlink/commits/master)

### Streamlink version

Latest build from the master branch

### Description

The hiplayer plugin has stopped working

**Sample links**

streamlink https://rotana.net/live-clip
streamlink https://www.media.gov.kw/LiveTV.aspx?PanChannel=KTV1


### Debug log

```text
pi@raspberrypi:~ $ streamlink https://rotana.net/live-clip --loglevel debug
[cli][debug] OS:         Linux-5.10.103-v7l+-armv7l-with-glibc2.31
[cli][debug] Python:     3.9.2
[cli][debug] Streamlink: 5.0.1+6.g4b6077d1
[cli][debug] Dependencies:
[cli][debug]  isodate: 0.6.0
[cli][debug]  lxml: 4.6.4
[cli][debug]  pycountry: 20.7.3
[cli][debug]  pycryptodome: 3.11.0
[cli][debug]  PySocks: 1.7.1
[cli][debug]  requests: 2.26.0
[cli][debug]  websocket-client: 1.2.1
[cli][debug]  importlib-metadata: 1.6.0
[cli][debug] Arguments:
[cli][debug]  url=https://rotana.net/live-clip
[cli][debug]  --loglevel=debug
[cli][info] Found matching plugin hiplayer for URL https://rotana.net/live-clip
[plugins.hiplayer][debug] JS URL=https://hiplayer.hibridcdn.net/l/rotana-clip
Traceback (most recent call last):
  File "/home/pi/.local/bin/streamlink", line 8, in <module>
    sys.exit(main())
  File "/home/pi/.local/lib/python3.9/site-packages/streamlink_cli/main.py", line 975, in main
    handle_url()
  File "/home/pi/.local/lib/python3.9/site-packages/streamlink_cli/main.py", line 606, in handle_url
    streams = fetch_streams(plugin)
  File "/home/pi/.local/lib/python3.9/site-packages/streamlink_cli/main.py", line 500, in fetch_streams
    return plugin.streams(stream_types=args.stream_types,
  File "/home/pi/.local/lib/python3.9/site-packages/streamlink/plugin/plugin.py", line 376, in streams
    ostreams = self._get_streams()
  File "/home/pi/.local/lib/python3.9/site-packages/streamlink/plugins/hiplayer.py", line 77, in _get_streams
    hls_url = data["streamUrl"]
TypeError: 'NoneType' object is not subscriptable
pi@raspberrypi:~ $ 


```
```



Discussion:
The site has made changes and it looks like the regex for getting the base64 encoded JSON data from the minified/obfuscated JS file is broken due to a different variable name from the JS minifier's mangling algorithm.
https://github.com/streamlink/streamlink/blob/5.0.1/src/streamlink/plugins/hiplayer.py#L58

The plugin doesn't check for a `None` response when accessing a property, hence the `TypeError`, which should also get fixed.

I'll open a PR with a fix in an hour or two.

Resolving patch:
diff --git a/src/streamlink/plugins/hiplayer.py b/src/streamlink/plugins/hiplayer.py
--- a/src/streamlink/plugins/hiplayer.py
+++ b/src/streamlink/plugins/hiplayer.py
@@ -46,8 +46,8 @@ def _get_streams(self):
                 ),
             ),
         )
-
         if not js_url:
+            log.error("Could not find JS URL")
             return
 
         log.debug(f"JS URL={js_url}")
@@ -55,9 +55,9 @@ def _get_streams(self):
         data = self.session.http.get(
             js_url,
             schema=validate.Schema(
-                re.compile(r"i\s*=\s*\[(.*)]\.join"),
+                re.compile(r"var \w+\s*=\s*\[(?P<data>.+)]\.join\([\"']{2}\)"),
                 validate.none_or_all(
-                    validate.get(1),
+                    validate.get("data"),
                     validate.transform(lambda s: re.sub(r"['\", ]", "", s)),
                     validate.transform(lambda s: base64.b64decode(s)),
                     validate.parse_json(),
@@ -73,13 +73,16 @@ def _get_streams(self):
                 ),
             ),
         )
+        if not data:
+            log.error("Could not find base64 encoded JSON data")
+            return
 
         hls_url = data["streamUrl"]
 
         if data["daiEnabled"]:
             log.debug("daiEnabled=true")
             hls_url = self.session.http.post(
-                self.DAI_URL.format(data['daiAssetKey']),
+                self.DAI_URL.format(data["daiAssetKey"]),
                 data={"api-key": data["daiApiKey"]},
                 schema=validate.Schema(
                     validate.parse_json(),


Test patch: