Repository: streamlink/streamlink

Issue:
Issue with Steam Broadcasting plugin
<!--
Thanks for reporting a plugin issue!
USE THE TEMPLATE. Otherwise your plugin issue may be rejected.

First, see the contribution guidelines:
https://github.com/streamlink/streamlink/blob/master/CONTRIBUTING.md#contributing-to-streamlink

Also check the list of open and closed plugin issues:
https://github.com/streamlink/streamlink/issues?q=is%3Aissue+label%3A%22plugin+issue%22

Please see the text preview to avoid unnecessary formatting errors.
-->


## Plugin Issue

<!-- Replace [ ] with [x] in order to check the box -->
- [x] This is a plugin issue and I have read the contribution guidelines.


### Description

<!-- Explain the plugin issue as thoroughly as you can. -->
Whenever I try to open a public stream from the list of "https://steamcommunity.com/?subsection=broadcasts" I get an error and stream doesn't open


### Reproduction steps / Explicit stream URLs to test

Example URL:
* https://steamcommunity.com/broadcast/watch/76561198046964848
* https://steamcommunity.com/broadcast/watch/76561198835282120


<!-- How can we reproduce this? Please note the exact steps below using the list format supplied. If you need more steps please add them. -->

1. Open CMD/Powershell
2. Type streamlink linktostream best



### Log output


<!--
TEXT LOG OUTPUT IS REQUIRED for a plugin issue!
Use the `--loglevel debug` parameter and avoid using parameters which suppress log output.
https://streamlink.github.io/cli.html#cmdoption-l

Make sure to **remove usernames and passwords**
You can copy the output to https://gist.github.com/ or paste it below.
-->

```
PS C:\WINDOWS\system32> streamlink steamcommunity.com/broadcast/watch/76561198046964848 best --loglevel debug
[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.5.2
[cli][debug] Streamlink: 0.14.2
[cli][debug] Requests(2.19.1), Socks(1.6.7), Websocket(0.48.0)
[cli][info] Found matching plugin steam for URL steamcommunity.com/broadcast/watch/76561198046964848
error: Unable to open URL: https://steamcommunity.com/broadcast/getbroadcastmpd/ (403 Client Error: Forbidden for url: https://steamcommunity.com/broadcast/getbroadcastmpd/?viewertoken=0&steamid=76561198046964848&broadcastid=0)
```


### Additional comments, screenshots, etc.



[Love Streamlink? Please consider supporting our collective. Thanks!](https://opencollective.com/streamlink/donate)



Discussion:

Resolving patch:
diff --git a/src/streamlink/plugins/steam.py b/src/streamlink/plugins/steam.py
--- a/src/streamlink/plugins/steam.py
+++ b/src/streamlink/plugins/steam.py
@@ -69,7 +69,7 @@ class SteamBroadcastPlugin(Plugin):
             help="""
             A Steam account password to use with --steam-email.
             """
-    ))
+        ))
 
     def __init__(self, url):
         super(SteamBroadcastPlugin, self).__init__(url)
@@ -175,11 +175,13 @@ def login(self, email, password):
         log.info("Attempting to login to Steam as {}".format(email))
         return self.dologin(email, password)
 
-    def _get_broadcast_stream(self, steamid, viewertoken=0):
+    def _get_broadcast_stream(self, steamid, viewertoken=0, sessionid=None):
+        log.debug("Getting broadcast stream: sessionid={0}".format(sessionid))
         res = self.session.http.get(self._get_broadcast_url,
-                       params=dict(broadcastid=0,
-                                   steamid=steamid,
-                                   viewertoken=viewertoken))
+                                    params=dict(broadcastid=0,
+                                                steamid=steamid,
+                                                viewertoken=viewertoken,
+                                                sessionid=sessionid))
         return self.session.http.json(res, schema=self._broadcast_schema)
 
     def _get_streams(self):
@@ -191,9 +193,12 @@ def _get_streams(self):
 
         # extract the steam ID from the URL
         steamid = self._url_re.match(self.url).group(1)
+        res = self.session.http.get(self.url)  # get the page to set some cookies
+        sessionid = res.cookies.get('sessionid')
 
         while streamdata is None or streamdata[u"success"] in ("waiting", "waiting_for_start"):
-            streamdata = self._get_broadcast_stream(steamid)
+            streamdata = self._get_broadcast_stream(steamid,
+                                                    sessionid=sessionid)
 
             if streamdata[u"success"] == "ready":
                 return DASHStream.parse_manifest(self.session, streamdata["url"])


Test patch: