/* Given a YouTube URL, extract the video ID and return it as a string. */ std::string youtubeId(std::string link) { // YouTube ID is either the "v" query parameter or a path std::size_t v = link.find("v="); // If it is the path, then it is just the last 11 characters. return std::string::npos == v ?link.substr(link.size()-11) :link.substr(v+2,11); }