prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  tf1 plugin better stream
  Hi,
  
  Are you sure there isn't better stream than 360p for TF1 ?
  [cli][info] Found matching plugin tf1 for URL https://www.tf1.fr/tf1/direct
  [cli][info] Available streams: 496k (worst), 234p_alt, 234p, 896k, 360p_alt, 360p (best)
  
  I have a far better quality with a web browser than best.
  
  --- 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/tf1.py`
  Content:
  ```
  1 from __future__ import print_function
  2 import re
  3 
  4 from streamlink.plugin import Plugin
  5 from streamlink.plugin.api import http, useragents
  6 from streamlink.stream import HDSStream
  7 from streamlink.stream import HLSStream
  8 
  9 
  10 class TF1(Plugin):
  11     url_re = re.compile(r"https?://(?:www\.)?(?:tf1\.fr/(tf1|tmc|tfx|tf1-series-films)/direct|(lci).fr/direct)/?")
  12     embed_url = "http://www.wat.tv/embedframe/live{0}"
  13     embed_re = re.compile(r"urlLive.*?:.*?\"(http.*?)\"", re.MULTILINE)
  14     api_url = "http://www.wat.tv/get/{0}/591997"
  15     swf_url = "http://www.wat.tv/images/v70/PlayerLite.swf"
  16     hds_channel_remap = {"tf1": "androidliveconnect", "lci": "androidlivelci", "tfx" : "nt1live", "tf1-series-films" : "hd1live" }
  17     hls_channel_remap = {"lci": "LCI", "tf1": "V4", "tfx" : "nt1", "tf1-series-films" : "hd1" }
  18 
  19     @classmethod
  20     def can_handle_url(cls, url):
  21         return cls.url_re.match(url) is not None
  22 
  23     def _get_hds_streams(self, channel):
  24         channel = self.hds_channel_remap.get(channel, "{0}live".format(channel))
  25         manifest_url = http.get(self.api_url.format(channel),
  26                                 params={"getURL": 1},
  27                                 headers={"User-Agent": useragents.FIREFOX}).text
  28 
  29         for s in HDSStream.parse_manifest(self.session,
  30                                           manifest_url,
  31                                           pvswf=self.swf_url,
  32                                           headers={"User-Agent": useragents.FIREFOX}).items():
  33             yield s
  34 
  35     def _get_hls_streams(self, channel):
  36         channel = self.hls_channel_remap.get(channel, channel)
  37         embed_url = self.embed_url.format(channel)
  38         self.logger.debug("Found embed URL: {0}", embed_url)
  39         # page needs to have a mobile user agent
  40         embed_page = http.get(embed_url, headers={"User-Agent": useragents.ANDROID})
  41 
  42         m = self.embed_re.search(embed_page.text)
  43         if m:
  44             hls_stream_url = m.group(1)
  45 
  46             try:
  47                 for s in HLSStream.parse_variant_playlist(self.session, hls_stream_url).items():
  48                     yield s
  49             except Exception:
  50                 self.logger.error("Failed to load the HLS playlist for {0}", channel)
  51 
  52     def _get_streams(self):
  53         m = self.url_re.match(self.url)
  54         if m:
  55             channel = m.group(1) or m.group(2)
  56             self.logger.debug("Found channel {0}", channel)
  57             for s in self._get_hds_streams(channel):
  58                 yield s
  59 
  60             for s in self._get_hls_streams(channel):
  61                 yield s
  62 
  63 
  64 __plugin__ = TF1
  65
  ```
  --- 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/tf1.py b/src/streamlink/plugins/tf1.py
  --- a/src/streamlink/plugins/tf1.py
  +++ b/src/streamlink/plugins/tf1.py
  @@ -1,6 +1,7 @@
   from __future__ import print_function
   import re
   
  +from streamlink.compat import urlparse, parse_qsl
   from streamlink.plugin import Plugin
   from streamlink.plugin.api import http, useragents
   from streamlink.stream import HDSStream
  @@ -41,8 +42,9 @@
   
           m = self.embed_re.search(embed_page.text)
           if m:
  -            hls_stream_url = m.group(1)
  -
  +            o = urlparse(m.group(1))
  +            prms = dict(parse_qsl(o.query))
  +            hls_stream_url = "{0}://{1}{2}?hdnea={3}".format(o.scheme, o.netloc, o.path, prms["hdnea"])
               try:
                   for s in HLSStream.parse_variant_playlist(self.session, hls_stream_url).items():
                       yield s
  
verification_info: {"golden_diff": "diff --git a/src/streamlink/plugins/tf1.py b/src/streamlink/plugins/tf1.py\n--- a/src/streamlink/plugins/tf1.py\n+++ b/src/streamlink/plugins/tf1.py\n@@ -1,6 +1,7 @@\n from __future__ import print_function\n import re\n \n+from streamlink.compat import urlparse, parse_qsl\n from streamlink.plugin import Plugin\n from streamlink.plugin.api import http, useragents\n from streamlink.stream import HDSStream\n@@ -41,8 +42,9 @@\n \n         m = self.embed_re.search(embed_page.text)\n         if m:\n-            hls_stream_url = m.group(1)\n-\n+            o = urlparse(m.group(1))\n+            prms = dict(parse_qsl(o.query))\n+            hls_stream_url = \"{0}://{1}{2}?hdnea={3}\".format(o.scheme, o.netloc, o.path, prms[\"hdnea\"])\n             try:\n                 for s in HLSStream.parse_variant_playlist(self.session, hls_stream_url).items():\n                     yield s\n", "issue": "tf1 plugin better stream\nHi,\r\n\r\nAre you sure there isn't better stream than 360p for TF1 ?\r\n[cli][info] Found matching plugin tf1 for URL https://www.tf1.fr/tf1/direct\r\n[cli][info] Available streams: 496k (worst), 234p_alt, 234p, 896k, 360p_alt, 360p (best)\r\n\r\nI have a far better quality with a web browser than best.\n", "before_files": [{"content": "from __future__ import print_function\nimport re\n\nfrom streamlink.plugin import Plugin\nfrom streamlink.plugin.api import http, useragents\nfrom streamlink.stream import HDSStream\nfrom streamlink.stream import HLSStream\n\n\nclass TF1(Plugin):\n    url_re = re.compile(r\"https?://(?:www\\.)?(?:tf1\\.fr/(tf1|tmc|tfx|tf1-series-films)/direct|(lci).fr/direct)/?\")\n    embed_url = \"http://www.wat.tv/embedframe/live{0}\"\n    embed_re = re.compile(r\"urlLive.*?:.*?\\\"(http.*?)\\\"\", re.MULTILINE)\n    api_url = \"http://www.wat.tv/get/{0}/591997\"\n    swf_url = \"http://www.wat.tv/images/v70/PlayerLite.swf\"\n    hds_channel_remap = {\"tf1\": \"androidliveconnect\", \"lci\": \"androidlivelci\", \"tfx\" : \"nt1live\", \"tf1-series-films\" : \"hd1live\" }\n    hls_channel_remap = {\"lci\": \"LCI\", \"tf1\": \"V4\", \"tfx\" : \"nt1\", \"tf1-series-films\" : \"hd1\" }\n\n    @classmethod\n    def can_handle_url(cls, url):\n        return cls.url_re.match(url) is not None\n\n    def _get_hds_streams(self, channel):\n        channel = self.hds_channel_remap.get(channel, \"{0}live\".format(channel))\n        manifest_url = http.get(self.api_url.format(channel),\n                                params={\"getURL\": 1},\n                                headers={\"User-Agent\": useragents.FIREFOX}).text\n\n        for s in HDSStream.parse_manifest(self.session,\n                                          manifest_url,\n                                          pvswf=self.swf_url,\n                                          headers={\"User-Agent\": useragents.FIREFOX}).items():\n            yield s\n\n    def _get_hls_streams(self, channel):\n        channel = self.hls_channel_remap.get(channel, channel)\n        embed_url = self.embed_url.format(channel)\n        self.logger.debug(\"Found embed URL: {0}\", embed_url)\n        # page needs to have a mobile user agent\n        embed_page = http.get(embed_url, headers={\"User-Agent\": useragents.ANDROID})\n\n        m = self.embed_re.search(embed_page.text)\n        if m:\n            hls_stream_url = m.group(1)\n\n            try:\n                for s in HLSStream.parse_variant_playlist(self.session, hls_stream_url).items():\n                    yield s\n            except Exception:\n                self.logger.error(\"Failed to load the HLS playlist for {0}\", channel)\n\n    def _get_streams(self):\n        m = self.url_re.match(self.url)\n        if m:\n            channel = m.group(1) or m.group(2)\n            self.logger.debug(\"Found channel {0}\", channel)\n            for s in self._get_hds_streams(channel):\n                yield s\n\n            for s in self._get_hls_streams(channel):\n                yield s\n\n\n__plugin__ = TF1\n", "path": "src/streamlink/plugins/tf1.py"}], "after_files": [{"content": "from __future__ import print_function\nimport re\n\nfrom streamlink.compat import urlparse, parse_qsl\nfrom streamlink.plugin import Plugin\nfrom streamlink.plugin.api import http, useragents\nfrom streamlink.stream import HDSStream\nfrom streamlink.stream import HLSStream\n\n\nclass TF1(Plugin):\n    url_re = re.compile(r\"https?://(?:www\\.)?(?:tf1\\.fr/(tf1|tmc|tfx|tf1-series-films)/direct|(lci).fr/direct)/?\")\n    embed_url = \"http://www.wat.tv/embedframe/live{0}\"\n    embed_re = re.compile(r\"urlLive.*?:.*?\\\"(http.*?)\\\"\", re.MULTILINE)\n    api_url = \"http://www.wat.tv/get/{0}/591997\"\n    swf_url = \"http://www.wat.tv/images/v70/PlayerLite.swf\"\n    hds_channel_remap = {\"tf1\": \"androidliveconnect\", \"lci\": \"androidlivelci\", \"tfx\" : \"nt1live\", \"tf1-series-films\" : \"hd1live\" }\n    hls_channel_remap = {\"lci\": \"LCI\", \"tf1\": \"V4\", \"tfx\" : \"nt1\", \"tf1-series-films\" : \"hd1\" }\n\n    @classmethod\n    def can_handle_url(cls, url):\n        return cls.url_re.match(url) is not None\n\n    def _get_hds_streams(self, channel):\n        channel = self.hds_channel_remap.get(channel, \"{0}live\".format(channel))\n        manifest_url = http.get(self.api_url.format(channel),\n                                params={\"getURL\": 1},\n                                headers={\"User-Agent\": useragents.FIREFOX}).text\n\n        for s in HDSStream.parse_manifest(self.session,\n                                          manifest_url,\n                                          pvswf=self.swf_url,\n                                          headers={\"User-Agent\": useragents.FIREFOX}).items():\n            yield s\n\n    def _get_hls_streams(self, channel):\n        channel = self.hls_channel_remap.get(channel, channel)\n        embed_url = self.embed_url.format(channel)\n        self.logger.debug(\"Found embed URL: {0}\", embed_url)\n        # page needs to have a mobile user agent\n        embed_page = http.get(embed_url, headers={\"User-Agent\": useragents.ANDROID})\n\n        m = self.embed_re.search(embed_page.text)\n        if m:\n            o = urlparse(m.group(1))\n            prms = dict(parse_qsl(o.query))\n            hls_stream_url = \"{0}://{1}{2}?hdnea={3}\".format(o.scheme, o.netloc, o.path, prms[\"hdnea\"])\n            try:\n                for s in HLSStream.parse_variant_playlist(self.session, hls_stream_url).items():\n                    yield s\n            except Exception:\n                self.logger.error(\"Failed to load the HLS playlist for {0}\", channel)\n\n    def _get_streams(self):\n        m = self.url_re.match(self.url)\n        if m:\n            channel = m.group(1) or m.group(2)\n            self.logger.debug(\"Found channel {0}\", channel)\n            for s in self._get_hds_streams(channel):\n                yield s\n\n            for s in self._get_hls_streams(channel):\n                yield s\n\n\n__plugin__ = TF1\n", "path": "src/streamlink/plugins/tf1.py"}]}