Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a youtube video is blocked/restricted/deleted

I have a website that stores users playlists, but sometimes the videos that were once usable get removed due to copyright violations, or get deleted. I would like my website to automatically detect when this happens, so it can delete the video, or replace it. I'v done a lot of research trying to figure this out but nothing is working. for example, the api data request for the youtube video ID IcmTyiVkhGk (which is unavailable due to copyright) doesn't have a yt:state variable (which would indicate it is restricted), under access control, it does not say restricted or anything similar. How do you check for this type of data?

http://gdata.youtube.com/feeds/api/videos/IcmTyiVkhGk?v=2&prettyprint=true

basically using this to get the data, but no relevant data is there I don't think.

this site is able to detect what regions the site is available in: http://polsy.org.uk/stuff/ytrestrict.cgi?ytid=IcmTyiVkhGk Does anyone know how this works?

like image 314
theprogrammer311 Avatar asked May 12 '15 12:05

theprogrammer311


1 Answers

Use the v3 API. https://developers.google.com/youtube/v3/docs/videos/list

Your question is in 2 parts.

  1. To check if video(s) have been removed from YouTube, send a videos:list request with the video ID(s). For a single ID you can just check if totalResults is 0. If checking multiple video IDs at once, cycle through the items response to see which video IDs still exist on YouTube.

Example:

GET https://www.googleapis.com/youtube/v3/videos?part=id&id=abcdefghijklm&key={YOUR_API_KEY}

{
 "kind": "youtube#videoListResponse",
 "etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/qFRkUhSdCF83BrjXm7uub8slGsk\"",
 "pageInfo": {
  "totalResults": 0,
  "resultsPerPage": 0
 },
 "items": [
 ]
}
  1. To check for access restrictions, send a videos:list request for contentDetails.

Example:

GET https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=IcmTyiVkhGk&key={YOUR_API_KEY}

Under items[] you'll check for

 "regionRestriction": {
 "blocked": [
  "QA",
  "AW",
  "IN",
  etc.
  ]
  }
like image 66
johnh10 Avatar answered Oct 13 '22 01:10

johnh10