Repository: streamlink/streamlink

Issue:
YouTube live streams not detected from channel page
<!--
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 -->
- [x] This is a bug report.
- [x] I have read the contribution guidelines.


### Description

As of yesterday, Streamlink doesn't detect a YouTube live stream when you put in channel home page as parameter. Tested with several YT channels. A friend of mine started experiencing same issue yesterday as well. Inputting direct video link works, but detecting that video from the channel page is now broken.


### Expected / Actual behavior

<!-- What do you expect to happen, and what is actually happening? -->
Streamlink should find an ID of the live stream and start downloading/streaming it.
Instead no video is found at all.

### 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. Find a YT channel that has a live stream
2. Input: *streamlink.exe https://www.youtube.com/channel/xxxxxxx* (other parameters don't seem to matter)
3. Output: *error: Could not find a video on this page*


### 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.

Don't post screenshots of the log output and instead copy the text from your terminal application.
-->
Channel ID removed:
```
streamlink --loglevel debug https://www.youtube.com/channel/xxxxx
[cli][debug] OS:         Windows 7
[cli][debug] Python:     3.6.6
[cli][debug] Streamlink: 1.6.0
[cli][debug] Requests(2.24.0), Socks(1.7.1), Websocket(0.57.0)
[cli][info] Found matching plugin youtube for URL https://www.youtube.com/channel/xxxxx
error: Could not find a video on this page
```


### Additional comments, etc.



[Love Streamlink? Please consider supporting our collective. Thanks!](https://opencollective.com/streamlink/donate)



Discussion:

It works for TRT World.

```
C:\>streamlink.exe --loglevel debug --http-no-ssl-verify --player=ffplay.exe "https://www.youtube.com/embed/live_stream?channel=UC7fWeaHhqgM4Ry-RMpM2YYw"
[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.6.6
[cli][debug] Streamlink: 1.6.0
[cli][debug] Requests(2.24.0), Socks(1.7.1), Websocket(0.57.0)
[cli][info] Found matching plugin youtube for URL https://www.youtube.com/embed/live_stream?channel=UC7fWeaHhqgM4Ry-RMpM2YYw
[plugin.youtube][debug] Re-directing to canonical URL: https://www.youtube.com/watch?v=CV5Fooi8YJA
[plugin.youtube][debug] Video ID from URL
[plugin.youtube][debug] Using video ID: CV5Fooi8YJA
[plugin.youtube][debug] get_video_info - 1: Found data
[plugin.youtube][debug] This video is live.
[utils.l10n][debug] Language code: en_GB
Available streams: 144p (worst), 240p, 360p, 480p, 720p, 1080p (best)
```
```
C:\>streamlink.exe --loglevel debug --http-no-ssl-verify --player=ffplay.exe "https://www.youtube.com/embed/live_stream?channel=UC7fWeaHhqgM4Ry-RMpM2YYw" 480p
[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.6.6
[cli][debug] Streamlink: 1.6.0
[cli][debug] Requests(2.24.0), Socks(1.7.1), Websocket(0.57.0)
[cli][info] Found matching plugin youtube for URL https://www.youtube.com/embed/live_stream?channel=UC7fWeaHhqgM4Ry-RMpM2YYw
[plugin.youtube][debug] Re-directing to canonical URL: https://www.youtube.com/watch?v=CV5Fooi8YJA
[plugin.youtube][debug] Video ID from URL
[plugin.youtube][debug] Using video ID: CV5Fooi8YJA
[plugin.youtube][debug] get_video_info - 1: Found data
[plugin.youtube][debug] This video is live.
[utils.l10n][debug] Language code: en_GB
[cli][info] Available streams: 144p (worst), 240p, 360p, 480p, 720p, 1080p (best)
[cli][info] Opening stream: 480p (hls)
[stream.hls][debug] Reloading playlist
[stream.hls][debug] First Sequence: 5216; Last Sequence: 5221
[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 5219; End Sequence: None
[stream.hls][debug] Adding segment 5219 to queue
[cli][debug] Pre-buffering 8192 bytes
[stream.hls][debug] Adding segment 5220 to queue
[stream.hls][debug] Adding segment 5221 to queue
[stream.hls][debug] Download of segment 5219 complete
[cli][info] Starting player: ffplay.exe
[cli.output][debug] Opening subprocess: ffplay.exe -
[cli][debug] Writing stream to output
[stream.hls][debug] Download of segment 5220 complete
[stream.hls][debug] Download of segment 5221 complete
[stream.hls][debug] Reloading playlist
[stream.hls][debug] Adding segment 5222 to queue
[stream.hls][debug] Adding segment 5223 to queue
[stream.hls][debug] Download of segment 5222 complete
[stream.hls][debug] Download of segment 5223 complete
```

@johnthecracker
I can confirm it works when you use this type of url: *https://www.youtube.com/embed/live_stream?channel=xxxxx*
I've been using *https://www.youtube.com/channel/xxxxxxx* for weeks and it worked until yesterday.
I too am having this issue. I posted about it in the r/streamlink reddit. I am going to try the embed url, and downgrading to an earlier version

Resolving patch:
diff --git a/src/streamlink/plugins/youtube.py b/src/streamlink/plugins/youtube.py
--- a/src/streamlink/plugins/youtube.py
+++ b/src/streamlink/plugins/youtube.py
@@ -255,6 +255,10 @@ def _find_video_id(self, url):
                     log.debug("Video ID from currentVideoEndpoint")
                     return video_id
             for x in search_dict(data, 'videoRenderer'):
+                if x.get("viewCountText", {}).get("runs"):
+                    if x.get("videoId"):
+                        log.debug("Video ID from videoRenderer (live)")
+                        return x["videoId"]
                 for bstyle in search_dict(x.get("badges", {}), "style"):
                     if bstyle == "BADGE_STYLE_TYPE_LIVE_NOW":
                         if x.get("videoId"):
@@ -266,8 +270,12 @@ def _find_video_id(self, url):
                 if link.attributes.get("rel") == "canonical":
                     canon_link = link.attributes.get("href")
                     if canon_link != url:
-                        log.debug("Re-directing to canonical URL: {0}".format(canon_link))
-                        return self._find_video_id(canon_link)
+                        if canon_link.endswith("v=live_stream"):
+                            log.debug("The video is not available")
+                            break
+                        else:
+                            log.debug("Re-directing to canonical URL: {0}".format(canon_link))
+                            return self._find_video_id(canon_link)
 
         raise PluginError("Could not find a video on this page")
 


Test patch: