Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically determine whether a Youtube video has been taken down

I'm getting most of the music on Rap Exegesis from YouTube (in the form of embedded players). Unfortunately, there's always the risk that one of the videos I'm using will be taken down (due to copyright issues or whatever), thereby breaking the corresponding page on my site.

Ideally I would have a cronjob that would check (nightly say) whether any videos had been removed and notify me. What's the best way to do this?

like image 723
Tom Lehman Avatar asked Oct 19 '09 21:10

Tom Lehman


2 Answers

The information you need is available via the YouTube API, specifically in the yt:state tag

Depending what language you are programming in there is lots of code around for interacting with the YouTube API.

Post here with more details if you are still having issues getting this to work.

like image 142
robjmills Avatar answered Oct 13 '22 04:10

robjmills


As well as the "yt:state tag", the OP of the video may not allow it to be embedded. If the list of songs on the front page is coming from a playlist that you maintain on YouTube, for example, then a way to make sure you aren't getting songs that aren't embeddable is to include the "&format=5" parameter when retrieving your list. E.g.

http://gdata.youtube.com/feeds/api/playlists/8BCDD04DE8F771B2?v=2&format=5

Also, if you are worried about country-level restrictions, then use the "&restriction=[two-letter country code]" parameter.

See the 'Developer's Guide: Data API Protocol – API Query Parameters'.

like image 25
Ralph Lavelle Avatar answered Oct 13 '22 04:10

Ralph Lavelle