Retrieve any video for use in an ad

function getVideo() {
// This will just get the first valid YouTube video in the account.
// It demonstrates how to filter to see if a video is valid for video ads.
var videos = AdsApp.adMedia().media()
.withCondition("Type = VIDEO")
.get();
var video = null;
while(videos.hasNext()){
video = videos.next();
// You have to use a YouTube video for True View ads, so only return if
// the YouTubeVideoId exists.
if(video.getYouTubeVideoId()) {
return video;
}
}
return null;
}

Retrieve a specific video for use in an ad

function getVideoByYouTubeId() {
// You can filter on the YouTubeVideoId if you already have that video in
// your account to fetch the exact one you want right away.
var videos = AdsApp.adMedia().media()
.withCondition("Type = VIDEO AND YouTubeVideoId = ABCDEFGHIJK")
.get();
if(videos.hasNext()){
return videos.next();
}
return null;
}