"""
$description Chinese live-streaming platform for live video game broadcasts and individual live streams.
$url huya.com
$type live
"""

import base64
import logging
import re
from html import unescape as html_unescape
from typing import Dict

from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream.http import HTTPStream

log = logging.getLogger(__name__)


@pluginmatcher(re.compile(
    r"https?://(?:www\.)?huya\.com/(?P<channel>[^/]+)"
))
class Huya(Plugin):
    QUALITY_WEIGHTS: Dict[str, int] = {}

    @classmethod
    def stream_weight(cls, key):
        weight = cls.QUALITY_WEIGHTS.get(key)
        if weight:
            return weight, "huya"

        return super().stream_weight(key)

    def _get_streams(self):
        data = self.session.http.get(self.url, schema=validate.Schema(
            validate.parse_html(),
            validate.xml_xpath_string(".//script[contains(text(),'var hyPlayerConfig = {')][1]/text()"),
            validate.none_or_all(
                re.compile(r"""(?P<q>"?)stream(?P=q)\s*:\s*(?:"(?P<base64>.+?)"|(?P<json>\{.+?})\s*}\s*;)"""),
            ),
            validate.none_or_all(
                validate.any(
                    validate.all(
                        validate.get("base64"),
                        str,
                        validate.transform(base64.b64decode),
                    ),
                    validate.all(
                        validate.get("json"),
                        str,
                    ),
                ),
                validate.parse_json(),
                {
                    "data": [{
                        "gameLiveInfo": {
                            "liveId": int,
                            "nick": str,
                            "roomName": str,
                        },
                        "gameStreamInfoList": [validate.all(
                            {
                                "sCdnType": str,
                                "iPCPriorityRate": int,
                                "sStreamName": str,
                                "sFlvUrl": str,
                                "sFlvUrlSuffix": str,
                                "sFlvAntiCode": validate.all(str, validate.transform(lambda v: html_unescape(v))),
                            },
                            validate.union_get(
                                "sCdnType",
                                "iPCPriorityRate",
                                "sStreamName",
                                "sFlvUrl",
                                "sFlvUrlSuffix",
                                "sFlvAntiCode",
                            )),
                        ],
                    }],
                },
                validate.get(("data", 0)),
                validate.union_get(
                    ("gameLiveInfo", "liveId"),
                    ("gameLiveInfo", "nick"),
                    ("gameLiveInfo", "roomName"),
                    "gameStreamInfoList",
                ),
            ),
        ))
        if not data:
            return

        self.id, self.author, self.title, streamdata = data

        for cdntype, priority, streamname, flvurl, suffix, anticode in streamdata:
            name = f"source_{cdntype.lower()}"
            self.QUALITY_WEIGHTS[name] = priority
            yield name, HTTPStream(self.session, f"{flvurl}/{streamname}.{suffix}?{anticode}")

        log.debug(f"QUALITY_WEIGHTS: {self.QUALITY_WEIGHTS!r}")


__plugin__ = Huya

src/streamlink/plugins/huya.py
"""
$description Chinese live-streaming platform for live video game broadcasts and individual live streams.
$url huya.com
$type live
"""

import base64
import logging
import re
from html import unescape as html_unescape
from typing import Dict

from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream.http import HTTPStream

log = logging.getLogger(__name__)


@pluginmatcher(re.compile(
    r"https?://(?:www\.)?huya\.com/(?P<channel>[^/]+)"
))
class Huya(Plugin):
    QUALITY_WEIGHTS: Dict[str, int] = {}

    @classmethod
    def stream_weight(cls, key):
        weight = cls.QUALITY_WEIGHTS.get(key)
        if weight:
            return weight, "huya"

        return super().stream_weight(key)

    def _get_streams(self):
        data = self.session.http.get(self.url, schema=validate.Schema(
            validate.parse_html(),
            validate.xml_xpath_string(".//script[contains(text(),'var hyPlayerConfig = {')][1]/text()"),
            validate.none_or_all(
                re.compile(r"""(?P<q>"?)stream(?P=q)\s*:\s*(?:"(?P<base64>.+?)"|(?P<json>\{.+?})\s*}\s*;)"""),
            ),
            validate.none_or_all(
                validate.any(
                    validate.all(
                        validate.get("base64"),
                        str,
                        validate.transform(base64.b64decode),
                    ),
                    validate.all(
                        validate.get("json"),
                        str,
                    ),
                ),
                validate.parse_json(),
                {
                    "data": [{
                        "gameLiveInfo": {
                            "liveId": str,
                            "nick": str,
                            "roomName": str,
                        },
                        "gameStreamInfoList": [validate.all(
                            {
                                "sCdnType": str,
                                "iPCPriorityRate": int,
                                "sStreamName": str,
                                "sFlvUrl": str,
                                "sFlvUrlSuffix": str,
                                "sFlvAntiCode": validate.all(str, validate.transform(lambda v: html_unescape(v))),
                            },
                            validate.union_get(
                                "sCdnType",
                                "iPCPriorityRate",
                                "sStreamName",
                                "sFlvUrl",
                                "sFlvUrlSuffix",
                                "sFlvAntiCode",
                            )),
                        ],
                    }],
                },
                validate.get(("data", 0)),
                validate.union_get(
                    ("gameLiveInfo", "liveId"),
                    ("gameLiveInfo", "nick"),
                    ("gameLiveInfo", "roomName"),
                    "gameStreamInfoList",
                ),
            ),
        ))
        if not data:
            return

        self.id, self.author, self.title, streamdata = data

        for cdntype, priority, streamname, flvurl, suffix, anticode in streamdata:
            name = f"source_{cdntype.lower()}"
            self.QUALITY_WEIGHTS[name] = priority
            yield name, HTTPStream(self.session, f"{flvurl}/{streamname}.{suffix}?{anticode}")

        log.debug(f"QUALITY_WEIGHTS: {self.QUALITY_WEIGHTS!r}")


__plugin__ = Huya

src/streamlink/plugins/huya.py
diff --git a/src/streamlink/plugins/huya.py b/src/streamlink/plugins/huya.py
index a813d2ea0f3..dcf3d68df9e 100644
--- a/src/streamlink/plugins/huya.py
+++ b/src/streamlink/plugins/huya.py
@@ -54,7 +54,7 @@ def _get_streams(self):
                 {
                     "data": [{
                         "gameLiveInfo": {
-                            "liveId": int,
+                            "liveId": str,
                             "nick": str,
                             "roomName": str,
                         },

plugins.huya: As of today, Huya plugin has been broken
### 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 stable release

### Description

When I try to open any public Huya stream I get an error message. Assuming Huya has changed how live IDs are handled and switched to strings.

### Debug log

```text
hina@Hinas-MacBook-Pro ~ % streamlink https://www.huya.com/660108 best --loglevel debug
[cli][debug] OS:         macOS 12.5
[cli][debug] Python:     3.10.6
[cli][debug] Streamlink: 4.3.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.3.3
[cli][debug] Arguments:
[cli][debug]  url=https://www.huya.com/660108
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][info] Found matching plugin huya for URL https://www.huya.com/660108
error: Unable to validate response text: ValidationError(NoneOrAllSchema):
  ValidationError(dict):
    Unable to validate value of key 'data'
    Context(AnySchema):
      ValidationError(dict):
        Unable to validate value of key 'gameLiveInfo'
        Context(dict):
          Unable to validate value of key 'liveId'
          Context(type):
            Type of '7134607205476108031' should be int, but is str
hina@Hinas-MacBook-Pro ~ %
```

