We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Unable to play Dailymotion live stream
### Checklist

- [x] This is a bug report.
- [ ] This is a feature request.
- [ ] This is a plugin (improvement) request.
- [ ] I have read the contribution guidelines.

### Description

Streamlink cannot read the live stream http://www.dailymotion.com/video/x3b68jn

### Reproduction steps / Explicit stream URLs to test

```
$ streamlink -l debug http://www.dailymotion.com/video/x3b68jn
[cli][info] Found matching plugin dailymotion for URL http://www.dailymotion.com/video/x3b68jn
[plugin.dailymotion][debug] Found media ID: x3b68jn
error: Unable to parse manifest XML: syntax error: line 1, column 0 ('#EXTM3U\n#EXT-X-STREAM-INF:BANDWID ...)
```

### Environment details

Operating system and version: Fedora 25
Streamlink version: https://github.com/streamlink/streamlink/commit/0c31ca9115bb62550fb3af7b626ef5496b6cf81b (latest snapshot today)
Python version: 3.5.3

### Comments, logs, screenshots, etc.
This is the only live stream on DM I've found with this issue. All the others I tested are OK.

--- 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/dailymotion.py`
Content:
```
1 import json
2 import re
3 
4 from functools import reduce
5 
6 from streamlink.compat import urlparse, range
7 from streamlink.plugin import Plugin
8 from streamlink.plugin.api import http, validate
9 from streamlink.stream import HDSStream, HLSStream, HTTPStream, RTMPStream
10 from streamlink.stream.playlist import FLVPlaylist
11 
12 COOKIES = {
13     "family_filter": "off",
14     "ff": "off"
15 }
16 QUALITY_MAP = {
17     "ld": "240p",
18     "sd": "360p",
19     "hq": "480p",
20     "hd720": "720p",
21     "hd1080": "1080p",
22     "custom": "live",
23     "auto": "hds",
24     "source": "hds"
25 }
26 STREAM_INFO_URL = "http://www.dailymotion.com/sequence/full/{0}"
27 USER_INFO_URL = "https://api.dailymotion.com/user/{0}"
28 
29 _rtmp_re = re.compile(r"""
30     (?P<host>rtmp://[^/]+)
31     /(?P<app>[^/]+)
32     /(?P<playpath>.+)
33 """, re.VERBOSE)
34 _url_re = re.compile(r"""
35     http(s)?://(\w+\.)?
36     dailymotion.com
37     (?:
38         (/embed)?/(video|live)
39         /(?P<media_id>[^_?/]+)
40     |
41         /(?P<channel_name>[A-Za-z0-9-_]+)
42     )
43 """, re.VERBOSE)
44 username_re = re.compile(r'''data-username\s*=\s*"(.*?)"''')
45 chromecast_re = re.compile(r'''stream_chromecast_url"\s*:\s*(?P<url>".*?")''')
46 
47 _media_inner_schema = validate.Schema([{
48     "layerList": [{
49         "name": validate.text,
50         validate.optional("sequenceList"): [{
51             "layerList": validate.all(
52                 [{
53                     "name": validate.text,
54                     validate.optional("param"): dict
55                 }],
56                 validate.filter(lambda l: l["name"] in ("video", "reporting"))
57             )
58         }]
59     }]
60 }])
61 _media_schema = validate.Schema(
62     validate.any(
63         _media_inner_schema,
64         validate.all(
65             {"sequence": _media_inner_schema},
66             validate.get("sequence")
67         )
68     )
69 )
70 _vod_playlist_schema = validate.Schema({
71     "duration": float,
72     "fragments": [[int, float]],
73     "template": validate.text
74 })
75 _vod_manifest_schema = validate.Schema({
76     "alternates": [{
77         "height": int,
78         "template": validate.text,
79         validate.optional("failover"): [validate.text]
80     }]
81 })
82 
83 
84 class DailyMotion(Plugin):
85     @classmethod
86     def can_handle_url(self, url):
87         return _url_re.match(url)
88 
89     def _get_streams_from_media(self, media_id):
90         res = http.get(STREAM_INFO_URL.format(media_id), cookies=COOKIES)
91         media = http.json(res, schema=_media_schema)
92 
93         params = extra_params = swf_url = None
94         for __ in media:
95             for __ in __["layerList"]:
96                 for __ in __.get("sequenceList", []):
97                     for layer in __["layerList"]:
98                         name = layer["name"]
99                         if name == "video":
100                             params = layer.get("param")
101                         elif name == "reporting":
102                             extra_params = layer.get("param", {})
103                             extra_params = extra_params.get("extraParams", {})
104 
105         if not params:
106             return
107 
108         if extra_params:
109             swf_url = extra_params.get("videoSwfURL")
110 
111         mode = params.get("mode")
112         if mode == "live":
113             return self._get_live_streams(params, swf_url)
114         elif mode == "vod":
115             return self._get_vod_streams(params)
116 
117     def _get_live_streams(self, params, swf_url):
118         for key, quality in QUALITY_MAP.items():
119             key_url = "{0}URL".format(key)
120             url = params.get(key_url)
121 
122             if not url:
123                 continue
124 
125             try:
126                 res = http.get(url, exception=IOError)
127             except IOError:
128                 continue
129 
130             if quality == "hds":
131                 streams = HDSStream.parse_manifest(self.session, res.url)
132                 for name, stream in streams.items():
133                     if key == "source":
134                         name += "+"
135 
136                     yield name, stream
137             elif res.text.startswith("rtmp"):
138                 match = _rtmp_re.match(res.text)
139                 if not match:
140                     continue
141 
142                 stream = RTMPStream(self.session, {
143                     "rtmp": match.group("host"),
144                     "app": match.group("app"),
145                     "playpath": match.group("playpath"),
146                     "swfVfy": swf_url,
147                     "live": True
148                 })
149 
150                 yield quality, stream
151 
152     def _create_flv_playlist(self, template):
153         res = http.get(template)
154         playlist = http.json(res, schema=_vod_playlist_schema)
155 
156         parsed = urlparse(template)
157         url_template = "{0}://{1}{2}".format(
158             parsed.scheme, parsed.netloc, playlist["template"]
159         )
160         segment_max = reduce(lambda i, j: i + j[0], playlist["fragments"], 0)
161 
162         substreams = [HTTPStream(self.session,
163                                  url_template.replace("$fragment$", str(i)))
164                       for i in range(1, segment_max + 1)]
165 
166         return FLVPlaylist(self.session,
167                            duration=playlist["duration"],
168                            flatten_timestamps=True,
169                            skip_header=True,
170                            streams=substreams)
171 
172     def _get_vod_streams(self, params):
173         manifest_url = params.get("autoURL")
174         if not manifest_url:
175             return
176 
177         res = http.get(manifest_url)
178         if res.headers.get("Content-Type") == "application/f4m+xml":
179             streams = HDSStream.parse_manifest(self.session, res.url)
180 
181             # TODO: Replace with "yield from" when dropping Python 2.
182             for __ in streams.items():
183                 yield __
184         elif res.headers.get("Content-Type") == "application/vnd.apple.mpegurl":
185             streams = HLSStream.parse_variant_playlist(self.session, res.url)
186 
187             # TODO: Replace with "yield from" when dropping Python 2.
188             for __ in streams.items():
189                 yield __
190         else:
191             manifest = http.json(res, schema=_vod_manifest_schema)
192             for params in manifest["alternates"]:
193                 name = "{0}p".format(params["height"])
194                 stream = self._create_flv_playlist(params["template"])
195                 yield name, stream
196 
197                 failovers = params.get("failover", [])
198                 for failover in failovers:
199                     stream = self._create_flv_playlist(failover)
200                     yield name, stream
201 
202     def _chrome_cast_stream_fallback(self):
203         self.logger.debug("Trying to find Chromecast URL as a fallback")
204         # get the page if not already available
205         page = http.get(self.url, cookies=COOKIES)
206         m = chromecast_re.search(page.text)
207         if m:
208             url = json.loads(m.group("url"))
209             return HLSStream.parse_variant_playlist(self.session, url)
210 
211     def get_featured_video(self):
212         self.logger.debug("Channel page, attempting to play featured video")
213         page = http.get(self.url, cookies=COOKIES)
214         username_m = username_re.search(page.text)
215         username = username_m and username_m.group(1)
216         if username:
217             self.logger.debug("Found username: {0}", username)
218             res = http.get(USER_INFO_URL.format(username),
219                            params={"fields": "videostar.url"})
220 
221             data = http.json(res)
222             if "videostar.url" in data and self.can_handle_url(data["videostar.url"]):
223                 return data["videostar.url"]
224 
225     def _get_streams(self):
226         match = _url_re.match(self.url)
227         media_id = match.group("media_id")
228 
229         if not media_id and match.group("channel_name"):
230             self.url = self.get_featured_video()
231             match = _url_re.match(self.url)
232             media_id = match.group("media_id")
233 
234         if media_id:
235             self.logger.debug("Found media ID: {0}", media_id)
236             streams = list(self._get_streams_from_media(media_id))
237             if streams:
238                 return streams
239 
240         return self._chrome_cast_stream_fallback()
241 
242 
243 __plugin__ = DailyMotion
244
```
--- 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()

```

diff --git a/src/streamlink/plugins/dailymotion.py b/src/streamlink/plugins/dailymotion.py
--- a/src/streamlink/plugins/dailymotion.py
+++ b/src/streamlink/plugins/dailymotion.py
@@ -128,7 +128,12 @@
                 continue
 
             if quality == "hds":
-                streams = HDSStream.parse_manifest(self.session, res.url)
+                self.logger.debug('PLAYLIST URL: {0}'.format(res.url))
+                try:
+                    streams = HDSStream.parse_manifest(self.session, res.url)
+                except:
+                    streams = HLSStream.parse_variant_playlist(self.session, res.url)
+
                 for name, stream in streams.items():
                     if key == "source":
                         name += "+"

{"golden_diff": "diff --git a/src/streamlink/plugins/dailymotion.py b/src/streamlink/plugins/dailymotion.py\n--- a/src/streamlink/plugins/dailymotion.py\n+++ b/src/streamlink/plugins/dailymotion.py\n@@ -128,7 +128,12 @@\n                 continue\n \n             if quality == \"hds\":\n-                streams = HDSStream.parse_manifest(self.session, res.url)\n+                self.logger.debug('PLAYLIST URL: {0}'.format(res.url))\n+                try:\n+                    streams = HDSStream.parse_manifest(self.session, res.url)\n+                except:\n+                    streams = HLSStream.parse_variant_playlist(self.session, res.url)\n+\n                 for name, stream in streams.items():\n                     if key == \"source\":\n                         name += \"+\"\n", "issue": "Unable to play Dailymotion live stream\n### Checklist\r\n\r\n- [x] This is a bug report.\r\n- [ ] This is a feature request.\r\n- [ ] This is a plugin (improvement) request.\r\n- [ ] I have read the contribution guidelines.\r\n\r\n### Description\r\n\r\nStreamlink cannot read the live stream http://www.dailymotion.com/video/x3b68jn\r\n\r\n### Reproduction steps / Explicit stream URLs to test\r\n\r\n```\r\n$ streamlink -l debug http://www.dailymotion.com/video/x3b68jn\r\n[cli][info] Found matching plugin dailymotion for URL http://www.dailymotion.com/video/x3b68jn\r\n[plugin.dailymotion][debug] Found media ID: x3b68jn\r\nerror: Unable to parse manifest XML: syntax error: line 1, column 0 ('#EXTM3U\\n#EXT-X-STREAM-INF:BANDWID ...)\r\n```\r\n\r\n### Environment details\r\n\r\nOperating system and version: Fedora 25\r\nStreamlink version: https://github.com/streamlink/streamlink/commit/0c31ca9115bb62550fb3af7b626ef5496b6cf81b (latest snapshot today)\r\nPython version: 3.5.3\r\n\r\n### Comments, logs, screenshots, etc.\r\nThis is the only live stream on DM I've found with this issue. All the others I tested are OK.\n", "before_files": [{"content": "import json\nimport re\n\nfrom functools import reduce\n\nfrom streamlink.compat import urlparse, range\nfrom streamlink.plugin import Plugin\nfrom streamlink.plugin.api import http, validate\nfrom streamlink.stream import HDSStream, HLSStream, HTTPStream, RTMPStream\nfrom streamlink.stream.playlist import FLVPlaylist\n\nCOOKIES = {\n    \"family_filter\": \"off\",\n    \"ff\": \"off\"\n}\nQUALITY_MAP = {\n    \"ld\": \"240p\",\n    \"sd\": \"360p\",\n    \"hq\": \"480p\",\n    \"hd720\": \"720p\",\n    \"hd1080\": \"1080p\",\n    \"custom\": \"live\",\n    \"auto\": \"hds\",\n    \"source\": \"hds\"\n}\nSTREAM_INFO_URL = \"http://www.dailymotion.com/sequence/full/{0}\"\nUSER_INFO_URL = \"https://api.dailymotion.com/user/{0}\"\n\n_rtmp_re = re.compile(r\"\"\"\n    (?P<host>rtmp://[^/]+)\n    /(?P<app>[^/]+)\n    /(?P<playpath>.+)\n\"\"\", re.VERBOSE)\n_url_re = re.compile(r\"\"\"\n    http(s)?://(\\w+\\.)?\n    dailymotion.com\n    (?:\n        (/embed)?/(video|live)\n        /(?P<media_id>[^_?/]+)\n    |\n        /(?P<channel_name>[A-Za-z0-9-_]+)\n    )\n\"\"\", re.VERBOSE)\nusername_re = re.compile(r'''data-username\\s*=\\s*\"(.*?)\"''')\nchromecast_re = re.compile(r'''stream_chromecast_url\"\\s*:\\s*(?P<url>\".*?\")''')\n\n_media_inner_schema = validate.Schema([{\n    \"layerList\": [{\n        \"name\": validate.text,\n        validate.optional(\"sequenceList\"): [{\n            \"layerList\": validate.all(\n                [{\n                    \"name\": validate.text,\n                    validate.optional(\"param\"): dict\n                }],\n                validate.filter(lambda l: l[\"name\"] in (\"video\", \"reporting\"))\n            )\n        }]\n    }]\n}])\n_media_schema = validate.Schema(\n    validate.any(\n        _media_inner_schema,\n        validate.all(\n            {\"sequence\": _media_inner_schema},\n            validate.get(\"sequence\")\n        )\n    )\n)\n_vod_playlist_schema = validate.Schema({\n    \"duration\": float,\n    \"fragments\": [[int, float]],\n    \"template\": validate.text\n})\n_vod_manifest_schema = validate.Schema({\n    \"alternates\": [{\n        \"height\": int,\n        \"template\": validate.text,\n        validate.optional(\"failover\"): [validate.text]\n    }]\n})\n\n\nclass DailyMotion(Plugin):\n    @classmethod\n    def can_handle_url(self, url):\n        return _url_re.match(url)\n\n    def _get_streams_from_media(self, media_id):\n        res = http.get(STREAM_INFO_URL.format(media_id), cookies=COOKIES)\n        media = http.json(res, schema=_media_schema)\n\n        params = extra_params = swf_url = None\n        for __ in media:\n            for __ in __[\"layerList\"]:\n                for __ in __.get(\"sequenceList\", []):\n                    for layer in __[\"layerList\"]:\n                        name = layer[\"name\"]\n                        if name == \"video\":\n                            params = layer.get(\"param\")\n                        elif name == \"reporting\":\n                            extra_params = layer.get(\"param\", {})\n                            extra_params = extra_params.get(\"extraParams\", {})\n\n        if not params:\n            return\n\n        if extra_params:\n            swf_url = extra_params.get(\"videoSwfURL\")\n\n        mode = params.get(\"mode\")\n        if mode == \"live\":\n            return self._get_live_streams(params, swf_url)\n        elif mode == \"vod\":\n            return self._get_vod_streams(params)\n\n    def _get_live_streams(self, params, swf_url):\n        for key, quality in QUALITY_MAP.items():\n            key_url = \"{0}URL\".format(key)\n            url = params.get(key_url)\n\n            if not url:\n                continue\n\n            try:\n                res = http.get(url, exception=IOError)\n            except IOError:\n                continue\n\n            if quality == \"hds\":\n                streams = HDSStream.parse_manifest(self.session, res.url)\n                for name, stream in streams.items():\n                    if key == \"source\":\n                        name += \"+\"\n\n                    yield name, stream\n            elif res.text.startswith(\"rtmp\"):\n                match = _rtmp_re.match(res.text)\n                if not match:\n                    continue\n\n                stream = RTMPStream(self.session, {\n                    \"rtmp\": match.group(\"host\"),\n                    \"app\": match.group(\"app\"),\n                    \"playpath\": match.group(\"playpath\"),\n                    \"swfVfy\": swf_url,\n                    \"live\": True\n                })\n\n                yield quality, stream\n\n    def _create_flv_playlist(self, template):\n        res = http.get(template)\n        playlist = http.json(res, schema=_vod_playlist_schema)\n\n        parsed = urlparse(template)\n        url_template = \"{0}://{1}{2}\".format(\n            parsed.scheme, parsed.netloc, playlist[\"template\"]\n        )\n        segment_max = reduce(lambda i, j: i + j[0], playlist[\"fragments\"], 0)\n\n        substreams = [HTTPStream(self.session,\n                                 url_template.replace(\"$fragment$\", str(i)))\n                      for i in range(1, segment_max + 1)]\n\n        return FLVPlaylist(self.session,\n                           duration=playlist[\"duration\"],\n                           flatten_timestamps=True,\n                           skip_header=True,\n                           streams=substreams)\n\n    def _get_vod_streams(self, params):\n        manifest_url = params.get(\"autoURL\")\n        if not manifest_url:\n            return\n\n        res = http.get(manifest_url)\n        if res.headers.get(\"Content-Type\") == \"application/f4m+xml\":\n            streams = HDSStream.parse_manifest(self.session, res.url)\n\n            # TODO: Replace with \"yield from\" when dropping Python 2.\n            for __ in streams.items():\n                yield __\n        elif res.headers.get(\"Content-Type\") == \"application/vnd.apple.mpegurl\":\n            streams = HLSStream.parse_variant_playlist(self.session, res.url)\n\n            # TODO: Replace with \"yield from\" when dropping Python 2.\n            for __ in streams.items():\n                yield __\n        else:\n            manifest = http.json(res, schema=_vod_manifest_schema)\n            for params in manifest[\"alternates\"]:\n                name = \"{0}p\".format(params[\"height\"])\n                stream = self._create_flv_playlist(params[\"template\"])\n                yield name, stream\n\n                failovers = params.get(\"failover\", [])\n                for failover in failovers:\n                    stream = self._create_flv_playlist(failover)\n                    yield name, stream\n\n    def _chrome_cast_stream_fallback(self):\n        self.logger.debug(\"Trying to find Chromecast URL as a fallback\")\n        # get the page if not already available\n        page = http.get(self.url, cookies=COOKIES)\n        m = chromecast_re.search(page.text)\n        if m:\n            url = json.loads(m.group(\"url\"))\n            return HLSStream.parse_variant_playlist(self.session, url)\n\n    def get_featured_video(self):\n        self.logger.debug(\"Channel page, attempting to play featured video\")\n        page = http.get(self.url, cookies=COOKIES)\n        username_m = username_re.search(page.text)\n        username = username_m and username_m.group(1)\n        if username:\n            self.logger.debug(\"Found username: {0}\", username)\n            res = http.get(USER_INFO_URL.format(username),\n                           params={\"fields\": \"videostar.url\"})\n\n            data = http.json(res)\n            if \"videostar.url\" in data and self.can_handle_url(data[\"videostar.url\"]):\n                return data[\"videostar.url\"]\n\n    def _get_streams(self):\n        match = _url_re.match(self.url)\n        media_id = match.group(\"media_id\")\n\n        if not media_id and match.group(\"channel_name\"):\n            self.url = self.get_featured_video()\n            match = _url_re.match(self.url)\n            media_id = match.group(\"media_id\")\n\n        if media_id:\n            self.logger.debug(\"Found media ID: {0}\", media_id)\n            streams = list(self._get_streams_from_media(media_id))\n            if streams:\n                return streams\n\n        return self._chrome_cast_stream_fallback()\n\n\n__plugin__ = DailyMotion\n", "path": "src/streamlink/plugins/dailymotion.py"}], "after_files": [{"content": "import json\nimport re\n\nfrom functools import reduce\n\nfrom streamlink.compat import urlparse, range\nfrom streamlink.plugin import Plugin\nfrom streamlink.plugin.api import http, validate\nfrom streamlink.stream import HDSStream, HLSStream, HTTPStream, RTMPStream\nfrom streamlink.stream.playlist import FLVPlaylist\n\nCOOKIES = {\n    \"family_filter\": \"off\",\n    \"ff\": \"off\"\n}\nQUALITY_MAP = {\n    \"ld\": \"240p\",\n    \"sd\": \"360p\",\n    \"hq\": \"480p\",\n    \"hd720\": \"720p\",\n    \"hd1080\": \"1080p\",\n    \"custom\": \"live\",\n    \"auto\": \"hds\",\n    \"source\": \"hds\"\n}\nSTREAM_INFO_URL = \"http://www.dailymotion.com/sequence/full/{0}\"\nUSER_INFO_URL = \"https://api.dailymotion.com/user/{0}\"\n\n_rtmp_re = re.compile(r\"\"\"\n    (?P<host>rtmp://[^/]+)\n    /(?P<app>[^/]+)\n    /(?P<playpath>.+)\n\"\"\", re.VERBOSE)\n_url_re = re.compile(r\"\"\"\n    http(s)?://(\\w+\\.)?\n    dailymotion.com\n    (?:\n        (/embed)?/(video|live)\n        /(?P<media_id>[^_?/]+)\n    |\n        /(?P<channel_name>[A-Za-z0-9-_]+)\n    )\n\"\"\", re.VERBOSE)\nusername_re = re.compile(r'''data-username\\s*=\\s*\"(.*?)\"''')\nchromecast_re = re.compile(r'''stream_chromecast_url\"\\s*:\\s*(?P<url>\".*?\")''')\n\n_media_inner_schema = validate.Schema([{\n    \"layerList\": [{\n        \"name\": validate.text,\n        validate.optional(\"sequenceList\"): [{\n            \"layerList\": validate.all(\n                [{\n                    \"name\": validate.text,\n                    validate.optional(\"param\"): dict\n                }],\n                validate.filter(lambda l: l[\"name\"] in (\"video\", \"reporting\"))\n            )\n        }]\n    }]\n}])\n_media_schema = validate.Schema(\n    validate.any(\n        _media_inner_schema,\n        validate.all(\n            {\"sequence\": _media_inner_schema},\n            validate.get(\"sequence\")\n        )\n    )\n)\n_vod_playlist_schema = validate.Schema({\n    \"duration\": float,\n    \"fragments\": [[int, float]],\n    \"template\": validate.text\n})\n_vod_manifest_schema = validate.Schema({\n    \"alternates\": [{\n        \"height\": int,\n        \"template\": validate.text,\n        validate.optional(\"failover\"): [validate.text]\n    }]\n})\n\n\nclass DailyMotion(Plugin):\n    @classmethod\n    def can_handle_url(self, url):\n        return _url_re.match(url)\n\n    def _get_streams_from_media(self, media_id):\n        res = http.get(STREAM_INFO_URL.format(media_id), cookies=COOKIES)\n        media = http.json(res, schema=_media_schema)\n\n        params = extra_params = swf_url = None\n        for __ in media:\n            for __ in __[\"layerList\"]:\n                for __ in __.get(\"sequenceList\", []):\n                    for layer in __[\"layerList\"]:\n                        name = layer[\"name\"]\n                        if name == \"video\":\n                            params = layer.get(\"param\")\n                        elif name == \"reporting\":\n                            extra_params = layer.get(\"param\", {})\n                            extra_params = extra_params.get(\"extraParams\", {})\n\n        if not params:\n            return\n\n        if extra_params:\n            swf_url = extra_params.get(\"videoSwfURL\")\n\n        mode = params.get(\"mode\")\n        if mode == \"live\":\n            return self._get_live_streams(params, swf_url)\n        elif mode == \"vod\":\n            return self._get_vod_streams(params)\n\n    def _get_live_streams(self, params, swf_url):\n        for key, quality in QUALITY_MAP.items():\n            key_url = \"{0}URL\".format(key)\n            url = params.get(key_url)\n\n            if not url:\n                continue\n\n            try:\n                res = http.get(url, exception=IOError)\n            except IOError:\n                continue\n\n            if quality == \"hds\":\n                self.logger.debug('PLAYLIST URL: {0}'.format(res.url))\n                try:\n                    streams = HDSStream.parse_manifest(self.session, res.url)\n                except:\n                    streams = HLSStream.parse_variant_playlist(self.session, res.url)\n\n                for name, stream in streams.items():\n                    if key == \"source\":\n                        name += \"+\"\n\n                    yield name, stream\n            elif res.text.startswith(\"rtmp\"):\n                match = _rtmp_re.match(res.text)\n                if not match:\n                    continue\n\n                stream = RTMPStream(self.session, {\n                    \"rtmp\": match.group(\"host\"),\n                    \"app\": match.group(\"app\"),\n                    \"playpath\": match.group(\"playpath\"),\n                    \"swfVfy\": swf_url,\n                    \"live\": True\n                })\n\n                yield quality, stream\n\n    def _create_flv_playlist(self, template):\n        res = http.get(template)\n        playlist = http.json(res, schema=_vod_playlist_schema)\n\n        parsed = urlparse(template)\n        url_template = \"{0}://{1}{2}\".format(\n            parsed.scheme, parsed.netloc, playlist[\"template\"]\n        )\n        segment_max = reduce(lambda i, j: i + j[0], playlist[\"fragments\"], 0)\n\n        substreams = [HTTPStream(self.session,\n                                 url_template.replace(\"$fragment$\", str(i)))\n                      for i in range(1, segment_max + 1)]\n\n        return FLVPlaylist(self.session,\n                           duration=playlist[\"duration\"],\n                           flatten_timestamps=True,\n                           skip_header=True,\n                           streams=substreams)\n\n    def _get_vod_streams(self, params):\n        manifest_url = params.get(\"autoURL\")\n        if not manifest_url:\n            return\n\n        res = http.get(manifest_url)\n        if res.headers.get(\"Content-Type\") == \"application/f4m+xml\":\n            streams = HDSStream.parse_manifest(self.session, res.url)\n\n            # TODO: Replace with \"yield from\" when dropping Python 2.\n            for __ in streams.items():\n                yield __\n        elif res.headers.get(\"Content-Type\") == \"application/vnd.apple.mpegurl\":\n            streams = HLSStream.parse_variant_playlist(self.session, res.url)\n\n            # TODO: Replace with \"yield from\" when dropping Python 2.\n            for __ in streams.items():\n                yield __\n        else:\n            manifest = http.json(res, schema=_vod_manifest_schema)\n            for params in manifest[\"alternates\"]:\n                name = \"{0}p\".format(params[\"height\"])\n                stream = self._create_flv_playlist(params[\"template\"])\n                yield name, stream\n\n                failovers = params.get(\"failover\", [])\n                for failover in failovers:\n                    stream = self._create_flv_playlist(failover)\n                    yield name, stream\n\n    def _chrome_cast_stream_fallback(self):\n        self.logger.debug(\"Trying to find Chromecast URL as a fallback\")\n        # get the page if not already available\n        page = http.get(self.url, cookies=COOKIES)\n        m = chromecast_re.search(page.text)\n        if m:\n            url = json.loads(m.group(\"url\"))\n            return HLSStream.parse_variant_playlist(self.session, url)\n\n    def get_featured_video(self):\n        self.logger.debug(\"Channel page, attempting to play featured video\")\n        page = http.get(self.url, cookies=COOKIES)\n        username_m = username_re.search(page.text)\n        username = username_m and username_m.group(1)\n        if username:\n            self.logger.debug(\"Found username: {0}\", username)\n            res = http.get(USER_INFO_URL.format(username),\n                           params={\"fields\": \"videostar.url\"})\n\n            data = http.json(res)\n            if \"videostar.url\" in data and self.can_handle_url(data[\"videostar.url\"]):\n                return data[\"videostar.url\"]\n\n    def _get_streams(self):\n        match = _url_re.match(self.url)\n        media_id = match.group(\"media_id\")\n\n        if not media_id and match.group(\"channel_name\"):\n            self.url = self.get_featured_video()\n            match = _url_re.match(self.url)\n            media_id = match.group(\"media_id\")\n\n        if media_id:\n            self.logger.debug(\"Found media ID: {0}\", media_id)\n            streams = list(self._get_streams_from_media(media_id))\n            if streams:\n                return streams\n\n        return self._chrome_cast_stream_fallback()\n\n\n__plugin__ = DailyMotion\n", "path": "src/streamlink/plugins/dailymotion.py"}]}