Repository: streamlink/streamlink
Pull request #1053 (2017-07-01 21:32:57)

Add support for hls streams in bigo
This is a workaround for issue #1031 since FLV streaming is broken

codecov[bot]: # [Codecov](https://codecov.io/gh/streamlink/streamlink/pull/1053?src=pr&el=h1) Report
> Merging [#1053](https://codecov.io/gh/streamlink/streamlink/pull/1053?src=pr&el=desc) into [master](https://codecov.io/gh/streamlink/streamlink/commit/527cef71f5089d1ca7ea1d40435c016a97baa893?src=pr&el=desc) will **decrease** coverage by `0.02%`.
> The diff coverage is `25%`.


```diff
@@            Coverage Diff             @@
##           master    #1053      +/-   ##
==========================================
- Coverage   42.44%   42.42%   -0.03%     
==========================================
  Files          94       94              
  Lines        7871     7878       +7     
==========================================
+ Hits         3341     3342       +1     
- Misses       4530     4536       +6
```

unnutricious: Addressed comments and also improved the url regex
bigotvuser: Although fully agree that improving the URL regex is being done at an opportune moment, could just the HLS changes be released for now so that it can be tested. It appears the change is regex would apply to only a minority of bigo tv URLs.
beardypig: Currently the tests are not passing, so this cannot be merged in its current state. 
bastimeyer: Since @unnutricious seems to be unavailable right now, someone could pull their changes, squash all the commits, add the needed fix and open a new PR with these two commits. This way, everyone will be credited for their work and the plugin gets fixed.

Patch:
diff --git a/src/streamlink/plugins/bigo.py b/src/streamlink/plugins/bigo.py
index 365d38cd..ed863fc1 100644
--- a/src/streamlink/plugins/bigo.py
+++ b/src/streamlink/plugins/bigo.py
@@ -4,8 +4,8 @@ import struct
 
 from streamlink import PluginError
 from streamlink.plugin import Plugin
-from streamlink.plugin.api import http
-from streamlink.stream import Stream
+from streamlink.plugin.api import http, useragents
+from streamlink.stream import Stream, HLSStream
 
 
 class BigoStream(Stream):
@@ -47,10 +47,13 @@ class BigoStream(Stream):
 
 
 class Bigo(Plugin):
-    _url_re = re.compile(r"https?://(?:www\.)?(bigo\.tv/\d+|bigoweb\.co/show/\d+)")
+    _url_re = re.compile(r"^https?://(www\.)?(bigo\.tv|bigoweb\.co/show)/[\w\d]+$")
     _flashvars_re = flashvars = re.compile(
         r'''^\s*(?<!<!--)<param.*value="tmp=(\d+)&channel=(\d+)&srv=(\d+\.\d+\.\d+\.\d+)&port=(\d+)"''',
         re.M)
+    _video_re = re.compile(
+        r'^\s*(?<!<!--)<source id="videoSrc" src="(http://.*\.m3u8)"',
+        re.M)
 
     @classmethod
     def can_handle_url(cls, url):
@@ -59,13 +62,13 @@ class Bigo(Plugin):
     def _get_streams(self):
         page = http.get(self.url,
                         allow_redirects=True,
-                        headers={"User-Agent": "Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0)"})
-        flashvars = self._flashvars_re.search(page.text)
-        if not flashvars:
+                        headers={"User-Agent": useragents.IPHONE_6})
+        videomatch = self._video_re.search(page.text)
+        if not videomatch:
             return
 
-        sid, uid, ip, port = flashvars.groups()
-        yield "live", BigoStream(self.session, sid, uid, ip, port)
+        videourl = videomatch.group(1)
+        yield "live", HLSStream(self.session, videourl)
 
 
 __plugin__ = Bigo


Test patch:
diff --git a/tests/test_plugin_bigo.py b/tests/test_plugin_bigo.py
index 99bd4e17..24df03b8 100644
--- a/tests/test_plugin_bigo.py
+++ b/tests/test_plugin_bigo.py
@@ -3,7 +3,7 @@ import unittest
 from streamlink.plugins.bigo import Bigo
 
 
-class TestPluginBongacams(unittest.TestCase):
+class TestPluginBigo(unittest.TestCase):
     def test_can_handle_url(self):
         # Correct urls
         self.assertTrue(Bigo.can_handle_url("http://www.bigoweb.co/show/00000000"))
@@ -14,6 +14,7 @@ class TestPluginBongacams(unittest.TestCase):
         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"))
+        self.assertTrue(Bigo.can_handle_url("http://www.bigo.tv/fancy1234"))
 
         # Old URLs don't work anymore
         self.assertFalse(Bigo.can_handle_url("http://live.bigo.tv/00000000"))