Repository: streamlink/streamlink

Issue:
lrt plugin: no playable streams after website redesign
<!--
Thanks for reporting a plugin issue!
USE THE TEMPLATE. Otherwise your plugin issue 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 plugin issues:
https://github.com/streamlink/streamlink/issues?q=is%3Aissue+label%3A%22plugin+issue%22

Please see the text preview to avoid unnecessary formatting errors.
-->


## Plugin Issue

<!-- Replace [ ] with [x] in order to check the box -->
- [x] This is a plugin issue and I have read the contribution guidelines.


### Description

<!-- Explain the plugin issue as thoroughly as you can. -->
After a site redesign in March, lrt.lt streams stopped working, returning a 'no playable streams...' error. The livestream pages are under the same URLs: 

TV:

- https://www.lrt.lt/mediateka/tiesiogiai/lrt-televizija

- https://www.lrt.lt/mediateka/tiesiogiai/lrt-plius

- https://www.lrt.lt/mediateka/tiesiogiai/lrt-lituanica



### 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. streamlink https://www.lrt.lt/mediateka/tiesiogiai/lrt-televizija
2. other streams mentioned above 


### Log output

<!--
TEXT LOG OUTPUT IS REQUIRED for a plugin issue!
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.
-->

```
PS C:\Users\SK> streamlink --loglevel debug https://www.lrt.lt/mediateka/tiesiogiai/lrt-televizija
[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.6.6
[cli][debug] Streamlink: 1.1.1
[cli][debug] Requests(2.21.0), Socks(1.6.7), Websocket(0.56.0)
[cli][info] Found matching plugin lrt for URL https://www.lrt.lt/mediateka/tiesiogiai/lrt-televizija
[plugin.lrt][debug] No match for sources regex
error: No playable streams found on this URL: https://www.lrt.lt/mediateka/tiesiogiai/lrt-televizija
```


### Additional comments, screenshots, etc.
Don't know if this is of any help, but:

The address of the playlist.m3u8 file loaded by the web browser looks like this (the _tokenhash_ and _tokenendtime_ parts are different each time):
`https://srautas.lrt.lt/lrt_televizija/smil:lrt_televizija.smil/playlist.m3u8?tokenhash=8NHAZ1a_gi6z434ehau8XSJ6QcsOZch16Bw3YRM-KM9e5jtWgjvmfk1vQMsjmYZqGc83WfnqY0ORKPwLEowC4w==&tokenendtime=1555866780`

_tokenendtime_ is an Unix timestamp corresponding to 35 minutes after load time

and the contents of the playlist look like this:
```
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=3500000,RESOLUTION=1920x1080
chunklist_b3500000_tkdG9rZW5oYXNoPThOSEFaMWFfZ2k2ejQzNGVoYXU4WFNKNlFjc09aY2gxNkJ3M1lSTS1LTTllNWp0V2dqdm1mazF2UU1zam1ZWnFHYzgzV2ZucVkwT1JLUHdMRW93QzR3PT0mdG9rZW5lbmR0aW1lPTE1NTU4NjY3ODA=.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1500000,RESOLUTION=1280x720
chunklist_b1500000_tkdG9rZW5oYXNoPThOSEFaMWFfZ2k2ejQzNGVoYXU4WFNKNlFjc09aY2gxNkJ3M1lSTS1LTTllNWp0V2dqdm1mazF2UU1zam1ZWnFHYzgzV2ZucVkwT1JLUHdMRW93QzR3PT0mdG9rZW5lbmR0aW1lPTE1NTU4NjY3ODA=.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=400000,RESOLUTION=640x360
chunklist_b400000_tkdG9rZW5oYXNoPThOSEFaMWFfZ2k2ejQzNGVoYXU4WFNKNlFjc09aY2gxNkJ3M1lSTS1LTTllNWp0V2dqdm1mazF2UU1zam1ZWnFHYzgzV2ZucVkwT1JLUHdMRW93QzR3PT0mdG9rZW5lbmR0aW1lPTE1NTU4NjY3ODA=.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=300000,RESOLUTION=426x240
chunklist_b300000_tkdG9rZW5oYXNoPThOSEFaMWFfZ2k2ejQzNGVoYXU4WFNKNlFjc09aY2gxNkJ3M1lSTS1LTTllNWp0V2dqdm1mazF2UU1zam1ZWnFHYzgzV2ZucVkwT1JLUHdMRW93QzR3PT0mdG9rZW5lbmR0aW1lPTE1NTU4NjY3ODA=.m3u8

```


[Love Streamlink? Please consider supporting our collective. Thanks!](https://opencollective.com/streamlink/donate)


Discussion:

Patch:
diff --git a/src/streamlink/plugins/lrt.py b/src/streamlink/plugins/lrt.py
index e6838be0..3045aee2 100644
--- 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 @@ class LRT(Plugin):
 
     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
index c7d4476c..8360e561 100644
--- a/tests/plugins/test_lrt.py
+++ b/tests/plugins/test_lrt.py
@@ -6,19 +6,22 @@ from streamlink.plugins.lrt import LRT
 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)