prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  July 17 Douyu.com error
  0.7.0
  streamlink https://www.douyu.com/17732 source -o "PATH & FILENAME"
  [cli][info] Found matching plugin douyutv for URL https://www.douyu.com/17732
  error: Unable to open URL: https://www.douyu.com/lapi/live/getPlay/17732 (500 Server Error: Internal Server Error for url: https://www.douyu.com/lapi/live/getPlay/17732)
  @fozzysec @steven7851
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/streamlink/plugins/douyutv.py`
  Content:
  ```
  1 import re
  2 import time
  3 import hashlib
  4 
  5 from requests.adapters import HTTPAdapter
  6 
  7 from streamlink.plugin import Plugin
  8 from streamlink.plugin.api import http, validate, useragents
  9 from streamlink.stream import HTTPStream, HLSStream, RTMPStream
  10 
  11 API_URL = "https://capi.douyucdn.cn/api/v1/{0}&auth={1}"
  12 VAPI_URL = "https://vmobile.douyu.com/video/getInfo?vid={0}"
  13 API_SECRET = "Y237pxTx2In5ayGz"
  14 SHOW_STATUS_ONLINE = 1
  15 SHOW_STATUS_OFFLINE = 2
  16 STREAM_WEIGHTS = {
  17         "low": 540,
  18         "medium": 720,
  19         "source": 1080
  20         }
  21 
  22 _url_re = re.compile(r"""
  23     http(s)?://
  24     (?:
  25         (?P<subdomain>.+)
  26         \.
  27     )?
  28     douyu.com/
  29     (?:
  30         show/(?P<vid>[^/&?]+)|
  31         (?P<channel>[^/&?]+)
  32     )
  33 """, re.VERBOSE)
  34 
  35 _room_id_re = re.compile(r'"room_id\\*"\s*:\s*(\d+),')
  36 _room_id_alt_re = re.compile(r'data-onlineid=(\d+)')
  37 
  38 _room_id_schema = validate.Schema(
  39     validate.all(
  40         validate.transform(_room_id_re.search),
  41         validate.any(
  42             None,
  43             validate.all(
  44                 validate.get(1),
  45                 validate.transform(int)
  46             )
  47         )
  48     )
  49 )
  50 
  51 _room_id_alt_schema = validate.Schema(
  52     validate.all(
  53         validate.transform(_room_id_alt_re.search),
  54         validate.any(
  55             None,
  56             validate.all(
  57                 validate.get(1),
  58                 validate.transform(int)
  59             )
  60         )
  61     )
  62 )
  63 
  64 _room_schema = validate.Schema(
  65     {
  66         "data": validate.any(None, {
  67             "show_status": validate.all(
  68                 validate.text,
  69                 validate.transform(int)
  70             ),
  71             "rtmp_url": validate.text,
  72             "rtmp_live": validate.text,
  73             "hls_url": validate.text,
  74             "rtmp_multi_bitrate": validate.all(
  75                 validate.any([], {
  76                     validate.text: validate.text
  77                 }),
  78                 validate.transform(dict)
  79             )
  80         })
  81     },
  82     validate.get("data")
  83 )
  84 
  85 _vapi_schema = validate.Schema(
  86     {
  87         "data": validate.any(None, {
  88             "video_url": validate.text
  89         })
  90     },
  91     validate.get("data")
  92 )
  93 
  94 
  95 class Douyutv(Plugin):
  96     @classmethod
  97     def can_handle_url(cls, url):
  98         return _url_re.match(url)
  99 
  100     @classmethod
  101     def stream_weight(cls, stream):
  102         if stream in STREAM_WEIGHTS:
  103             return STREAM_WEIGHTS[stream], "douyutv"
  104         return Plugin.stream_weight(stream)
  105 
  106     def _get_streams(self):
  107         match = _url_re.match(self.url)
  108         subdomain = match.group("subdomain")
  109 
  110         http.verify = False
  111         http.mount('https://', HTTPAdapter(max_retries=99))
  112 
  113         if subdomain == 'v':
  114             vid = match.group("vid")
  115             headers = {
  116                 "User-Agent": useragents.ANDROID,
  117                 "X-Requested-With": "XMLHttpRequest"
  118             }
  119             res = http.get(VAPI_URL.format(vid), headers=headers)
  120             room = http.json(res, schema=_vapi_schema)
  121             yield "source", HLSStream(self.session, room["video_url"])
  122             return
  123 
  124         channel = match.group("channel")
  125         try:
  126             channel = int(channel)
  127         except ValueError:
  128             channel = http.get(self.url, schema=_room_id_schema)
  129             if channel is None:
  130                 channel = http.get(self.url, schema=_room_id_alt_schema)
  131 
  132         http.headers.update({'User-Agent': useragents.ANDROID})
  133         cdns = ["ws", "tct", "ws2", "dl"]
  134         ts = int(time.time())
  135         suffix = "room/{0}?aid=androidhd1&cdn={1}&client_sys=android&time={2}".format(channel, cdns[0], ts)
  136         sign = hashlib.md5((suffix + API_SECRET).encode()).hexdigest()
  137 
  138         res = http.get(API_URL.format(suffix, sign))
  139         room = http.json(res, schema=_room_schema)
  140         if not room:
  141             self.logger.info("Not a valid room url.")
  142             return
  143 
  144         if room["show_status"] != SHOW_STATUS_ONLINE:
  145             self.logger.info("Stream currently unavailable.")
  146             return
  147 
  148         url = room["hls_url"]
  149         yield "source", HLSStream(self.session, url)
  150 
  151         url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room)
  152         if 'rtmp:' in url:
  153             stream = RTMPStream(self.session, {
  154                     "rtmp": url,
  155                     "live": True
  156                     })
  157             yield "source", stream
  158         else:
  159             yield "source", HTTPStream(self.session, url)
  160 
  161         multi_streams = {
  162                 "middle": "low",
  163                 "middle2": "medium"
  164                 }
  165         for name, url in room["rtmp_multi_bitrate"].items():
  166             url = "{room[rtmp_url]}/{url}".format(room=room, url=url)
  167             name = multi_streams[name]
  168             if 'rtmp:' in url:
  169                 stream = RTMPStream(self.session, {
  170                         "rtmp": url,
  171                         "live": True
  172                         })
  173                 yield name, stream
  174             else:
  175                 yield name, HTTPStream(self.session, url)
  176 
  177 
  178 __plugin__ = Douyutv
  179
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/streamlink/plugins/douyutv.py b/src/streamlink/plugins/douyutv.py
  --- a/src/streamlink/plugins/douyutv.py
  +++ b/src/streamlink/plugins/douyutv.py
  @@ -10,7 +10,7 @@
   
   API_URL = "https://capi.douyucdn.cn/api/v1/{0}&auth={1}"
   VAPI_URL = "https://vmobile.douyu.com/video/getInfo?vid={0}"
  -API_SECRET = "Y237pxTx2In5ayGz"
  +API_SECRET = "zNzMV1y4EMxOHS6I5WKm"
   SHOW_STATUS_ONLINE = 1
   SHOW_STATUS_OFFLINE = 2
   STREAM_WEIGHTS = {
  @@ -129,10 +129,10 @@
               if channel is None:
                   channel = http.get(self.url, schema=_room_id_alt_schema)
   
  -        http.headers.update({'User-Agent': useragents.ANDROID})
  +        http.headers.update({'User-Agent': useragents.WINDOWS_PHONE_8})
           cdns = ["ws", "tct", "ws2", "dl"]
           ts = int(time.time())
  -        suffix = "room/{0}?aid=androidhd1&cdn={1}&client_sys=android&time={2}".format(channel, cdns[0], ts)
  +        suffix = "room/{0}?aid=wp&cdn={1}&client_sys=wp&time={2}".format(channel, cdns[0], ts)
           sign = hashlib.md5((suffix + API_SECRET).encode()).hexdigest()
   
           res = http.get(API_URL.format(suffix, sign))
  
verification_info: {"golden_diff": "diff --git a/src/streamlink/plugins/douyutv.py b/src/streamlink/plugins/douyutv.py\n--- a/src/streamlink/plugins/douyutv.py\n+++ b/src/streamlink/plugins/douyutv.py\n@@ -10,7 +10,7 @@\n \n API_URL = \"https://capi.douyucdn.cn/api/v1/{0}&auth={1}\"\n VAPI_URL = \"https://vmobile.douyu.com/video/getInfo?vid={0}\"\n-API_SECRET = \"Y237pxTx2In5ayGz\"\n+API_SECRET = \"zNzMV1y4EMxOHS6I5WKm\"\n SHOW_STATUS_ONLINE = 1\n SHOW_STATUS_OFFLINE = 2\n STREAM_WEIGHTS = {\n@@ -129,10 +129,10 @@\n             if channel is None:\n                 channel = http.get(self.url, schema=_room_id_alt_schema)\n \n-        http.headers.update({'User-Agent': useragents.ANDROID})\n+        http.headers.update({'User-Agent': useragents.WINDOWS_PHONE_8})\n         cdns = [\"ws\", \"tct\", \"ws2\", \"dl\"]\n         ts = int(time.time())\n-        suffix = \"room/{0}?aid=androidhd1&cdn={1}&client_sys=android&time={2}\".format(channel, cdns[0], ts)\n+        suffix = \"room/{0}?aid=wp&cdn={1}&client_sys=wp&time={2}\".format(channel, cdns[0], ts)\n         sign = hashlib.md5((suffix + API_SECRET).encode()).hexdigest()\n \n         res = http.get(API_URL.format(suffix, sign))\n", "issue": "July 17 Douyu.com error\n0.7.0\r\nstreamlink https://www.douyu.com/17732 source -o \"PATH & FILENAME\"\r\n[cli][info] Found matching plugin douyutv for URL https://www.douyu.com/17732\r\nerror: Unable to open URL: https://www.douyu.com/lapi/live/getPlay/17732 (500 Server Error: Internal Server Error for url: https://www.douyu.com/lapi/live/getPlay/17732)\r\n@fozzysec @steven7851\n", "before_files": [{"content": "import re\nimport time\nimport hashlib\n\nfrom requests.adapters import HTTPAdapter\n\nfrom streamlink.plugin import Plugin\nfrom streamlink.plugin.api import http, validate, useragents\nfrom streamlink.stream import HTTPStream, HLSStream, RTMPStream\n\nAPI_URL = \"https://capi.douyucdn.cn/api/v1/{0}&auth={1}\"\nVAPI_URL = \"https://vmobile.douyu.com/video/getInfo?vid={0}\"\nAPI_SECRET = \"Y237pxTx2In5ayGz\"\nSHOW_STATUS_ONLINE = 1\nSHOW_STATUS_OFFLINE = 2\nSTREAM_WEIGHTS = {\n        \"low\": 540,\n        \"medium\": 720,\n        \"source\": 1080\n        }\n\n_url_re = re.compile(r\"\"\"\n    http(s)?://\n    (?:\n        (?P<subdomain>.+)\n        \\.\n    )?\n    douyu.com/\n    (?:\n        show/(?P<vid>[^/&?]+)|\n        (?P<channel>[^/&?]+)\n    )\n\"\"\", re.VERBOSE)\n\n_room_id_re = re.compile(r'\"room_id\\\\*\"\\s*:\\s*(\\d+),')\n_room_id_alt_re = re.compile(r'data-onlineid=(\\d+)')\n\n_room_id_schema = validate.Schema(\n    validate.all(\n        validate.transform(_room_id_re.search),\n        validate.any(\n            None,\n            validate.all(\n                validate.get(1),\n                validate.transform(int)\n            )\n        )\n    )\n)\n\n_room_id_alt_schema = validate.Schema(\n    validate.all(\n        validate.transform(_room_id_alt_re.search),\n        validate.any(\n            None,\n            validate.all(\n                validate.get(1),\n                validate.transform(int)\n            )\n        )\n    )\n)\n\n_room_schema = validate.Schema(\n    {\n        \"data\": validate.any(None, {\n            \"show_status\": validate.all(\n                validate.text,\n                validate.transform(int)\n            ),\n            \"rtmp_url\": validate.text,\n            \"rtmp_live\": validate.text,\n            \"hls_url\": validate.text,\n            \"rtmp_multi_bitrate\": validate.all(\n                validate.any([], {\n                    validate.text: validate.text\n                }),\n                validate.transform(dict)\n            )\n        })\n    },\n    validate.get(\"data\")\n)\n\n_vapi_schema = validate.Schema(\n    {\n        \"data\": validate.any(None, {\n            \"video_url\": validate.text\n        })\n    },\n    validate.get(\"data\")\n)\n\n\nclass Douyutv(Plugin):\n    @classmethod\n    def can_handle_url(cls, url):\n        return _url_re.match(url)\n\n    @classmethod\n    def stream_weight(cls, stream):\n        if stream in STREAM_WEIGHTS:\n            return STREAM_WEIGHTS[stream], \"douyutv\"\n        return Plugin.stream_weight(stream)\n\n    def _get_streams(self):\n        match = _url_re.match(self.url)\n        subdomain = match.group(\"subdomain\")\n\n        http.verify = False\n        http.mount('https://', HTTPAdapter(max_retries=99))\n\n        if subdomain == 'v':\n            vid = match.group(\"vid\")\n            headers = {\n                \"User-Agent\": useragents.ANDROID,\n                \"X-Requested-With\": \"XMLHttpRequest\"\n            }\n            res = http.get(VAPI_URL.format(vid), headers=headers)\n            room = http.json(res, schema=_vapi_schema)\n            yield \"source\", HLSStream(self.session, room[\"video_url\"])\n            return\n\n        channel = match.group(\"channel\")\n        try:\n            channel = int(channel)\n        except ValueError:\n            channel = http.get(self.url, schema=_room_id_schema)\n            if channel is None:\n                channel = http.get(self.url, schema=_room_id_alt_schema)\n\n        http.headers.update({'User-Agent': useragents.ANDROID})\n        cdns = [\"ws\", \"tct\", \"ws2\", \"dl\"]\n        ts = int(time.time())\n        suffix = \"room/{0}?aid=androidhd1&cdn={1}&client_sys=android&time={2}\".format(channel, cdns[0], ts)\n        sign = hashlib.md5((suffix + API_SECRET).encode()).hexdigest()\n\n        res = http.get(API_URL.format(suffix, sign))\n        room = http.json(res, schema=_room_schema)\n        if not room:\n            self.logger.info(\"Not a valid room url.\")\n            return\n\n        if room[\"show_status\"] != SHOW_STATUS_ONLINE:\n            self.logger.info(\"Stream currently unavailable.\")\n            return\n\n        url = room[\"hls_url\"]\n        yield \"source\", HLSStream(self.session, url)\n\n        url = \"{room[rtmp_url]}/{room[rtmp_live]}\".format(room=room)\n        if 'rtmp:' in url:\n            stream = RTMPStream(self.session, {\n                    \"rtmp\": url,\n                    \"live\": True\n                    })\n            yield \"source\", stream\n        else:\n            yield \"source\", HTTPStream(self.session, url)\n\n        multi_streams = {\n                \"middle\": \"low\",\n                \"middle2\": \"medium\"\n                }\n        for name, url in room[\"rtmp_multi_bitrate\"].items():\n            url = \"{room[rtmp_url]}/{url}\".format(room=room, url=url)\n            name = multi_streams[name]\n            if 'rtmp:' in url:\n                stream = RTMPStream(self.session, {\n                        \"rtmp\": url,\n                        \"live\": True\n                        })\n                yield name, stream\n            else:\n                yield name, HTTPStream(self.session, url)\n\n\n__plugin__ = Douyutv\n", "path": "src/streamlink/plugins/douyutv.py"}], "after_files": [{"content": "import re\nimport time\nimport hashlib\n\nfrom requests.adapters import HTTPAdapter\n\nfrom streamlink.plugin import Plugin\nfrom streamlink.plugin.api import http, validate, useragents\nfrom streamlink.stream import HTTPStream, HLSStream, RTMPStream\n\nAPI_URL = \"https://capi.douyucdn.cn/api/v1/{0}&auth={1}\"\nVAPI_URL = \"https://vmobile.douyu.com/video/getInfo?vid={0}\"\nAPI_SECRET = \"zNzMV1y4EMxOHS6I5WKm\"\nSHOW_STATUS_ONLINE = 1\nSHOW_STATUS_OFFLINE = 2\nSTREAM_WEIGHTS = {\n        \"low\": 540,\n        \"medium\": 720,\n        \"source\": 1080\n        }\n\n_url_re = re.compile(r\"\"\"\n    http(s)?://\n    (?:\n        (?P<subdomain>.+)\n        \\.\n    )?\n    douyu.com/\n    (?:\n        show/(?P<vid>[^/&?]+)|\n        (?P<channel>[^/&?]+)\n    )\n\"\"\", re.VERBOSE)\n\n_room_id_re = re.compile(r'\"room_id\\\\*\"\\s*:\\s*(\\d+),')\n_room_id_alt_re = re.compile(r'data-onlineid=(\\d+)')\n\n_room_id_schema = validate.Schema(\n    validate.all(\n        validate.transform(_room_id_re.search),\n        validate.any(\n            None,\n            validate.all(\n                validate.get(1),\n                validate.transform(int)\n            )\n        )\n    )\n)\n\n_room_id_alt_schema = validate.Schema(\n    validate.all(\n        validate.transform(_room_id_alt_re.search),\n        validate.any(\n            None,\n            validate.all(\n                validate.get(1),\n                validate.transform(int)\n            )\n        )\n    )\n)\n\n_room_schema = validate.Schema(\n    {\n        \"data\": validate.any(None, {\n            \"show_status\": validate.all(\n                validate.text,\n                validate.transform(int)\n            ),\n            \"rtmp_url\": validate.text,\n            \"rtmp_live\": validate.text,\n            \"hls_url\": validate.text,\n            \"rtmp_multi_bitrate\": validate.all(\n                validate.any([], {\n                    validate.text: validate.text\n                }),\n                validate.transform(dict)\n            )\n        })\n    },\n    validate.get(\"data\")\n)\n\n_vapi_schema = validate.Schema(\n    {\n        \"data\": validate.any(None, {\n            \"video_url\": validate.text\n        })\n    },\n    validate.get(\"data\")\n)\n\n\nclass Douyutv(Plugin):\n    @classmethod\n    def can_handle_url(cls, url):\n        return _url_re.match(url)\n\n    @classmethod\n    def stream_weight(cls, stream):\n        if stream in STREAM_WEIGHTS:\n            return STREAM_WEIGHTS[stream], \"douyutv\"\n        return Plugin.stream_weight(stream)\n\n    def _get_streams(self):\n        match = _url_re.match(self.url)\n        subdomain = match.group(\"subdomain\")\n\n        http.verify = False\n        http.mount('https://', HTTPAdapter(max_retries=99))\n\n        if subdomain == 'v':\n            vid = match.group(\"vid\")\n            headers = {\n                \"User-Agent\": useragents.ANDROID,\n                \"X-Requested-With\": \"XMLHttpRequest\"\n            }\n            res = http.get(VAPI_URL.format(vid), headers=headers)\n            room = http.json(res, schema=_vapi_schema)\n            yield \"source\", HLSStream(self.session, room[\"video_url\"])\n            return\n\n        channel = match.group(\"channel\")\n        try:\n            channel = int(channel)\n        except ValueError:\n            channel = http.get(self.url, schema=_room_id_schema)\n            if channel is None:\n                channel = http.get(self.url, schema=_room_id_alt_schema)\n\n        http.headers.update({'User-Agent': useragents.WINDOWS_PHONE_8})\n        cdns = [\"ws\", \"tct\", \"ws2\", \"dl\"]\n        ts = int(time.time())\n        suffix = \"room/{0}?aid=wp&cdn={1}&client_sys=wp&time={2}\".format(channel, cdns[0], ts)\n        sign = hashlib.md5((suffix + API_SECRET).encode()).hexdigest()\n\n        res = http.get(API_URL.format(suffix, sign))\n        room = http.json(res, schema=_room_schema)\n        if not room:\n            self.logger.info(\"Not a valid room url.\")\n            return\n\n        if room[\"show_status\"] != SHOW_STATUS_ONLINE:\n            self.logger.info(\"Stream currently unavailable.\")\n            return\n\n        url = room[\"hls_url\"]\n        yield \"source\", HLSStream(self.session, url)\n\n        url = \"{room[rtmp_url]}/{room[rtmp_live]}\".format(room=room)\n        if 'rtmp:' in url:\n            stream = RTMPStream(self.session, {\n                    \"rtmp\": url,\n                    \"live\": True\n                    })\n            yield \"source\", stream\n        else:\n            yield \"source\", HTTPStream(self.session, url)\n\n        multi_streams = {\n                \"middle\": \"low\",\n                \"middle2\": \"medium\"\n                }\n        for name, url in room[\"rtmp_multi_bitrate\"].items():\n            url = \"{room[rtmp_url]}/{url}\".format(room=room, url=url)\n            name = multi_streams[name]\n            if 'rtmp:' in url:\n                stream = RTMPStream(self.session, {\n                        \"rtmp\": url,\n                        \"live\": True\n                        })\n                yield name, stream\n            else:\n                yield name, HTTPStream(self.session, url)\n\n\n__plugin__ = Douyutv\n", "path": "src/streamlink/plugins/douyutv.py"}]}