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

2

11

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?

Apteral answered 12/5, 2015 at 12:16 Comment(0)
C
13

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.
  ]
  }
Camelliacamelopard answered 12/5, 2015 at 16:55 Comment(3)
exactly what I ended up doing. Thanks.Apteral
It looks working, because you put a fake ID in there. if you try a real disabled one, it won't work.Euripus
you need to ask for the status part, it will contain uploadStatus: rejected for removed videos, with a reason in rejectionStatusMcculley
V
0

I also have a site that share some of your features. I use php code to load the youtube page of the video and then parse the source code to find the keyword "Sorry about that." I can check about 1.1k videos in a few seconds. If you time your calls right it's not enough to pass as a DDOS attack.

However this method doesn't detect the region restrictions.

Vieva answered 14/5, 2016 at 0:43 Comment(1)
This does not work. Besides the fact that YT could change that text, the user may have settings such that another language is used.Brougham

© 2022 - 2024 — McMap. All rights reserved.