internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: streamlink/streamlink

Issue:
Less violent way of closing player when stream ends
Currently streamlink uses SIGKILL to close the player when a stream ends. This prevents the player from doing its own cleanup. For example, mpv leaves DPMS/screensaver disabled because of this. I know there is --player-no-close option, but that has an unwanted side-effect of not closing the player immediately in some situations.

I suggest fixing it by using SIGTERM instead:
```diff
diff -bur streamlink-0.1.0-orig/src/streamlink_cli/output.py streamlink-0.1.0/src/streamlink_cli/output.py
--- streamlink-0.1.0-orig/src/streamlink_cli/output.py  2016-11-21 21:56:29.000000000 +0200
+++ streamlink-0.1.0/src/streamlink_cli/output.py       2016-12-08 22:08:23.000000000 +0200
@@ -161,7 +161,7 @@
 
         if self.kill:
             with ignored(Exception):
-                self.player.kill()
+                self.player.terminate()
         self.player.wait()
 
     def _write(self, data):
```


Discussion:
Could check to see that the player has terminated after a short while, and possibly kill it after a timeout? 
@beardypig This sounds like a more reasonable solution.
Sending `SIGTERM` doesn't guarantee that the player will shutdown. (eg. see VLC and the `--play-and-exit` parameter)
Something like this, with a 5 second time out to kill it... maybe there is a nicer way though. 
```diff
diff --git a/src/streamlink_cli/output.py b/src/streamlink_cli/output.py
index 7488f99..7f36c5f 100644
--- a/src/streamlink_cli/output.py
+++ b/src/streamlink_cli/output.py
@@ -161,7 +162,15 @@ class PlayerOutput(Output):

         if self.kill:
             with ignored(Exception):
-                self.player.kill()
+                self.player.terminate()
+                if not is_win32:
+                    t, timeout = 0.0, 5.0
+                    while not self.player.poll() and t < timeout:
+                        sleep(0.5)
+                        t += 0.5
+                    if not self.player.returncode:
+                        self.player.kill()
```


Resolving patch:
diff --git a/src/streamlink_cli/output.py b/src/streamlink_cli/output.py
--- a/src/streamlink_cli/output.py
+++ b/src/streamlink_cli/output.py
@@ -67,6 +67,8 @@ def _write(self, data):
 
 
 class PlayerOutput(Output):
+    PLAYER_TERMINATE_TIMEOUT = 10.0
+
     def __init__(self, cmd, args=DEFAULT_PLAYER_ARGUMENTS, filename=None, quiet=True, kill=True, call=False, http=False,
                  namedpipe=None):
         super(PlayerOutput, self).__init__()
@@ -160,7 +162,15 @@ def _close(self):
 
         if self.kill:
             with ignored(Exception):
-                self.player.kill()
+                self.player.terminate()
+                if not is_win32:
+                    t, timeout = 0.0, self.PLAYER_TERMINATE_TIMEOUT
+                    while not self.player.poll() and t < timeout:
+                        sleep(0.5)
+                        t += 0.5
+
+                    if not self.player.returncode:
+                        self.player.kill()
         self.player.wait()
 
     def _write(self, data):


Test patch:
Repository: streamlink/streamlink

Issue:
error: unknown locale: UTF-8
### Checklist

- [x] This is a bug report.

### Description
When I run streamlink, and see this error
```
[cli][info] Found matching plugin twitch for URL twitch.tv/dota2ruhub
error: unknown locale: UTF-8
```
Fixed after adding .bash_profile/.zshrc
```
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
```

### Reproduction steps / Stream URLs to test

1. Install latest streamlink 0.3.1
2. run streamlink

### Environment details (operating system, python version, etc.)

MacOS, Python 2.7.11, system lang eng


Discussion:

Resolving patch:
diff --git a/src/streamlink/utils/l10n.py b/src/streamlink/utils/l10n.py
--- a/src/streamlink/utils/l10n.py
+++ b/src/streamlink/utils/l10n.py
@@ -117,7 +117,10 @@ def language_code(self):
     @language_code.setter
     def language_code(self, language_code):
         if language_code is None:
-            language_code, _ = locale.getdefaultlocale()
+            try:
+                language_code, _ = locale.getdefaultlocale()
+            except ValueError:
+                language_code = None
             if language_code is None or language_code == "C":
                 # cannot be determined
                 language_code = DEFAULT_LANGUAGE_CODE


Test patch:
Repository: streamlink/streamlink

Issue:
0.3.2 Release
Closes #562 


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -46,7 +46,7 @@
 sys_path.insert(0, srcdir)
 
 setup(name="streamlink",
-      version="0.3.1",
+      version="0.3.2",
       description="Streamlink is command-line utility that extracts streams "
                   "from various services and pipes them into a video player of "
                   "choice.",
diff --git a/src/streamlink/__init__.py b/src/streamlink/__init__.py
--- a/src/streamlink/__init__.py
+++ b/src/streamlink/__init__.py
@@ -12,7 +12,7 @@
 
 
 __title__ = "streamlink"
-__version__ = "0.3.1"
+__version__ = "0.3.2"
 __license__ = "Simplified BSD"
 __author__ = "Streamlink"
 __copyright__ = "Copyright 2016 Streamlink"


Test patch:
Repository: streamlink/streamlink

Issue:
Address already in use
Is there a way to unbind the port once streamlink is stopped? It takes sometimes up to a minute before the port can be used by some other process.


Discussion:
How are you exiting Streamlink?
CTRL+c or kill -9 PID
I take it you mean when using the http player option? 
Correct.

Resolving patch:
diff --git a/src/streamlink_cli/utils/http_server.py b/src/streamlink_cli/utils/http_server.py
--- a/src/streamlink_cli/utils/http_server.py
+++ b/src/streamlink_cli/utils/http_server.py
@@ -23,6 +23,7 @@ def send_error(self, code, message):
 class HTTPServer(object):
     def __init__(self):
         self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         self.conn = self.host = self.port = None
         self.bound = False
 
@@ -111,4 +112,5 @@ def close(self, client_only=False):
             self.conn.close()
 
         if not client_only:
+            self.socket.shutdown(2)
             self.socket.close()


Test patch:
Repository: streamlink/streamlink

Issue:
When I close VLC I get this error
### Checklist

- [x] This is a bug report.
- [ ] This is a plugin request.
- [ ] This is a feature request.
- [ ] I used the search function to find already opened/closed issues or pull requests.

### Description
```
[cli][info] Player closed
[cli][info] Stream ended
[cli][info] Closing currently open stream...
Traceback (most recent call last):
  File "d:\Program Files (x86)\Streamlink\bin\streamlink-script.py", line 12, in
 <module>
    main()
  File "d:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\main.py", line 952
, in main
    handle_url()
  File "d:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\main.py", line 499
, in handle_url
    handle_stream(plugin, streams, stream_name)
  File "d:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\main.py", line 381
, in handle_stream
    success = output_stream(stream)
  File "d:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\main.py", line 270
, in output_stream
    read_stream(stream_fd, output, prebuffer)
  File "contextlib.py", line 159, in __exit__
  File "d:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\output.py", line 2
8, in close
    self._close()
  File "d:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\output.py", line 1
58, in _close
    self.http.close()
  File "d:\Program Files (x86)\Streamlink\pkgs\streamlink_cli\utils\http_server.
py", line 115, in close
    self.socket.shutdown(2)
OSError: [WinError 10057] A request to send or receive data was disallowed becau
se the socket is not connected and (when sending on a datagram socket using a se
ndto call) no address was supplied
```

### Expected / Actual behavior

Not to happen

### Reproduction steps / Stream URLs to test

just close vlc when watching a twitch stream

### Environment details (operating system, python version, etc.)

Win7 64bit latest nightly

### Comments, logs, screenshots, etc.
@gravyboat @beardypig do you get this error too?



Discussion:

Resolving patch:
diff --git a/src/streamlink_cli/utils/http_server.py b/src/streamlink_cli/utils/http_server.py
--- a/src/streamlink_cli/utils/http_server.py
+++ b/src/streamlink_cli/utils/http_server.py
@@ -112,5 +112,8 @@ def close(self, client_only=False):
             self.conn.close()
 
         if not client_only:
-            self.socket.shutdown(2)
+            try:
+                self.socket.shutdown(2)
+            except OSError:
+                pass
             self.socket.close()


Test patch:
Repository: streamlink/streamlink

Issue:
Plugin request: Aliez.tv to Aliez.me
### Checklist

- [x] This is a bug report.
- [x] This is a plugin request.
- [ ] This is a feature request.
- [ ] I used the search function to find already opened/closed issues or pull requests.

### Description

Aliez.tv does not exist anymore there is Aliez.me which is actually the same streaming site.

### Reproduction steps / Stream URLs to test

1. http://aliez.me/live/fkpev212/ link im trying to open in player


Discussion:
Maybe it would be interesting to include in plugin aliez.* instead of aliez.me. That way once they change domain name it won't be required to adapt plugin. 

Resolving patch:
diff --git a/src/streamlink/plugins/alieztv.py b/src/streamlink/plugins/aliez.py
similarity index 94%
rename from src/streamlink/plugins/alieztv.py
rename to src/streamlink/plugins/aliez.py
--- a/src/streamlink/plugins/alieztv.py
+++ b/src/streamlink/plugins/aliez.py
@@ -8,13 +8,8 @@
 from streamlink.stream import HTTPStream, RTMPStream
 
 _url_re = re.compile(r"""
-    http(s)?://(\w+\.)?aliez.tv
-    (?:
-        /live/[^/]+
-    )?
-    (?:
-        /video/\d+/[^/]+
-    )?
+    https?://(\w+\.)?aliez.\w+/
+    (?:live/[^/]+|video/\d+/[^/]+)
 """, re.VERBOSE)
 _file_re = re.compile(r"\"?file\"?:\s+['\"]([^'\"]+)['\"]")
 _swf_url_re = re.compile(r"swfobject.embedSWF\(\"([^\"]+)\",")


Test patch:
Repository: streamlink/streamlink

Issue:
bigoweb.co / bigolive.tv plugin no longer works


----

### Checklist

- [x] This is a bug report.
- [ ] This is a plugin request.
- [ ] This is a feature request.
- [ ] I used the search function to find already opened/closed issues or pull requests.

### Description
error: No plugin can handle bigoweb.co addressess as of 10 minutes ago

### Expected / Actual behavior

10 minutes ago it worked fine and now it gives an error.
...

### Reproduction steps / Stream URLs to test

1. ...http://www.bigoweb.co/ (any stream)
2. ...
3. ...

### Environment details (operating system, python version, etc.)

...

### Comments, logs, screenshots, etc.

...



Discussion:

Resolving patch:
diff --git a/src/streamlink/plugins/bigo.py b/src/streamlink/plugins/bigo.py
--- a/src/streamlink/plugins/bigo.py
+++ b/src/streamlink/plugins/bigo.py
@@ -47,7 +47,7 @@ def close(self):
 
 
 class Bigo(Plugin):
-    _url_re = re.compile(r"https?://(live.bigo.tv/\d+|bigoweb.co/show/\d+)")
+    _url_re = re.compile(r"https?://(?:www\.)?(bigo\.tv/\d+|bigoweb\.co/show/\d+)")
     _flashvars_re = flashvars = re.compile(
         r'''^\s*(?<!<!--)<param.*value="tmp=(\d+)&channel=(\d+)&srv=(\d+\.\d+\.\d+\.\d+)&port=(\d+)"''',
         re.M)


Test patch:
diff --git a/tests/test_plugin_bigo.py b/tests/test_plugin_bigo.py
new file mode 100644
--- /dev/null
+++ b/tests/test_plugin_bigo.py
@@ -0,0 +1,31 @@
+import unittest
+
+from streamlink.plugins.bigo import Bigo
+
+
+class TestPluginBongacams(unittest.TestCase):
+    def test_can_handle_url(self):
+        # Correct urls
+        self.assertTrue(Bigo.can_handle_url("http://www.bigoweb.co/show/00000000"))
+        self.assertTrue(Bigo.can_handle_url("https://www.bigoweb.co/show/00000000"))
+        self.assertTrue(Bigo.can_handle_url("http://bigoweb.co/show/00000000"))
+        self.assertTrue(Bigo.can_handle_url("https://bigoweb.co/show/00000000"))
+        self.assertTrue(Bigo.can_handle_url("http://bigo.tv/00000000"))
+        self.assertTrue(Bigo.can_handle_url("https://bigo.tv/00000000"))
+        self.assertTrue(Bigo.can_handle_url("https://www.bigo.tv/00000000"))
+        self.assertTrue(Bigo.can_handle_url("http://www.bigo.tv/00000000"))
+
+        # Old URLs don't work anymore
+        self.assertFalse(Bigo.can_handle_url("http://live.bigo.tv/00000000"))
+        self.assertFalse(Bigo.can_handle_url("https://live.bigo.tv/00000000"))
+
+        # Wrong URL structure
+        self.assertFalse(Bigo.can_handle_url("ftp://www.bigo.tv/00000000"))
+        self.assertFalse(Bigo.can_handle_url("https://www.bigo.tv/show/00000000"))
+        self.assertFalse(Bigo.can_handle_url("http://www.bigo.tv/show/00000000"))
+        self.assertFalse(Bigo.can_handle_url("http://bigo.tv/show/00000000"))
+        self.assertFalse(Bigo.can_handle_url("https://bigo.tv/show/00000000"))
+
+
+if __name__ == "__main__":
+    unittest.main()
Repository: streamlink/streamlink

Issue:
[cli][error] Could not open stream doesn't exit with code 1, but with 0
### Checklist

- [x] This is a bug report.
- [ ] This is a plugin request.
- [ ] This is a feature request.
- [x] I used the search function to find already opened/closed issues or pull requests.

### Description

When streamlink finds a stream, but can not (for whatever reason) open it, the exit code is 0 (success) and not 1 (error).

### Expected / Actual behavior

streamlink should exit with exit code 1 (error).

### Reproduction steps / Stream URLs to test

1. streamlink streamurl best
2. wait for it to open the stream
3. wait for error that it can not open the stream
4. wait for it to exit
5. echo $?
0

### Environment details (operating system, python version, etc.)

Linux, Python 3.6

### Comments, logs, screenshots, etc.

```bash
# streamlink hlsvariant://example/*.m3u8 best 
[cli][info] Found matching plugin stream for URL hlsvariant://example/*.m3u8
[cli][info] Available streams: 240p (worst), 480p (best)
[cli][info] Opening stream: 480p (hls)
[cli][error] Could not open stream: Unable to open URL: http://example/*.m3u8 (404 Client Error: Not Found for url: http://example/*.m3u8)
```
```bash
# echo $?
0
```




Discussion:

Resolving patch:
diff --git a/src/streamlink_cli/main.py b/src/streamlink_cli/main.py
--- a/src/streamlink_cli/main.py
+++ b/src/streamlink_cli/main.py
@@ -244,14 +244,17 @@ def output_stream(stream):
     """Open stream, create output and finally write the stream to output."""
     global output
 
+    success_open = False
     for i in range(args.retry_open):
         try:
             stream_fd, prebuffer = open_stream(stream)
+            success_open = True
             break
         except StreamError as err:
-            console.logger.error("{0}", err)
-    else:
-        return
+            console.logger.error("Try {0}/{1}: Could not open stream {2} ({3})", i+1, args.retry_open, stream, err)
+
+    if not success_open:
+        console.exit("Could not open stream {0}, tried {1} times, exiting", stream, args.retry_open)
 
     output = create_output()
 
@@ -307,14 +310,14 @@ def read_stream(stream, output, prebuffer, chunk_size=8192):
                 elif is_http and err.errno in ACCEPTABLE_ERRNO:
                     console.logger.info("HTTP connection closed")
                 else:
-                    console.logger.error("Error when writing to output: {0}", err)
+                    console.exit("Error when writing to output: {0}, exiting", err)
 
                 break
     except IOError as err:
-        console.logger.error("Error when reading from stream: {0}", err)
-
-    stream.close()
-    console.logger.info("Stream ended")
+        console.exit("Error when reading from stream: {0}, exiting", err)
+    finally:
+        stream.close()
+        console.logger.info("Stream ended")
 
 
 def handle_stream(plugin, streams, stream_name):


Test patch:
Repository: streamlink/streamlink

Issue:
Add already-created facebook plugin
### Checklist

- [ ] This is a bug report.
- [x] This is a feature request.
- [ ] This is a plugin (improvement) request.
- [ ] I have read the contribution guidelines.

### Description
Add an already-created plugin for facebook videos (non-Dash, 360p quality). A link can be found in #226, the original creator left if there and allowed anybody to work on it and use it. Since we have no way of viewing facebook videos, I think this would be a very good addition for the upcoming 0.6 version. 


Discussion:

Resolving patch:
diff --git a/src/streamlink/plugins/facebook.py b/src/streamlink/plugins/facebook.py
new file mode 100644
--- /dev/null
+++ b/src/streamlink/plugins/facebook.py
@@ -0,0 +1,24 @@
+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+)")
+
+
+class Facebook(Plugin):
+    @classmethod
+    def can_handle_url(cls, url):
+        return _url_re.match(url)
+
+    def _get_streams(self):
+        match = _url_re.match(self.url)
+        video = match.group("video_id")
+
+        playlist = _playlist_url.format(video)
+
+        return HLSStream.parse_variant_playlist(self.session, playlist)
+
+__plugin__ = Facebook


Test patch:
diff --git a/tests/test_plugin_facebook.py b/tests/test_plugin_facebook.py
new file mode 100644
--- /dev/null
+++ b/tests/test_plugin_facebook.py
@@ -0,0 +1,14 @@
+import unittest
+
+from streamlink.plugins.facebook import Facebook
+
+
+class TestPluginFacebook(unittest.TestCase):
+    def test_can_handle_url(self):
+        # should match
+        self.assertTrue(Facebook.can_handle_url("https://www.facebook.com/nos/videos/1725546430794241/"))
+        self.assertTrue(Facebook.can_handle_url("https://www.facebook.com/nytfood/videos/1485091228202006/"))
+        self.assertTrue(Facebook.can_handle_url("https://www.facebook.com/SporTurkTR/videos/798553173631138/"))
+
+        # shouldn't match
+        self.assertFalse(Facebook.can_handle_url("https://www.facebook.com"))
Repository: streamlink/streamlink

Issue:
Plugin request TVN.bg
### Checklist

- [ ] This is a bug report.
- [ ] This is a feature request.
- [x] This is a plugin (improvement) request.
- [ ] I have read the contribution guidelines.

### Description
A simple plugin to open the stream available at http://tvn.bg/live/


Discussion:

Resolving patch:
diff --git a/src/streamlink/plugins/tvnbg.py b/src/streamlink/plugins/tvnbg.py
new file mode 100644
--- /dev/null
+++ b/src/streamlink/plugins/tvnbg.py
@@ -0,0 +1,38 @@
+import re
+
+from streamlink.plugin import Plugin
+from streamlink.plugin.api import http
+from streamlink.compat import urljoin
+from streamlink.stream import HLSStream
+
+
+class TVNBG(Plugin):
+    url_re = re.compile(r"https?://(?:live\.)?tvn\.bg/(?:live)?")
+    iframe_re = re.compile(r'<iframe.*?src="([^"]+)".*?></iframe>')
+    src_re = re.compile(r'<source.*?src="([^"]+)".*?/>')
+
+
+    @classmethod
+    def can_handle_url(cls, url):
+        return cls.url_re.match(url) is not None
+
+    def _get_streams(self):
+        base_url = self.url
+        res = http.get(self.url)
+
+        # Search for the iframe in the page
+        iframe_m = self.iframe_re.search(res.text)
+        if iframe_m:
+            # If the iframe is found, load the embedded page
+            base_url = iframe_m.group(1)
+            res = http.get(iframe_m.group(1))
+
+        # Search the page (original or embedded) for the stream URL
+        src_m = self.src_re.search(res.text)
+        if src_m:
+            stream_url = urljoin(base_url, src_m.group(1))
+            # There is no variant playlist, only a plain HLS Stream
+            yield "live", HLSStream(self.session, stream_url)
+
+
+__plugin__ = TVNBG


Test patch:
Repository: streamlink/streamlink

Issue:
Plugin request for NEW SmashCast TV (merger of Azubu and Hitbox)
This week finally came the result of the merger between Azubu and Hitbox.
The new [Smashcast TV.](https://www.smashcast.tv/)
Now, we need a plugin for this new platform. :)

Thanks to all the Streamlink developers.


Discussion:
the old hitbox plugin still works, you just need change the current smashcast.tv link to hitbox.tv link, for example: from "https://www.smashcast.tv/aravingloon" to "https://www.hitbox.tv/aravingloon"
It's true, I had not tried it, it really works.
So I think it's easy to create a new plugin, basically swap the url from hitbox to smashcast in the plugin.
I'll try to change that.
DONE! 👍 
[smashcast.zip](https://github.com/streamlink/streamlink/files/988560/smashcast.zip)


Resolving patch:
diff --git a/src/streamlink/plugins/hitbox.py b/src/streamlink/plugins/hitbox.py
--- a/src/streamlink/plugins/hitbox.py
+++ b/src/streamlink/plugins/hitbox.py
@@ -8,16 +8,16 @@
 from streamlink.stream import HLSStream, HTTPStream, RTMPStream
 from streamlink.utils import absolute_url
 
-HLS_PLAYLIST_BASE = "http://www.hitbox.tv{0}"
-LIVE_API = "http://www.hitbox.tv/api/media/live/{0}?showHidden=true"
-PLAYER_API = "http://www.hitbox.tv/api/player/config/{0}/{1}?embed=false&showHidden=true"
+HLS_PLAYLIST_BASE = "http://www.smashcast.tv{0}"
+LIVE_API = "http://www.smashcast.tv/api/media/live/{0}?showHidden=true"
+PLAYER_API = "http://www.smashcast.tv/api/player/config/{0}/{1}?embed=false&showHidden=true"
 SWF_BASE = "http://edge.vie.hitbox.tv/static/player/flowplayer/"
 SWF_URL = SWF_BASE + "flowplayer.commercial-3.2.16.swf"
-VOD_BASE_URL = "http://www.hitbox.tv/"
+VOD_BASE_URL = "http://www.smashcast.tv/"
 
 _quality_re = re.compile(r"(\d+p)$")
 _url_re = re.compile(r"""
-    http(s)?://(www\.)?hitbox.tv
+    http(s)?://(www\.)?(hitbox|smashcast).tv
     /(?P<channel>[^/]+)
     (?:
         /(?P<media_id>[^/]+)
@@ -76,7 +76,7 @@
 
 class Hitbox(Plugin):
     @classmethod
-    def can_handle_url(self, url):
+    def can_handle_url(cls, url):
         return _url_re.match(url)
 
     def _get_quality(self, label):


Test patch: