3

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

enter image description here

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.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Mohsen
  • 427
  • 4
  • 20

3 Answers3

2

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.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
  • Basically this method sends a request to the embedding endoint and checks for the word "UNPLAYABLE" in it's content. It can be easily implemented in any programming language – Mohsen Apr 23 '22 at 15:12
  • Also I added a "Accept-Language=en" header to make sure I always get the results in English – Mohsen Apr 23 '22 at 15:16
  • The `Accept-Language=en` isn't required because `UNPLAYABLE` is written in YouTube JSON answer as a value for `status` so not shown to the end-user so not translated. – Benjamin Loison Apr 23 '22 at 15:48
1

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.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
0

Make sure you have your referer and referer-policy set in the header all requests.

A. Nurb
  • 496
  • 1
  • 3
  • 17