The following php snippet of code I use to find deleted youtube videos in wordpress posts.. hope it helps someone.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
// put post content into variable $post_content
 
$post_content=$post->post_content; // via mysql direct post table row $post
 
preg_match_all("/\[youtube\=http:\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/|#!v=)([a-zA-Z0-9\-\_]{11})([^&lt;\s]*)\]/", $post_content, $matches, PREG_SET_ORDER);
// scan through each youtube url match
foreach ($matches as $match) {
$videoid=trim($match[3]); // youtube video reference code
if(!check_youtube($videoid)) {
echo($videoid." dead in post <br>\n");
// put code in here to handle post with deleted youtube video
}}
 
function check_youtube($videoid) {
if (strtolower(file_get_contents('http://gdata.youtube.com/feeds/api/videos/'.$videoid)) == 'video not found') {
  return false;
} else {
  return true;
}}
 
?>