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
As @seengee says, the "right" way to do this is to look for the yt:state tag in the XML representation of a YouTube video via the YouTube API
To get this XML representation, you GET http://gdata.youtube.com/feeds/api/videos/VIDEO_ID (more details here). So implementing this check should be as easy as:
def valid_embed_link?
doc = Hpricot(open("http://gdata.youtube.com/feeds/api/videos/#{youtube_video_id}"))
doc.at('yt:state').blank?
end
Unfortunately this yields false positives. For example, http://www.youtube.com/watch?v=MX6rC1krGp0 plays fine, but http://gdata.youtube.com/feeds/api/videos/MX6rC1krGp0 contains a yt:state tag. Therefore, I've gone with this hackier method:
def valid_embed_link?
doc = Hpricot(open("http://www.youtube.com/watch?v=#{youtube_video_id}"))
return doc.at('.yt-alert-content').blank?
end