nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: streamlink/streamlink
Pull request #5395 (2023-06-22 20:25:53)

cli.argparser: allow disabling session options
`streamlink_cli.argparser` should be able to set session options which default to `True` to `False`. Fix that by checking whether the argument dest on the argparse namespace is not `None` (aka set).

Currently, there are no session options which default to `True`.

----

Required for being able to add `--webbrowser=false` with respective default value of `True` on the Streamlink session.


Patch:
diff --git a/src/streamlink_cli/argparser.py b/src/streamlink_cli/argparser.py
index d63c8b21..8e624a19 100644
--- a/src/streamlink_cli/argparser.py
+++ b/src/streamlink_cli/argparser.py
@@ -1329,7 +1329,7 @@ _ARGUMENT_TO_SESSIONOPTION: List[Tuple[str, str, Optional[Callable[[Any], Any]]]
 def setup_session_options(session: Streamlink, args: argparse.Namespace):
     for arg, option, mapper in _ARGUMENT_TO_SESSIONOPTION:
         value = getattr(args, arg)
-        if value:
+        if value is not None:
             if mapper is not None:
                 value = mapper(value)
             session.set_option(option, value)


Test patch:
diff --git a/tests/cli/test_argparser.py b/tests/cli/test_argparser.py
index a36710fc..5586ce1b 100644
--- a/tests/cli/test_argparser.py
+++ b/tests/cli/test_argparser.py
@@ -59,6 +59,23 @@ def test_setup_session_options(parser: ArgumentParser, session: Streamlink, argv
     assert session.get_option(option) == expected
 
 
+@pytest.mark.parametrize(("default", "new", "expected"), [
+    pytest.param(False, None, False, id="Default False, unset"),
+    pytest.param(True, None, True, id="Default True, unset"),
+    pytest.param(False, False, False, id="Default False, set to False"),
+    pytest.param(False, True, True, id="Default False, set to True"),
+    pytest.param(True, False, False, id="Default True, set to False"),
+    pytest.param(True, True, True, id="Default True, set to True"),
+])
+def test_setup_session_options_override(monkeypatch: pytest.MonkeyPatch, session: Streamlink, default, new, expected):
+    arg = "NON_EXISTING_ARGPARSER_ARGUMENT"
+    key = "NON-EXISTING-SESSION-OPTION-KEY"
+    monkeypatch.setattr("streamlink_cli.argparser._ARGUMENT_TO_SESSIONOPTION", [(arg, key, None)])
+    session.set_option(key, default)
+    setup_session_options(session, Namespace(**{arg: new}))
+    assert session.get_option(key) == expected
+
+
 def test_cli_main_setup_session_options(monkeypatch: pytest.MonkeyPatch, parser: ArgumentParser, session: Streamlink):
     class StopTest(Exception):
         pass
Repository: streamlink/streamlink
Pull request #3160 (2020-09-09 16:22:38)

plugins.tvplayer: update regex and tests for /uk/ URLs
https://github.com/streamlink/streamlink/issues/3145#issuecomment-689650652

codecov[bot]: # [Codecov](https://codecov.io/gh/streamlink/streamlink/pull/3160?src=pr&el=h1) Report
> Merging [#3160](https://codecov.io/gh/streamlink/streamlink/pull/3160?src=pr&el=desc) into [master](https://codecov.io/gh/streamlink/streamlink/commit/c30a59f9a72947cd1a4129d250274149fb1cd847?el=desc) will **not change** coverage.
> The diff coverage is `100.00%`.


```diff
@@           Coverage Diff           @@
##           master    #3160   +/-   ##
=======================================
  Coverage   52.66%   52.66%           
=======================================
  Files         244      244           
  Lines       15636    15636           
=======================================
  Hits         8235     8235           
  Misses       7401     7401           
```

gravyboat: Looks good, thanks.

Patch:
diff --git a/src/streamlink/plugins/tvplayer.py b/src/streamlink/plugins/tvplayer.py
index 8a783f70..6b244acb 100644
--- a/src/streamlink/plugins/tvplayer.py
+++ b/src/streamlink/plugins/tvplayer.py
@@ -17,7 +17,7 @@ class TVPlayer(Plugin):
     update_url = "https://tvplayer.com/account/update-detail"
     dummy_postcode = "SE1 9LT"  # location of ITV HQ in London
 
-    url_re = re.compile(r"https?://(?:www.)?tvplayer.com/(:?watch/?|watch/(.+)?)")
+    url_re = re.compile(r"https?://(?:www.)?tvplayer.com/(:?uk/)?(:?watch/?|watch/(.+)?)")
     stream_attrs_re = re.compile(r'data-player-(expiry|key|token|uvid)\s*=\s*"(.*?)"', re.S)
     login_token_re = re.compile(r'input.*?name="_token".*?value="(\w+)"')
     stream_schema = validate.Schema({


Test patch:
diff --git a/tests/plugins/test_tvplayer.py b/tests/plugins/test_tvplayer.py
index dcbb404c..340c802d 100644
--- a/tests/plugins/test_tvplayer.py
+++ b/tests/plugins/test_tvplayer.py
@@ -19,10 +19,15 @@ class TestPluginTVPlayer(unittest.TestCase):
         self.assertTrue(TVPlayer.can_handle_url("http://www.tvplayer.com/watch/"))
         self.assertTrue(TVPlayer.can_handle_url("http://tvplayer.com/watch"))
         self.assertTrue(TVPlayer.can_handle_url("http://www.tvplayer.com/watch"))
+        self.assertTrue(TVPlayer.can_handle_url("http://www.tvplayer.com/uk/watch"))
         self.assertTrue(TVPlayer.can_handle_url("http://tvplayer.com/watch/dave"))
+        self.assertTrue(TVPlayer.can_handle_url("http://tvplayer.com/uk/watch/dave"))
         self.assertTrue(TVPlayer.can_handle_url("http://www.tvplayer.com/watch/itv"))
+        self.assertTrue(TVPlayer.can_handle_url("http://www.tvplayer.com/uk/watch/itv"))
         self.assertTrue(TVPlayer.can_handle_url("https://www.tvplayer.com/watch/itv"))
+        self.assertTrue(TVPlayer.can_handle_url("https://www.tvplayer.com/uk/watch/itv"))
         self.assertTrue(TVPlayer.can_handle_url("https://tvplayer.com/watch/itv"))
+        self.assertTrue(TVPlayer.can_handle_url("https://tvplayer.com/uk/watch/itv"))
 
         # shouldn't match
         self.assertFalse(TVPlayer.can_handle_url("http://www.tvplayer.com/"))
Repository: streamlink/streamlink
Pull request #3960 (2021-08-28 23:34:45)

plugins.pluto: fix URL match for 2 letter language codes
fixes #3959


bastimeyer: Please add tests for the updated URL matcher.
mkbloke: Oops, I forgot about updating the tests... should be OK now, cheers.

Patch:
diff --git a/src/streamlink/plugins/pluto.py b/src/streamlink/plugins/pluto.py
index 08769a62..00a563b9 100644
--- a/src/streamlink/plugins/pluto.py
+++ b/src/streamlink/plugins/pluto.py
@@ -12,7 +12,7 @@ log = logging.getLogger(__name__)
 
 
 @pluginmatcher(re.compile(r'''
-    https?://(?:www\.)?pluto\.tv/(?:
+    https?://(?:www\.)?pluto\.tv/(?:\w{2}/)?(?:
         live-tv/(?P<slug_live>[^/?]+)/?$
         |
         on-demand/series/(?P<slug_series>[^/]+)/season/\d+/episode/(?P<slug_episode>[^/]+)$


Test patch:
diff --git a/tests/plugins/test_pluto.py b/tests/plugins/test_pluto.py
index 56a1a25b..8f622be7 100644
--- a/tests/plugins/test_pluto.py
+++ b/tests/plugins/test_pluto.py
@@ -15,6 +15,15 @@ class TestPluginCanHandleUrlPluto(PluginCanHandleUrl):
         'http://pluto.tv/on-demand/series/fear-factor-usa-(lf)/season/5/episode/underwater-safe-bob-car-ramp-2004-5-3',
         'https://www.pluto.tv/on-demand/movies/dr.-no-1963-1-1',
         'http://pluto.tv/on-demand/movies/the-last-dragon-(1985)-1-1',
+        'http://www.pluto.tv/lc/live-tv/channel-lineup',
+        'http://pluto.tv/lc/live-tv/channel',
+        'http://pluto.tv/lc/live-tv/channel/',
+        'https://pluto.tv/lc/live-tv/red-bull-tv-2',
+        'https://pluto.tv/lc/live-tv/4k-tv',
+        'http://www.pluto.tv/lc/on-demand/series/leverage/season/1/episode/the-nigerian-job-2009-1-1',
+        'http://pluto.tv/lc/on-demand/series/fear-factor-usa-(lf)/season/5/episode/underwater-safe-bob-car-ramp-2004-5-3',
+        'https://www.pluto.tv/lc/on-demand/movies/dr.-no-1963-1-1',
+        'http://pluto.tv/lc/on-demand/movies/the-last-dragon-(1985)-1-1',
     ]
 
     should_not_match = [
@@ -28,4 +37,14 @@ class TestPluginCanHandleUrlPluto(PluginCanHandleUrl):
         'http://pluto.tv/on-demand/series/dr.-no-1963-1-1',
         'http://pluto.tv/on-demand/movies/leverage/season/1/episode/the-nigerian-job-2009-1-1',
         'http://pluto.tv/on-demand/fear-factor-usa-(lf)/season/5/episode/underwater-safe-bob-car-ramp-2004-5-3',
+        'https://fake.pluto.tv/lc/live-tv/hello',
+        'http://www.pluto.tv/lc/live-tv/channel-lineup/extra',
+        'https://www.pluto.tv/lc/live-tv',
+        'https://pluto.tv/lc/live-tv',
+        'https://www.pluto.com/lc/live-tv/swag',
+        'http://pluto.tv/lc/movies/dr.-no-1963-1-1',
+        'http://pluto.tv/lc/on-demand/movies/dr.-no-1/963-1-1',
+        'http://pluto.tv/lc/on-demand/series/dr.-no-1963-1-1',
+        'http://pluto.tv/lc/on-demand/movies/leverage/season/1/episode/the-nigerian-job-2009-1-1',
+        'http://pluto.tv/lc/on-demand/fear-factor-usa-(lf)/season/5/episode/underwater-safe-bob-car-ramp-2004-5-3',
     ]