How to identify the YouTube videos that can't embed on file - youtube

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.

Related

Youtube's API age restriction is empty but the embed player is reporting that "This video is age-restricted"

When I'm getting the response from Youtube's API for some videos, the contentRating is empty:
"contentDetails":{
"duration":"PT1H24M43S",
"dimension":"2d",
"definition":"sd",
"caption":"true",
"licensedContent":true,
"regionRestriction":{
"allowed":[
"US"
]
},
"contentRating":{
},
"projection":"rectangular"
},
...but the embed player says that "This video is age-restricted and only available on YouTube" and as a result my app is embedding videos that are unplayable for some users.
In contentRating, I was expecting to find "ytRating": "ytAgeRestricted" but unfortunately this isn't true in some cases!
Is another (bulletproof) way to find out if the video is age restricted?

YouTube API: detect that the video is age-restricted

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

Youtube data api v3 and angular 2+

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.

Know if a video Youtube is unavailable with the API

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
}

Youtube API v3 Duration PlaylistItem

If I get all Playlist Items with the Youtube Data API v3, I am getting this format for all videos:
"contentDetails": {
"videoId": "KUL_AHeC4zw",
"startAt": "PT0S",
"endAt": "PT21M12.667S"
}
Whats that thingie next to endAt? Why is there a point in the middle? I expect some kind of PT21M54S. I just want the duration as I would get it when I am fetching a single video. Is that a bug or am I just not able to understand that ISO Date Format?
This field "endAt" is not the same as the "duration" of the video, but where the playlist owner wants it to stop playing. The video duration is located in the video resource and not in the playlistItem. And it requieres another lookup request.
You can find the definitions of the fields in the YouTube documentation. See for those resource definitions:
https://developers.google.com/youtube/v3/docs/playlistItems#resource
and https://developers.google.com/youtube/v3/docs/videos#resource
"startAt": "PT0S",
"endAt": "PT21M12.667S"
This property has been deprecated and, if set, its value is ignored.
For More Info Check at https://developers.google.com/youtube/v3/docs/playlistItems#resource

Resources