Check if a video is available
Asked Answered
M

2

9

I'm working on YouTube data API v3.

I want to know how can i check if a video has been disabled or removed by YouTube.

E.g: https://www.youtube.com/watch?v=dHt_6Z2OaZI

https://www.googleapis.com/youtube/v3/videos?id=dHt_6Z2OaZI
&part=snippet,contentDetails,player,statistics,status
&key=[mykey]

I can not get any idea from the API.

{
"kind": "youtube#videoListResponse",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/Y7032cCbQSAurzEiVMjdFYzamtg\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/2FORRsUGqbS1nvQK3AR1PfmiN7I\"",
"id": "dHt_6Z2OaZI",
"snippet": {},
"contentDetails": {
"duration": "PT1H31M1S",
"dimension": "2d",
"definition": "sd",
"caption": "false",
"licensedContent": false
},
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
},
"statistics": {
"viewCount": "301",
"likeCount": "0",
"dislikeCount": "0",
"favoriteCount": "0",
"commentCount": "0"
},
"player": {
"embedHtml": "<iframe width=\"640\" height=\"360\" src=\"//www.youtube.com/embed/dHt_6Z2OaZI\" frameborder=\"0\" allowfullscreen></iframe>"
}
}
]
}

I tried this

https://www.googleapis.com/youtube/v3/videos
?part=id
&key=[mykey]
&id=dHt_6Z2OaZI

But it's NOT working, still give the result.

Munafo answered 16/7, 2015 at 18:29 Comment(3)
This question may have what you are looking for: #1591793Sheley
@Sheley That question uses the deprecated v2 of the YouTube API, and is not helpful for anyone looking for an answer using the v3 API.Musing
Relevant answer using v3: https://mcmap.net/q/995020/-how-do-i-check-if-a-youtube-video-is-blocked-restricted-deletedSheley
K
4

There's a status field in the results you posted. I think the subfield that most closely relates to what you want is uploadStatus. When I perform an API call for that video, I get:

"status": {
    "uploadStatus": "rejected",
    "rejectionReason": "uploaderAccountSuspended",
    "privacyStatus": "public",
    "license": "youtube",
    "embeddable": true,
    "publicStatsViewable": true
   }

From the documentation, here are the possible values for uploadStatus:

  • deleted
  • failed
  • processed
  • rejected
  • uploaded

After a video is successfully uploaded and processed, it should be accessible to users (assuming it's also public). Therefore, you should just be checking if status is "rejected" or "deleted".

Klinges answered 17/7, 2015 at 21:1 Comment(1)
I am afraid that does not work for deleted videos. This is what the api returns for a deleted video: { "kind": "youtube#videoListResponse", "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/q9wh51deRpP1b7X8Nc3D-bdBxqs\"", "pageInfo": { "totalResults": 0, "resultsPerPage": 0 }, "items": [ ] }Voguish
T
0

In case someone is still interested in this issue:

Right now ContentDetails of Item include RegionRestriction object. You have to analyze it to see if the video is available - here are the details: documentation

Generally if RegionRestriction.Blocked contains a country you're viewing from, than the video is not available for you (similarly you can analyze RegionRestriction.Allowed).

Tania answered 8/11, 2019 at 11:16 Comment(1)
Okay, but how do I check if video is removed by an author?Squander

© 2022 - 2024 — McMap. All rights reserved.