A small percentage of our users don't seem to have a default live broadcast on YouTube even though live streaming is enabled on their channel.
Here's the query I'm using:
youtube.liveBroadcasts
.list({
part: 'snippet,contentDetails,status',
mine: true,
broadcastType: 'persistent',
})
Here's a normal response:
{ kind: 'youtube#liveBroadcastListResponse',
etag: '"XI7nbFXulYBIpL0ayR_gDh3eu1k/tnMgqhFvImsLcGAkkJ86gMVeu7o"',
pageInfo: { totalResults: 0, resultsPerPage: 5 },
items:
[ { kind: 'youtube#liveBroadcast',
etag: '"XI7nbFXulYBIpL0ayR_gDh3eu1k/FqKww8uAZT-v7cY4LAc70S74LZE"',
id: 'jW9y9FCovHs',
snippet: [Object],
status: [Object],
contentDetails: [Object] } ] }
But for some channels, it returns an item with no data:
{ kind: 'youtube#liveBroadcastListResponse',
etag: '"XI7nbFXulYBIpL0ayR_gDh3eu1k/6A_Pgj2FJo4w0Hg6io_OE8jCrzY"',
pageInfo: { totalResults: 0, resultsPerPage: 5 },
items:
[ { kind: 'youtube#liveBroadcast',
etag: '"XI7nbFXulYBIpL0ayR_gDh3eu1k/vyGp6PvFo4RvsFtPoIWeCReyIC8"' } ] }
These users will often have other past live broadcast, but no default.
The snippet.isDefaultBroadcast section in the docs says that each channel with live streaming enabled should have a default broadcast. Any ideas? Is there something different about certain channels that would cause this?
You can read the documentation about how default broadcast work. It says that when a channel starts streaming video to its default stream, the video is visible on the channel's default broadcast. When the stream ends, YouTube converts the completed broadcast to a YouTube video and assigns the video a YouTube video ID. I think this will only modify by the owner of the channel.
Related
I want a way to get YouTube shorts for a specific channel from YouTube API. I looked every where and I couldn't find anything.
Currently I can get a playlist ID for all channel videos with this endpoint:
request = youtube.channels().list(
part="contentDetails",
id=id
)
I also tried these parameters:
request = youtube.channels().list(
part="snippet,contentDetails,statistics,brandingSettings",
id=id
)
So is there a way to get YouTube shorts from a specific channel from YouTube API or any other source if it's available.
One way of detecting if a YouTube video ID is a Short without even using the API is to try a HEAD HTTP request to the /shorts/ version of the URL and see if it redirects you.
https://www.youtube.com/shorts/hKwrn5-7FjQ is a Short and if you visit that URL, you'll get an HTTP status code of 200 and the URL won't change.
https://www.youtube.com/watch?v=B-s71n0dHUk is not a Short, and if you visit https://www.youtube.com/shorts/B-s71n0dHUk, you get a 303 redirect back to the original URL.
Keep in mind, that this behavior might change down the line, but it works as of May 2022.
It seems that once again YouTube Data API v3 doesn't provide a basic feature.
For checking if a given video is a short:
I would recommend you to use my open-source YouTube operational API. Indeed by requesting the JSON document https://yt.lemnoslife.com/videos?part=short&id=VIDEO_ID containing item["short"]["available"] boolean, your problem is solved.
Example of short id: ydPkyvWtmg4
For listing shorts of a channel:
I would recommend you to use my open-source YouTube operational API. Indeed by requesting the JSON document https://yt.lemnoslife.com/channels?part=shorts&id=CHANNEL_ID. The entry item["shorts"] contains the data you are looking for. Note that the pagination works as the one of YouTube Data API v3.
Example of result for channel UC5O114-PQNYkurlTg6hekZw:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UC5O114-PQNYkurlTg6hekZw",
"shorts": [
{
"videoId": "fP8nKVauFwc",
"title": "India: United Nations Counter Terrorism Committee Watch LIVE #shorts",
"thumbnails": [
{
"url": "https:\/\/i.ytimg.com\/vi\/fP8nKVauFwc\/hq720_2.jpg?sqp=-oaymwEYCNAFENAFSFryq4qpAwoIARUAAIhC0AEB&rs=AOn4CLCgJEYgv_msT5pkfWeEEN3VBt4wjg",
"width": 720,
"height": 720
}
],
"viewCount": 3700
},
...
],
"nextPageToken": "4qmFsgLlARIYVUM1TzExNC1QUU5Za3VybFRnNmhla1p3GsgBOGdhU0FScVBBVktNQVFxSEFRcGZRME00VVVGU2IyWnZaMWxqUTJob1ZsRjZWbEJOVkVVd1RGWkNVbFJzYkhKa1dFcHpWa2RqTW1GSFZuSlhibU5SUVZOSlVrTm5PSGhQYWtVeVRtcGplVTE2VlRST2FrVXdUbXBCY1VSUmIweFhWRUl5VGtab1dGSllSbGRNVmtVU0pEWXpOakJoTkRVNUxUQXdNREF0TWpKaE15MDRObUV6TFdRMFpqVTBOMlZqWVRSbFl4Z0I=,CgtuNjFmZlJlR0QxcyiVgICbBg=="
}
]
}
Below is a sample python code to send the HEAD HTTP request.
import requests
def is_short(vid):
url = 'https://www.youtube.com/shorts/' + vid
ret = requests.head(url)
if ret.status_code == 200:
return True
else: # whether 303 or other values, it's not short
return False
I don't know why but I don't get status code 303 whether it's a short or not with axios. So this is another way of checking if it's a short or not.
const isShort = async (videoId) => {
const url = "https://www.youtube.com/shorts/" + videoId
const res = await axios.head(url)
console.log(res.request.res.responseUrl)
// if it's a short it ends with "/shorts/videoId"
// if it's NOT a short it ends "/watch?=videoId"
}
Maybe axios automatically redirects?
You can use the new dimension called 'creatorContentType' from Youtube Analytics and Reports API.
// You can get IDs from PlaylistItems or Search API
const IDs = ["videoID1", "videoID2", "videoID3"];
// Get the analytics data of selected videos based on their IDs
const { data: analyticsData } = await youtubeAnalytics.reports.query({
ids: "channel==MINE",
startDate: "2019-01-01",
// Today's date
endDate: new Date().toISOString().split("T")[0],
metrics: "views",
dimensions: "video,creatorContentType",
filters: `video==${IDs.join(",")}`,
access_token,
});
It basically returns values listed below:
Value
Description
LIVE_STREAM
The viewed content was a YouTube live stream.
SHORTS
The viewed content was a YouTube Short.
STORY
The viewed content was a YouTube Story.
VIDEO_ON_DEMAND
The viewed content was a YouTube video that does not fall under one of the other dimension values.
UNSPECIFIED
The content type of the viewed content is unknown.
Notes:
Don't forget it returns values just for the videos uploaded after 01.01.2019.
Don't forget to add analytics scopes and enable Analytics and Reports API.
When you upload a video to YouTube you may get a Includes copyrighted content flag in the video manager. Then when you go and check the video you see a message under the "copyright" section:
You have x copyright claims on your video. and below this is a Details section displaying interesting information like:
"CONTENT","CLAIMANT","POLICY" and it shows the time region where this claimed content is located in the video. What i would like to know is if Youtube's or Google's API can give us this same information?
Try using Videos: list.
Send HTTP request using this format:
GET https://www.googleapis.com/youtube/v3/videos
If successful, this method returns a response body with this sample video resource:
"contentDetails": {
"licensedContent": boolean,
"regionRestriction": {
"allowed": [
string
],
"blocked": [
string
]
},
"status": {
"privacyStatus": string,
"publishAt": datetime,
"license": string,
"publicStatsViewable": boolean
}
I develop the mobile app with livestream feature and I need to get default livebroadcast with default livestream data.
When user didn't enable livestreams in his youtube account I show him message with link to https://www.youtube.com/live_streaming_signup .
After if user enabled livestreams in his youtube account I can't get default livebroadcast with broadcast type persistent.
My request url is: https://www.googleapis.com/youtube/v3/liveBroadcasts?part=contentDetails&mine=true&broadcastType=persistent&access_token=
My response is:
{
"kind": "youtube#liveBroadcastListResponse",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/5WQLBG6RLCbLPgwsAs3o13sBM98\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#liveBroadcast",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/vyGp6PvFo4RvsFtPoIWeCReyIC8\""
}
]
}
Only after go to live dashboard page stream now I can got default livebroadcast with broadcast type persistent and then got livestream by default livebroadcast boundStremId
Why? How I can get default livebroadcast and default livestream without go to livestream dashboard?
I tried your query, and just like you, I can get 200 response, but I can only get 1 result. So the alternative way that I used to get the live broadcast is by using the Search: list under the DATA API. Here, you can use the eventType=live to get the live broadcast video.
GET https://www.googleapis.com/youtube/v3/search?part=snippet&eventType=live&type=video&key={YOUR_API_KEY}
For the persistent broadcast, try to check this SO question if it can help you.
For more information check these related SO questions:
YouTube API live broadcast
How to get list of live video broadcasts using youtube api v3
I'm using OBS to stream my screen to Youtube Live.
While my stream is live I'm querying the liveBroadcasts/list endpoint to know if my broadcast is live.
part -> id, status
mine -> true
HTTP GET: GET https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2Cstatus&mine=true&key={YOUR_API_KEY}
The status dictionary returns something like this
even if my stream is live:
"status": {
"lifeCycleStatus": "complete",
"privacyStatus": "public",
"recordingStatus": "recording"
}
The value for the lifeCycleStatus I'm looking for is live but the API always returns complete
I don't want to use the search.list endpoint due to the delay.
Broadcast status can be queried for the specific video using below GET request:
GET https://www.googleapis.com/youtube/v3/videos?id=7OyvXCM63uQ&key=API_KEY&part=liveStreamingDetails,snippet
Response :
Snippet.liveBroadcastContent: "upcoming",
liveStreamingDetails: {
scheduledStartTime: "2016-06-19T18:47:04.000Z",
scheduledEndTime: "2016-06-19T19:17:04.000Z"
}
Via the Youtube API, how can I detect if a video Youtube is unavailable (ex : https://www.youtube.com/watch?v=5nRZlcB2jPY) ?
Thanks
This is also partially possible without API. Let's say you want to see if the following video is available:
https://www.youtube.com/watch?v=esDJPiGu5x0
The ID of the video is shown as the GET parameter v. Use this one to request the following thumbnail:
https://img.youtube.com/vi/esDJPiGu5x0/0.jpg
If the content of the response has a length of 0 and/or the http response code by youtube.com is 404, then the video is not available anymore.
You would make an API call for the video status.
https://www.googleapis.com/youtube/v3/videos?id=VIDEOID&part=status&key=APIKEY
Then check the uploadStatus in the json result:
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
}