prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Request: Add more functions to facebook plugin
  ### Checklist
  
  - [x] This is a bug report.
  - [ ] This is a feature request.
  - [x] This is a plugin (improvement) request.
  - [ ] I have read the contribution guidelines.
  
  ### Description
  Reminder that with the new initial support of Mpeg Dash #880 and #990 might be fixable now, depending on what streamlink supports and how Facebook's videos and livestreaming has changed since this was last looked it.
  
  
  </issue>
  <code>
  [start of src/streamlink/plugins/facebook.py]
  1 import re
  2 
  3 from streamlink.plugin import Plugin
  4 from streamlink.stream import HLSStream
  5 
  6 _playlist_url = "https://www.facebook.com/video/playback/playlist.m3u8?v={0}"
  7 
  8 _url_re = re.compile(r"http(s)?://(www\.)?facebook\.com/[^/]+/videos/(?P<video_id>\d+)")
  9 
  10 
  11 class Facebook(Plugin):
  12     @classmethod
  13     def can_handle_url(cls, url):
  14         return _url_re.match(url)
  15 
  16     @Plugin.broken(990)
  17     def _get_streams(self):
  18         match = _url_re.match(self.url)
  19         video = match.group("video_id")
  20 
  21         playlist = _playlist_url.format(video)
  22 
  23         return HLSStream.parse_variant_playlist(self.session, playlist)
  24 
  25 
  26 __plugin__ = Facebook
  27
  [end of src/streamlink/plugins/facebook.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/src/streamlink/plugins/facebook.py b/src/streamlink/plugins/facebook.py
  --- a/src/streamlink/plugins/facebook.py
  +++ b/src/streamlink/plugins/facebook.py
  @@ -1,26 +1,42 @@
   import re
   
   from streamlink.plugin import Plugin
  -from streamlink.stream import HLSStream
  -
  -_playlist_url = "https://www.facebook.com/video/playback/playlist.m3u8?v={0}"
  -
  -_url_re = re.compile(r"http(s)?://(www\.)?facebook\.com/[^/]+/videos/(?P<video_id>\d+)")
  +from streamlink.plugin.api import http, useragents
  +from streamlink.stream import DASHStream, HTTPStream
  +from streamlink.utils import parse_json
   
   
   class Facebook(Plugin):
  +    _url_re = re.compile(r"https?://(?:www\.)?facebook\.com/[^/]+/videos")
  +    _mpd_re = re.compile(r'''(sd|hd)_src["']?\s*:\s*(?P<quote>["'])(?P<url>.+?)(?P=quote)''')
  +    _playlist_re = re.compile(r'''video:\[({url:".+?}\])''')
  +    _plurl_re = re.compile(r'''url:"(.*?)"''')
  +
       @classmethod
       def can_handle_url(cls, url):
  -        return _url_re.match(url)
  +        return cls._url_re.match(url)
   
  -    @Plugin.broken(990)
       def _get_streams(self):
  -        match = _url_re.match(self.url)
  -        video = match.group("video_id")
  +        res = http.get(self.url, headers={"User-Agent": useragents.CHROME})
  +        with open("temp.html", "w") as f:
  +            f.write(res.text)
  +
  +        for match in self._mpd_re.finditer(res.text):
  +            manifest_url = match.group("url")
  +            if "\\/" in manifest_url:
  +                # if the URL is json encoded, decode it
  +                manifest_url = parse_json("\"{}\"".format(manifest_url))
  +            for s in DASHStream.parse_manifest(self.session, manifest_url).items():
  +                yield s
  +        else:
  +            match = self._playlist_re.search(res.text)
  +            playlist = match and match.group(1)
  +            if playlist:
  +                for url in {url.group(1) for url in self._plurl_re.finditer(playlist)}:
  +                    yield "live", HTTPStream(self.session, url)
  +
   
  -        playlist = _playlist_url.format(video)
   
  -        return HLSStream.parse_variant_playlist(self.session, playlist)
   
   
   __plugin__ = Facebook
  
verification_info: {"golden_diff": "diff --git a/src/streamlink/plugins/facebook.py b/src/streamlink/plugins/facebook.py\n--- a/src/streamlink/plugins/facebook.py\n+++ b/src/streamlink/plugins/facebook.py\n@@ -1,26 +1,42 @@\n import re\n \n from streamlink.plugin import Plugin\n-from streamlink.stream import HLSStream\n-\n-_playlist_url = \"https://www.facebook.com/video/playback/playlist.m3u8?v={0}\"\n-\n-_url_re = re.compile(r\"http(s)?://(www\\.)?facebook\\.com/[^/]+/videos/(?P<video_id>\\d+)\")\n+from streamlink.plugin.api import http, useragents\n+from streamlink.stream import DASHStream, HTTPStream\n+from streamlink.utils import parse_json\n \n \n class Facebook(Plugin):\n+    _url_re = re.compile(r\"https?://(?:www\\.)?facebook\\.com/[^/]+/videos\")\n+    _mpd_re = re.compile(r'''(sd|hd)_src[\"']?\\s*:\\s*(?P<quote>[\"'])(?P<url>.+?)(?P=quote)''')\n+    _playlist_re = re.compile(r'''video:\\[({url:\".+?}\\])''')\n+    _plurl_re = re.compile(r'''url:\"(.*?)\"''')\n+\n     @classmethod\n     def can_handle_url(cls, url):\n-        return _url_re.match(url)\n+        return cls._url_re.match(url)\n \n-    @Plugin.broken(990)\n     def _get_streams(self):\n-        match = _url_re.match(self.url)\n-        video = match.group(\"video_id\")\n+        res = http.get(self.url, headers={\"User-Agent\": useragents.CHROME})\n+        with open(\"temp.html\", \"w\") as f:\n+            f.write(res.text)\n+\n+        for match in self._mpd_re.finditer(res.text):\n+            manifest_url = match.group(\"url\")\n+            if \"\\\\/\" in manifest_url:\n+                # if the URL is json encoded, decode it\n+                manifest_url = parse_json(\"\\\"{}\\\"\".format(manifest_url))\n+            for s in DASHStream.parse_manifest(self.session, manifest_url).items():\n+                yield s\n+        else:\n+            match = self._playlist_re.search(res.text)\n+            playlist = match and match.group(1)\n+            if playlist:\n+                for url in {url.group(1) for url in self._plurl_re.finditer(playlist)}:\n+                    yield \"live\", HTTPStream(self.session, url)\n+\n \n-        playlist = _playlist_url.format(video)\n \n-        return HLSStream.parse_variant_playlist(self.session, playlist)\n \n \n __plugin__ = Facebook\n", "issue": "Request: Add more functions to facebook plugin\n### Checklist\r\n\r\n- [x] This is a bug report.\r\n- [ ] This is a feature request.\r\n- [x] This is a plugin (improvement) request.\r\n- [ ] I have read the contribution guidelines.\r\n\r\n### Description\r\nReminder that with the new initial support of Mpeg Dash #880 and #990 might be fixable now, depending on what streamlink supports and how Facebook's videos and livestreaming has changed since this was last looked it.\r\n\n", "before_files": [{"content": "import re\n\nfrom streamlink.plugin import Plugin\nfrom streamlink.stream import HLSStream\n\n_playlist_url = \"https://www.facebook.com/video/playback/playlist.m3u8?v={0}\"\n\n_url_re = re.compile(r\"http(s)?://(www\\.)?facebook\\.com/[^/]+/videos/(?P<video_id>\\d+)\")\n\n\nclass Facebook(Plugin):\n    @classmethod\n    def can_handle_url(cls, url):\n        return _url_re.match(url)\n\n    @Plugin.broken(990)\n    def _get_streams(self):\n        match = _url_re.match(self.url)\n        video = match.group(\"video_id\")\n\n        playlist = _playlist_url.format(video)\n\n        return HLSStream.parse_variant_playlist(self.session, playlist)\n\n\n__plugin__ = Facebook\n", "path": "src/streamlink/plugins/facebook.py"}]}