Repository: streamlink/streamlink

Issue:
--twitch-disable-reruns error
<!--
Thanks for reporting a bug!
USE THE TEMPLATE. Otherwise your bug report 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 bug reports:
https://github.com/streamlink/streamlink/issues?q=is%3Aissue+label%3A%22bug%22

Please see the text preview to avoid unnecessary formatting errors.
-->


## Bug Report

<!-- Replace [ ] with [x] in order to check the box -->
- [x] This is a bug report and I have read the contribution guidelines.


### Description

<!-- Explain the bug as thoroughly as you can. Don't leave out information which is necessary for us to reproduce and debug this issue. -->
Reruns disabling seems to be working but this error accurs in cmd
![cmd_ZJg3To8rUo](https://user-images.githubusercontent.com/51099894/73242786-f5af9680-41b6-11ea-973e-aaf14b37f472.png)

### Expected / Actual behavior

<!-- What do you expect to happen, and what is actually happening? -->


### Reproduction steps / Explicit stream URLs to test

<!-- 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. ...
2. ...
3. ...


### Log output

<!--
TEXT LOG OUTPUT IS REQUIRED for a bug report!
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.
-->

```
REPLACE THIS TEXT WITH THE LOG OUTPUT
```


### Additional comments, screenshots, etc.



[Love Streamlink? Please consider supporting our collective. Thanks!](https://opencollective.com/streamlink/donate)


Discussion:

Patch:
diff --git a/src/streamlink/plugins/twitch.py b/src/streamlink/plugins/twitch.py
index 80a6ad4e..969709d2 100644
--- a/src/streamlink/plugins/twitch.py
+++ b/src/streamlink/plugins/twitch.py
@@ -99,8 +99,11 @@ _user_schema = validate.Schema(
 _stream_schema = validate.Schema(
     {
         "stream": validate.any(None, {
-            "stream_type": validate.any("live", "rerun"),
-            "broadcast_platform": validate.any("live", "rerun")
+            "stream_type": validate.text,
+            "broadcast_platform": validate.text,
+            "channel": validate.any(None, {
+                "broadcaster_software": validate.text
+            })
         })
     },
     validate.get("stream")
@@ -709,7 +712,11 @@ class Twitch(Plugin):
     def _check_for_rerun(self):
         stream = self.api.streams(self.channel_id, schema=_stream_schema)
 
-        return stream and (stream["stream_type"] == "rerun" or stream["broadcast_platform"] == "rerun")
+        return stream and (
+            stream["stream_type"] != "live"
+            or stream["broadcast_platform"] == "rerun"
+            or stream["channel"] and stream["channel"]["broadcaster_software"] == "watch_party_rerun"
+        )
 
     def _get_hls_streams(self, stream_type="live"):
         log.debug("Getting {0} HLS streams for {1}".format(stream_type, self.channel))


Test patch:
diff --git a/tests/plugins/test_twitch.py b/tests/plugins/test_twitch.py
index 849d2533..3c74d2db 100644
--- a/tests/plugins/test_twitch.py
+++ b/tests/plugins/test_twitch.py
@@ -208,8 +208,11 @@ class TestTwitchReruns(unittest.TestCase):
             mocked_stream = mock.get(
                 "https://api.twitch.tv/kraken/streams/1234.json",
                 json={"stream": None} if params.pop("offline", False) else {"stream": {
-                    "stream_type": params.pop("stream_type", "rerun"),
-                    "broadcast_platform": params.pop("broadcast_platform", "rerun")
+                    "stream_type": params.pop("stream_type", "live"),
+                    "broadcast_platform": params.pop("broadcast_platform", "live"),
+                    "channel": {
+                        "broadcaster_software": params.pop("broadcaster_software", "")
+                    }
                 }}
             )
 
@@ -220,13 +223,21 @@ class TestTwitchReruns(unittest.TestCase):
             try:
                 streams = plugin.streams()
             except TestTwitchReruns.StopError:
-                streams = None
+                streams = True
                 pass
 
             return streams, mocked_users, mocked_stream, mocked[0]
 
-    def test_disable_reruns(self, mock_log):
-        streams, api_users, api_stream, access_token = self.start(stream_type="rerun", broadcast_platform="rerun")
+    def test_disable_reruns_live(self, mock_log):
+        streams, api_users, api_stream, access_token = self.start()
+        self.assertTrue(api_users.called_once)
+        self.assertTrue(api_stream.called_once)
+        self.assertTrue(access_token.called_once)
+        self.assertTrue(streams)
+        self.assertNotIn(self.log_call, mock_log.info.call_args_list)
+
+    def test_disable_reruns_not_live(self, mock_log):
+        streams, api_users, api_stream, access_token = self.start(stream_type="rerun")
         self.assertTrue(api_users.called_once)
         self.assertTrue(api_stream.called_once)
         self.assertFalse(access_token.called)
@@ -249,20 +260,20 @@ class TestTwitchReruns(unittest.TestCase):
         self.assertDictEqual(streams, {})
         self.assertIn(self.log_call, mock_log.info.call_args_list)
 
-    def test_disable_reruns_live(self, mock_log):
-        streams, api_users, api_stream, access_token = self.start(stream_type="live", broadcast_platform="live")
+    def test_disable_reruns_broadcaster_software(self, mock_log):
+        streams, api_users, api_stream, access_token = self.start(broadcaster_software="watch_party_rerun")
         self.assertTrue(api_users.called_once)
         self.assertTrue(api_stream.called_once)
         self.assertTrue(access_token.called_once)
-        self.assertIsNone(streams)
-        self.assertNotIn(self.log_call, mock_log.info.call_args_list)
+        self.assertDictEqual(streams, {})
+        self.assertIn(self.log_call, mock_log.info.call_args_list)
 
     def test_disable_reruns_offline(self, mock_log):
         streams, api_users, api_stream, access_token = self.start(offline=True)
         self.assertTrue(api_users.called_once)
         self.assertTrue(api_stream.called_once)
         self.assertTrue(access_token.called_once)
-        self.assertIsNone(streams)
+        self.assertTrue(streams)
         self.assertNotIn(self.log_call, mock_log.info.call_args_list)
 
     def test_enable_reruns(self, mock_log):
@@ -270,5 +281,5 @@ class TestTwitchReruns(unittest.TestCase):
         self.assertFalse(api_users.called)
         self.assertFalse(api_stream.called)
         self.assertTrue(access_token.called_once)
-        self.assertIsNone(streams)
+        self.assertTrue(streams)
         self.assertNotIn(self.log_call, mock_log.info.call_args_list)