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
}
Related
I have a mobile application that embeds some youtube videos in a webview.
The problem is that, using YouTube Data API v3 I get a list of "Embeddable" items to show. But some of them say that "Video unavailable". When I paste the same code on on jsfiddle or a domain or some sort of webserver, it does work but when reading from File or navigating to html string via webview, it doesn't work.
My question is that how can I understand if the video that I'm trying to embed is actually embeddable from file or not?
I have checked youtube data API v3 outputs for each video and I couldn't find any meaningful information.
Is there some other sort of web api or http endpoint that I can check to see if the video is right?
If not, how can I get data from youtube player programatically to see whether it successfully embedded it or not?
The sample list of the youtube videos that can't be embedded in file are following:
https://www.youtube.com/watch?v=TjI3bzvbCU4
https://www.youtube.com/watch?v=QWveXdj6oZU
https://www.youtube.com/watch?v=KEEnap_h8cs
Note: My problem is to identify the unimbeddable items, because I want to load them from file (in a mobile app). Therefore trying to loading it from a webserver isn't an option for me.
Note 2: These blocks aren't regional, they are domain based.
YouTube Data API v3 provides a not working embed page while it says that it is.
While for other videos like this one (ZqYezph-hgg) it works.
So my idea is just to retrieve https://www.youtube.com/embed/VIDEO_ID and see if the video is unplayable like this for instance:
curl -s https://www.youtube.com/embed/TjI3bzvbCU4 | grep "UNPLAYABLE" | wc -l
Returns 1, so this video is unplayable.
curl -s https://www.youtube.com/embed/ZqYezph-hgg | grep "UNPLAYABLE" | wc -l
Returns 0, so this video is playable.
I found this entry on Google Support that might explain why a video is not available.
Quote:
Actually found the issue here. The videos that were displaying this on
embed had "Copyrighted" music playing in the background. YouTube
apparently does not play videos like this while embedded. We had our
user remove the audio and re-uploaded the video and everything is
working fine now.
Hope this helps somebody.
Probably, YouTube Data API is not updated for match the value set by the uploader/owner of the video AND YouTube guidelines for allow embed the videos.
For this case, I suggest you to post a ticket on Issue Tracker.
If you enter to the source code of the video - like: view-source:https://www.youtube.com/embed/TjI3bzvbCU4, you can find there a property called previewPlayabilityStatus as follows:
"previewPlayabilityStatus": {
"status": "UNPLAYABLE",
"reason": "Video no disponible",
"errorScreen": {
"playerErrorMessageRenderer": {
"reason": {
"runs": [{
"text": "Video no disponible"
}]
},
"proceedButton": {
"buttonRenderer": {
"style": "STYLE_DEFAULT",
"size": "SIZE_DEFAULT",
"isDisabled": false,
"text": {
"simpleText": "Mirar en YouTube"
},
"navigationEndpoint": {
"clickTrackingParams": "CAEQ8FsiEwiT6sGfg6j3AhVG25QJHY96Amgu003d"
This info was available throught this endpoint: https://www.youtube.com/get_video_info?video_id=TjI3bzvbCU4, but, now, an HTTP ERROR 410 is returned.
Unfortunately, this info does not provide any useful data about the reason(s) why the video is not available - despite the fact the response of the YouTube Data API says is is embeddable:
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true,
"madeForKids": false
},
You can also use this alternative for embed a YouTube video - I share it here because I find it interesting.
Make sure you have your referer and referer-policy set in the header all requests.
As per docs:
contentDetails.contentRating.ytRating
A rating that YouTube uses to identify age-restricted content.
But that doesn't seem to work as documented, here's the example: https://www.youtube.com/watch?v=IUc0wyae-WI
API response:
{
"items": [
{
"id": "U9x_WdDwATA",
"contentDetails": {
"contentRating": {},
},
}
]
}
Notice that contentRating.ytRating isn't set which means that the video doesn't have age-restriction according to API.
But actually it's not the case: https://www.youtube.com/embed/IUc0wyae-WI?hl=en
This video is age-restricted and only available on YouTube. Learn more
Watch on YouTube
Where's my mistake? Or is it the bug in YouTube API v3?
try to find playabilityStatus:
see for more details:
Use the YouTube API to check if a video is embeddable
This is undocumented API existing for long time, so exploring it is up
to developer. I am aware of "status" (ok/fail), "errorcode" (100 and
150 in my practice), "reason" (string description of error). I am
getting duration ("length_seconds") this way because oEmbed does not
provide this information (strange, but true) and I can hardly motivate
every employer to get keys from youTube to use official API
Im here to ask if it's possible to fully use youtube data api v3 with angular 2+, the documentation just have examples from javascript like authentication, playlist videos, insert a playlist and search of videos (samples)
I'm trying to upload a video, using parameter like:
(gapi.client as any).youtube.videos.insert({
"resource": {
// Video title and description
"snippet": {
"title": "Test",
"description": "Test video upload via YouTube API"
},
"status": {
"privacyStatus": "private"
}
},
"part": "snippet,status,id",
"media": {
"body": video
})
My problem is that even like this, it always return error 404 : "The request does not include the video content.", documentation says the videos needs to be video/* or application/octet-stream, and my video object is a File extended from Blob.
What could i'm possibly doing wrong?
If it's the video file, what I have to do to work?
PS: "(gapi.client as any).youtube" has this any, because youtube is not a property from the interface, its loaded.
Solved
I'm brazilian then I was searching portuguese documentation, that is quite poor, when changed to English, I found 2 archives cors_upload.js and upload_video.js JS samples in the documentation, converted then to typescript and now it works.
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'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"
}