Repository: streamlink/streamlink

Issue:
Update lrt plugin to cover updated page
Hello, this piece of edit should resolve  streamlink#2440
Btw first commit to other's projects.

P.S streamlink should also cover VOD part or not?


Discussion:
# [Codecov](https://codecov.io/gh/streamlink/streamlink/pull/2466?src=pr&el=h1) Report
> Merging [#2466](https://codecov.io/gh/streamlink/streamlink/pull/2466?src=pr&el=desc) into [master](https://codecov.io/gh/streamlink/streamlink/commit/bd24ab87037d0749170b9f14cc45868866078954?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `0%`.


```diff
@@            Coverage Diff            @@
##           master   #2466      +/-   ##
=========================================
+ Coverage    52.6%   52.6%   +<.01%     
=========================================
  Files         239     239              
  Lines       15059   15057       -2     
=========================================
- Hits         7922    7921       -1     
+ Misses       7137    7136       -1
```

> [plugin.lrt][debug] No match for sources regex

does not fix it

---

using the video_id is probably a better way to fix this

Resolving patch:
diff --git a/src/streamlink/plugins/lrt.py b/src/streamlink/plugins/lrt.py
--- a/src/streamlink/plugins/lrt.py
+++ b/src/streamlink/plugins/lrt.py
@@ -1,20 +1,16 @@
 import logging
 import re
-from functools import partial
 
 from streamlink.plugin import Plugin
 from streamlink.stream import HLSStream
-from streamlink.utils import parse_json
-from streamlink.compat import urlparse
 
 log = logging.getLogger(__name__)
 
 
 class LRT(Plugin):
-    _url_re = re.compile(r"https?://(?:www\.)?lrt.lt/mediateka/.")
-    _source_re = re.compile(r'sources\s*:\s*(\[{.*?}\]),', re.DOTALL | re.IGNORECASE)
-    js_to_json = partial(re.compile(r'(?!<")(\w+)\s*:\s*(["\']|\d?\.?\d+,|true|false|\[|{)').sub, r'"\1":\2')
-
+    _url_re = re.compile(r"https?://(?:www\.)?lrt.lt/mediateka/tiesiogiai/.")
+    _video_id_re = re.compile(r"""var\svideo_id\s*=\s*["'](?P<video_id>\w+)["']""")
+    API_URL = "https://www.lrt.lt/servisai/stream_url/live/get_live_url.php?channel={0}"
 
     @classmethod
     def can_handle_url(cls, url):
@@ -22,21 +18,16 @@ def can_handle_url(cls, url):
 
     def _get_streams(self):
         page = self.session.http.get(self.url)
-        m = self._source_re.search(page.text)
+        m = self._video_id_re.search(page.text)
         if m:
-            params = ""
-            data = m.group(1)
-            log.debug("Source data: {0}".format(data))
-            if "location.hash.substring" in data:
-                log.debug("Removing hash substring addition")
-                data = re.sub(r"\s*\+\s*location.hash.substring\(\d+\)", "", data)
-                params = urlparse(self.url).fragment
-            data = self.js_to_json(data)
-            for stream in parse_json(data):
-                for s in HLSStream.parse_variant_playlist(self.session, stream['file'], params=params).items():
-                    yield s
+            video_id = m.group("video_id")
+            data = self.session.http.get(self.API_URL.format(video_id)).json()
+            hls_url = data["response"]["data"]["content"]
+
+            for s in HLSStream.parse_variant_playlist(self.session, hls_url).items():
+                yield s
         else:
-            log.debug("No match for sources regex")
+            log.debug("No match for video_id regex")
 
 
 __plugin__ = LRT


Test patch:
diff --git a/tests/plugins/test_lrt.py b/tests/plugins/test_lrt.py
--- a/tests/plugins/test_lrt.py
+++ b/tests/plugins/test_lrt.py
@@ -6,19 +6,22 @@
 class TestPluginLRT(unittest.TestCase):
     def test_can_handle_url(self):
         should_match = [
+            "https://www.lrt.lt/mediateka/tiesiogiai/lrt-opus",
+            "https://www.lrt.lt/mediateka/tiesiogiai/lrt-klasika",
+            "https://www.lrt.lt/mediateka/tiesiogiai/lrt-radijas",
+            "https://www.lrt.lt/mediateka/tiesiogiai/lrt-lituanica",
+            "https://www.lrt.lt/mediateka/tiesiogiai/lrt-plius",
             "https://www.lrt.lt/mediateka/tiesiogiai/lrt-televizija",
-            "https://www.lrt.lt/mediateka/tiesiogiai/lrt-kultura",
-            "https://www.lrt.lt/mediateka/tiesiogiai/lrt-lituanica"
-            "https://www.lrt.lt/mediateka/irasas/1013694276/savanoriai-tures-galimybe-pamatyti-popieziu-is-arciau#wowzaplaystart=1511000&wowzaplayduration=168000"
         ]
         for url in should_match:
-            self.assertTrue(LRT.can_handle_url(url))
+            self.assertTrue(LRT.can_handle_url(url), url)
 
     def test_can_handle_url_negative(self):
         should_not_match = [
             "https://www.lrt.lt",
             "https://www.youtube.com",
+            "https://www.lrt.lt/mediateka/irasas/1013694276/savanoriai-tures-galimybe-pamatyti-popieziu-is-arciau",
 
         ]
         for url in should_not_match:
-            self.assertFalse(LRT.can_handle_url(url))
+            self.assertFalse(LRT.can_handle_url(url), url)