Repository: streamlink/streamlink

Issue:
raiplay.it
<!--
Thanks for reporting an issue!
USE THE TEMPLATE. Otherwise your issue may be rejected.

This template should only be used if your issue doesn't match the other more specific ones.

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 issues:
https://github.com/streamlink/streamlink/issues?q=is%3Aissue

Please see the text preview to avoid unnecessary formatting errors.
-->


## Issue

<!-- Replace [ ] with [x] in order to check the box -->
- [ ] This is not a bug report, feature request, or plugin issue/request.
- [ ] I have read the contribution guidelines.


### Description

<!-- Explain the issue as thoroughly as you can. -->


### Expected / Actual behavior

<!-- What do you expect to happen, and what is actually happening? -->


### 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. -->

https://www.raiplay.it/dirette/rai2
2. ...
3. ...


### Logs

<!--
TEXT LOG OUTPUT IS OPTIONAL for generic issues!
However, depending on the issue, log output can be useful for the developers to understand the problem. It also includes information about your platform. If you don't intend to include log output, please at least provide these platform details.
Thanks!

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.
-->

```
~$ streamlink   --loglevel debug https://www.raiplay.it/dirette/rai2   best --player  ffplay
[cli][debug] OS:         Linux-5.4.0-42-generic-x86_64-with-glibc2.29
[cli][debug] Python:     3.8.2
[cli][debug] Streamlink: 1.5.0
[cli][debug] Requests(2.22.0), Socks(1.6.7), Websocket(0.53.0)
[cli][info] Found matching plugin raiplay for URL https://www.raiplay.it/dirette/rai2
[plugin.raiplay][debug] Found channel: rai2
error: No playable streams found on this URL: https://www.raiplay.it/dirette/rai2
~$ 
```


### Additional comments, screenshots, etc.

```
:~$ streamlink   --version
streamlink 1.5.0
:~
```

same in windows 10


[Love Streamlink? Please consider supporting our collective. Thanks!](https://opencollective.com/streamlink/donate)



Discussion:
It's not a live stream, it's just VODs.
> It's not a live stream, it's just VODs.



> It's not a live stream, it's just VODs.

I'm sorry You are wrong.  Please enter in  a  browser "https://www.raiplay.it/dirette/rai2" and You will see that you reach live stream just clicking on play botton ( the URL field remain unchanged !  "https://www.raiplay.it/dirette/rai2"
 I'm sorry You are wrong. Please enter in a browser "
https://www.raiplay.it/dirette/rai2" and You will see that you reach live
stream just clicking on play botton ( the URL field remain unchanged ! "
https://www.raiplay.it/dirette/rai2".
Just for example:
in web browser address:
"https://www.raiplay.it/dirette/rai2"
... stream playing
using video download helper ... copy address  ... insert user agent

then:

ffplay -user_agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0)
Gecko/20100101 Firefox/80.0"  -i "
https://raidue1-live.akamaized.net/hls/live/598310/raidue1/raidue1/rai2_2400/exp=1599217615~acl=%2fhls%2flive%2f598310%2fraidue1%2f*!%2fhls%2flive%2f598310-b%2fraidue1%2f*!%2f*.key~data=hdntl~hmac=49b0cd0797a4ba799cfb290649c38f6a8fe88c4614224c41008a905217bc2549/chunklist.m3u8?aka_me_session_id=AAAAAAAAAADPH1JfAAAAAJw6HTo7gjvcyNGzLfZMeLFLSx9amXBd+hR0pzbTjDi0l8hGOdkbTy8RvHNoxvp1mhViuL6SMRPt"


play LIVE stream ....

bye for now





On Thu, Sep 3, 2020 at 1:37 AM Forrest <notifications@github.com> wrote:

> Closed #3143 <https://github.com/streamlink/streamlink/issues/3143>.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/streamlink/streamlink/issues/3143#event-3722210300>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AIAGSI42E3SDGVLU3SR4K3DSD3JMXANCNFSM4QTMFHTA>
> .
>

I can't access the video stream itself because it's geo-restricted to Italy. When I visited the URL before, as well as now and did a translation on the title and description it's just a "live" stream of pre-recorded content, and in this case a movie from 2006. That's basically just a bunch of VODs pushed in to a live stream and I don't believe it counts. Please show me a link to live content that is occurring now, not pre-recorded content.
@gravyboat, try: https://www.raiplay.it/dirette/rainews24 for an unrestricted channel.  It appears there are URL params on the playlist, but not the individual chunklists:
```
streamlink hls://https://rainews1-live.akamaized.net/hls/live/598326/rainews1/rainews1/rainews_1200/chunklist.m3u8 live
[cli][info] Found matching plugin hls for URL hls://https://rainews1-live.akamaized.net/hls/live/598326/rainews1/rainews1/rainews_1200/chunklist.m3u8
[cli][info] Available streams: live (worst, best)
[cli][info] Opening stream: live (hls)
[cli][info] Starting player: mpv
[cli][info] Player closed
[cli][info] Stream ended
[cli][info] Closing currently open stream...
```

Reopening, since there are a couple of live streams (news channels).

@writetome1 
Plugin requests should be as detailed as possible with enough information, so please don't wonder if your thread gets closed if it doesn't meet the requirements. Take a look here:
https://github.com/streamlink/streamlink/blob/master/CONTRIBUTING.md#plugin-requests

----

> try: [raiplay.it/dirette/rainews24](https://www.raiplay.it/dirette/rainews24) for an unrestricted channel

This one does indeed work with a non-italian IP, but everything else is geo-restricted. It looks like it doesn't make much of a difference though, as you can still make the necessary requests to get to the HLS playlist.

1. Find the DOM element with the `data-video-json` attribute and replace the path segment of the input URL with its value
   `https://www.raiplay.it/dirette/rai1` => `https://www.raiplay.it/dirette/rai1.json`
2. Request the video JSON URL, parse it as JSON and find the `video.content_url` value. Optionally replace the HTTP scheme with HTTPS.
   `https://mediapolis.rai.it/relinker/relinkerServlet.htm?cont=2606803`
3. That relinker URL will either redirect to the live stream's HLS playlist, or a mp4 file if it's geo-blocked.

Didn't realize and didn't check that we already had a plugin for this site. Relabeling...

Resolving patch:
diff --git a/src/streamlink/plugins/raiplay.py b/src/streamlink/plugins/raiplay.py
--- a/src/streamlink/plugins/raiplay.py
+++ b/src/streamlink/plugins/raiplay.py
@@ -1,35 +1,54 @@
-from __future__ import print_function
+import logging
 import re
 
+from streamlink.compat import urlparse, urlunparse
 from streamlink.plugin import Plugin
-from streamlink.plugin.api import useragents
 from streamlink.plugin.api import validate
 from streamlink.stream import HLSStream
+from streamlink.utils import parse_json
+
+
+log = logging.getLogger(__name__)
 
 
 class RaiPlay(Plugin):
-    url_re = re.compile(r"https?://(?:www\.)?raiplay\.it/dirette/(\w+)/?")
-    stream_re = re.compile(r"data-video-url.*?=.*?\"([^\"]+)\"")
-    stream_schema = validate.Schema(
-        validate.all(
-            validate.transform(stream_re.search),
-            validate.any(
-                None,
-                validate.all(validate.get(1), validate.url())
-            )
-        )
+    _re_url = re.compile(r"https?://(?:www\.)?raiplay\.it/dirette/(\w+)/?")
+
+    _re_data = re.compile(r"data-video-json\s*=\s*\"([^\"]+)\"")
+    _schema_data = validate.Schema(
+        validate.transform(_re_data.search),
+        validate.any(None, validate.get(1))
+    )
+    _schema_json = validate.Schema(
+        validate.transform(parse_json),
+        validate.get("video"),
+        validate.get("content_url"),
+        validate.url()
     )
 
     @classmethod
     def can_handle_url(cls, url):
-        return cls.url_re.match(url) is not None
+        return cls._re_url.match(url) is not None
 
     def _get_streams(self):
-        channel = self.url_re.match(self.url).group(1)
-        self.logger.debug("Found channel: {0}", channel)
-        stream_url = self.session.http.get(self.url, schema=self.stream_schema)
-        if stream_url:
-            return HLSStream.parse_variant_playlist(self.session, stream_url, headers={"User-Agent": useragents.CHROME})
+        json_url = self.session.http.get(self.url, schema=self._schema_data)
+        if not json_url:
+            return
+
+        json_url = urlunparse(urlparse(self.url)._replace(path=json_url))
+        log.debug("Found JSON URL: {0}".format(json_url))
+
+        stream_url = self.session.http.get(json_url, schema=self._schema_json)
+        log.debug("Found stream URL: {0}".format(stream_url))
+
+        res = self.session.http.request("HEAD", stream_url)
+        # status code will be 200 even if geo-blocked, so check the returned content-type
+        if not res or not res.headers or res.headers["Content-Type"] == "video/mp4":
+            log.error("Geo-restricted content")
+            return
+
+        for stream in HLSStream.parse_variant_playlist(self.session, stream_url).items():
+            yield stream
 
 
 __plugin__ = RaiPlay


Test patch: