Deleting Video Entrys based on Video ID and Developer Key


A quick helper function explaining how to delete Video Entry's from YouTube based on a Developer Tag and based on an array of Video ID's to delete. Please note that this example assumes the use of the PHP Client Library.
/**
 * Delete a video matching a developer tag and a video id.
 *
 * @param $youTubeService Zend_Gdata_YouTube An authenticated YouTube service object.
 * @param $developerTag string A developer tag for which to retrieve videos.
 * @param $videoIdsToDelete array An array of video ids to be deleted.
 * @return void
 */
function deleteVideosByDeveloperTag($youTubeService, $developerTag, $videoIdsToDelete)
{
 $devTagUrl = 'http://gdata.youtube.com/feeds/videos/-/%7B' .
   'http%3A%2F%2Fgdata.youtube.com%2Fschemas%2F2007%2F' .
   'developertags.cat%7D' . $developerTag;

  $devTagFeed = $youTubeService->getVideoFeed($devTagUrl);

  foreach($developerTagFeed as $videoEntry) {
    if ($entry instanceof Zend_Gdata_YouTube_VideoEntry) {
      $videoIdsToBeDeleted[] = $videoEntry->getVideoId();
    }
  }

  // Then use a read-write feed to actually perform the deletion(s)
  $myVideoFeed = $youTubeService->getUserUploads('default');

  foreach($myVideoFeed as $videoEntry) {
    $id = $videoEntry->getVideoId();
     if (in_array($id, $videoIdsToBeDeleted) {
       $youTubeService->delete($videoEntry);
    }
  }
}