//------------------------------------------------------------------------------ const string ofxThreadedYouTubeVideo::getRandomURL() { string url = ""; const string search_url = "https://www.googleapis.com/youtube/v3/search?q=\"v="+genRandomString(4)+"\"&key=AIzaSyDGYA7woinSUM_eQStrJWgLaCA5fugJ3IA&part=snippet&maxResults=50&"; cout << "--------------------------------------------------" << endl; cout << "URL=" << search_url << endl; if (!response.open(search_url)) { cout << "Failed to parse JSON\n" << endl; } unsigned int numVideos = response["items"].size(); unsigned int totalVideos = response["pageInfo"]["totalResults"].asUInt(); ofLogNotice("ofxThreadedYouTubeVideo") << "Total videos = " << totalVideos; ofLogNotice("ofxThreadedYouTubeVideo") << "numVideos = " << numVideos; if(numVideos == 0) { ofLogError("ofxThreadedYouTubeVideo") << "No videos returned"; return ""; } int i = ofRandom(0,numVideos); Json::Value entryNode = response["items"][i]; cout << "title = " << entryNode["snippet"]["title"].asString() << endl; cout << "video id = " << entryNode["id"]["videoId"].asString() << endl; cout << "--------------------------------------------------" << endl; url = "https://www.youtube.com/watch?v="+entryNode["id"]["videoId"].asString(); return url; }
void multipleFactoryTest(size_t times) { std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<unsigned long> distr(5, 20); ofstream logfile("log.txt", ios::app); Logger::printPromptlyToStdOut(); for (size_t i = 50; i < 50 + times; ++i) { Logger::log("Test with ID #" + to_string(i) + " is started."); testFactory(genRandomString(i), seconds(distr(gen)), seconds(distr(gen)), i); Logger::print(logfile); Logger::clear(); cout << endl; } Logger::save("log.txt"); }