How to find ID for stream for a broadcast ID or vice-versa (YouTube Data API)?

Viewed 105

I would like to find the streams associated with a broadcast with 'ready' status. I've been looking at the broadcasts using this call, and don't see either the streams or a key I can use to correlate them:

curl -H "Authorization: Bearer XXX_AUTH_TOKEN_XXX" "https://www.googleapis.com/youtube/v3/liveBroadcasts?part=status&broadcastStatus=all&maxResults=100"

This produces:

{
  "kind": "youtube#liveBroadcastListResponse",
  "etag": "LgRz6pjADsE_wIIphSY6n_M3LDE",
  "pageInfo": {
    "totalResults": 39,
    "resultsPerPage": 50
  },
  "items": [
    {
      "kind": "youtube#liveBroadcast",
      "etag": "DC7GxUyFsLEyJorVsv7gl7yBxYY",
      "id": "BRsOTPMIb_s",
      "status": {
        "lifeCycleStatus": "ready",
        "privacyStatus": "public",
        "recordingStatus": "notRecording",
        "madeForKids": false,
        "selfDeclaredMadeForKids": false
      }
    },
     ...
 ]
}

Similarly, I would like to know if a stream in the 'inactive' state is associated with an existing broadcast, so I can add it to a new one if needed.

curl -H "Authorization: Bearer XXX_AUTH_TOKEN_XXX" "https://www.googleapis.com/youtube/v3/liveStreams?part=snippet,cdn,contentDetails,status&mine=true&maxResults=100"

This produces:

{
  "kind": "youtube#liveStream",
  "etag": "i3qny6yeyCwtlZkNHB5lgMLGF1I",
  "id": "EFWoMyGEmXWkp7dWPLYdWA1615776388366728",
  "snippet": {
    "publishedAt": "2021-03-15T02:46:29Z",
    "channelId": "XXXXXXXXXXXXXXXXXXXXXXXX",
    "title": "Default stream key",
    "description": "Description for default stream key",
    "isDefaultStream": false
  },
  "cdn": {
    "ingestionType": "rtmp",
    "ingestionInfo": {
      "streamName": "XXXX-XXXX-XXXX-XXXX-XXXX",
      "ingestionAddress": "rtmp://a.rtmp.youtube.com/live2",
      "backupIngestionAddress": "rtmp://b.rtmp.youtube.com/live2?backup=1",
      "rtmpsIngestionAddress": "rtmps://a.rtmps.youtube.com/live2",
      "rtmpsBackupIngestionAddress": "rtmps://b.rtmps.youtube.com/live2?backup=1"
    },
    "resolution": "variable",
    "frameRate": "variable"
  },
  "status": {
    "streamStatus": "inactive",
    "healthStatus": {
      "status": "noData"
    }
  },
  "contentDetails": {
    "closedCaptionsIngestionUrl": "http://upload.youtube.com/closedcaption?cid=sdgs-zk2j-grt3-x9jj-d7ks",
    "isReusable": true
  }
}

For example, the broadcast above apparently is related to the stream above since they were created by YouTube Studio, as the default ones when manually starting a stream. However, it is unclear from the two JSON snippets what connects them.

Any ideas on how to relate them is greatly appreciated!

1 Answers

My mistake, adding contentDetails to part fixed this.

curl -H "Authorization: Bearer XXXX_AUTH_TOKEN_XXXX" "https://www.googleapis.com/youtube/v3/liveBroadcasts?part=status,contentDetails&broadcastStatus=all&maxResults=100"

Details:

    {
      "kind": "youtube#liveBroadcast",
      "etag": "m1O2kGwzs7czUSuB5-hvdWu-Qwc",
      "id": "GYnbNz_baGk",
      "status": {
        "lifeCycleStatus": "complete",
        "privacyStatus": "public",
        "recordingStatus": "recorded",
        "madeForKids": true,
        "selfDeclaredMadeForKids": true
      },
      "contentDetails": {
        "boundStreamId": "EFWoMyGEmXWkp7dWPLYdWA1615776388366728",
        "boundStreamLastUpdateTimeMs": "2021-05-17T19:53:36Z",
        "monitorStream": {
          "enableMonitorStream": true,
          "broadcastStreamDelayMs": 0,
          "embedHtml": "\u003ciframe width=\"425\" height=\"344\" src=\"https://www.youtube.com/embed/XXXXXXXXX?autoplay=1&livemonitor=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen\u003e\u003c/iframe\u003e"
        },
        "enableEmbed": false,
        "enableDvr": true,
        "enableContentEncryption": false,
        "startWithSlate": false,
        "recordFromStart": true,
        "enableClosedCaptions": false,
        "closedCaptionsType": "closedCaptionsDisabled",
        "enableLowLatency": false,
        "latencyPreference": "ultraLow",
        "projection": "rectangular",
        "enableAutoStart": true,
        "enableAutoStop": true
      }
    }
Related