Youtube API v3 - Get "Live Now" rtmp and streamkey

Youtube now has a Live Streaming section that allows users to broadcast their own live sessions. There are two options in this section of "Live Streaming": "Live Now [Beta]" and "Events".

  • Live Now is a quick and easy way to start a streaming session by simply pointing your video encoder to the specified RTMP Url and Stream Key URLs. It will automatically detect the embedded media and begin broadcasting.

  • Events are almost the same, but with settings in advance, although it will not start automatically for broadcasting, and you need to manually configure everything manually.

I know that the Youtube API allows you to retrieve the URL of the reception and event stream, so you can broadcast for this purpose, but for this you also need to manage many other steps manually (for example, publish a stream, associate broadcasts with streams, check status, start , stop, etc ..). On the other hand, "Live Now" does everything automatically.

Question: How can I get information about swallowing "Live Now" (rtmp url and streamkey) from the Youtube v3 API?

+5
source share
4 answers

"Live Now", API "Live Now" "Events". API , , API.

liveBroadcast liveStream, liveBroadcasts.bind, liveStream, status.streamStatus.

+2

livebroadcasts.list broadcastType, "persistent".

livestreams.list boundstreamid.

+10

"Live Now" rtmp streamkey

       $broadcastsResponse = $youtube->liveBroadcasts->listLiveBroadcasts(
            'id,snippet,contentDetails',
            array(
                'broadcastType' => 'persistent',
                'mine' => 'true',
            ));

        $boundStreamId = $broadcastsResponse['items']['0']['contentDetails']['boundStreamId'];

        $streamsResponse = $youtube->liveStreams->listLiveStreams('id,snippet,cdn', array(
//            'mine' => 'true',
            'id' => $boundStreamId
        ));

        print_r($streamsResponse);
+2
 // Keep client_id,client_secret and redirect_uri the client_secrets.json
 UserCredential credential;
 string BoundStreamId = string.Empty;
 string StreamKey=string.Empty;
 using (var stream = new FileStream("client_secrets.json", FileMode.Open, 
   FileAccess.Read))
            {
                credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
                new[] { YouTubeService.Scope.Youtube,YouTubeService.Scope.YoutubeReadonly},
                "user",
                CancellationToken.None,
                new FileDataStore(this.GetType().ToString())
             );
            }
if (credential != null)
            {
                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "MyApp" // your app name
                });
 LiveBroadcastsResource.ListRequest lbRequest = youtubeService.LiveBroadcasts.List("id,snippet,contentDetails,status");
                lbRequest.BroadcastType = LiveBroadcastsResource.ListRequest.BroadcastTypeEnum.Persistent;
                lbRequest.MaxResults = 10;

                lbRequest.Mine = true;

                var bcResponse = await lbRequest.ExecuteAsync();

                IEnumerator<LiveBroadcast> iLB = bcResponse.Items.GetEnumerator();
                while (iLB.MoveNext() && string.IsNullOrEmpty(liveChatId))
                {
                  BoundStreamId = livebroadcast.ContentDetails.BoundStreamId;
                }
 LiveStreamsResource.ListRequest lsRequest =
                                   youtubeService.LiveStreams.List("id,snippet,cdn,status");
                lsRequest.MaxResults = 50;                    
                lsRequest.Id = BoundStreamId;

                var srResponse = await lsRequest.ExecuteAsync();

                IEnumerator<LiveStream> iLS = srResponse.Items.GetEnumerator();
 if (srResponse != null)
                {
                 foreach(LiveStream lvStream in srResponse.Items)
                    {
                       StreamKey= lvStream.Cdn.IngestionInfo.StreamName);
                    }
                }
          }
0
source

Source: https://habr.com/ru/post/1616499/


All Articles