//-------------------------------------------------------------- void testApp::getJSON(){ cout << "Getting JSON..." << endl; ss.str(std::string()); // clear string stream ss << "Getting JSON..." << endl; //get json std::string url = "http://stormy-badlands-2316.herokuapp.com/data"; if (!response.open(url)) { cout << "Failed to parse JSON\n" << endl; ss.str(std::string()); // clear string stream ss << "Failed to parse JSON\n" << endl; }else{ gotJSON = true; ss.str(std::string()); // clear string stream //save json file std::string json_final_path =ofToDataPath("json/innovid_videos.json", true); string command = "mkdir "+ofToDataPath("json", true); ofSystemCall(command); command = "curl -o "+json_final_path+ " " + url; ofSystemCall(command); updateJSONDebug(); updateDDL(); downloadVideos(); } }
//-------------------------------------------------------------- void testApp::downloadVideos(){ cout << "downloading videos" << endl; for (int i=0; i<response["videos"].size(); i++){ ofFile video; string video_url = response["videos"][i]["link"].asString(); string video_filename = "movies/" + response["videos"][i]["filename"].asString(); string video_final_path = ofToDataPath(video_filename, true); if (!video.doesFileExist(video_final_path)) { string command = "curl -o "+video_final_path+ " " + video_url; ofSystemCall(command); } } }
//-------------------------------------------------------------- void testApp::setup(){ string youtube_dl = ofToDataPath("youtube-dl", true); // Open a Youtube video feed // http://code.google.com/apis/youtube/2.0/developers_guide_protocol_video_feeds.html // http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?v=2&alt=json // http://gdata.youtube.com/feeds/api/videos?q=skateboarding+dog&alt=json ofxJSONElement youtube; youtube.open("http://gdata.youtube.com/feeds/api/videos?q=slow+loris&alt=json"); // Loop through all of the feed->entry items in the feed int numVideos = min(4, (int)youtube["feed"]["entry"].size()); for(int i=0; i<numVideos; i++) { // use ofToDataPath to get the complete path to the youtube-dl program // https://github.com/rg3/youtube-dl // In each one, there will be a "link" item that contains multiple "href" strings // We want the first href string inside the link item string youtube_url = youtube["feed"]["entry"][i]["link"][UInt(0)]["href"].asString(); cout << youtube_url << endl; // Assemble a command just like the one you would use on the command line // Format 18 = H264 (see http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs) string command = youtube_dl+" --get-url --format 18 "+youtube_url; //cout << command << endl; // Get the full (nasty) URL of the raw video string vid_url = ofSystemCall(command); //cout << vid_url << endl; // Load the video (from a url!) and start playing it vids[i].loadMovie(vid_url); vids[i].play(); } }
//-------------------------------------------------------------- void testApp::setup(){ ofSetFrameRate(60); ofSetVerticalSync(true); //setup background ofSetBackgroundAuto(false); ofBackground(0, 0, 0); red = 255; green, blue = 0; //set up some params for our particle system, this should all be in the ui //we should also load this in from the ui! to do... mZoneRadius = 80.0f; mLowThresh = 0.5f; mHighThresh = 0.8f; mAttractStrength = 0.005f; mRepelStrength = 0.01f; mOrientStrength = 0.01f; mFlatten = false; //setup ui setupUI(); //setup camera cam.setup(); mCenter = ofVec3f(0); string youtube_dl = ofToDataPath("youtube-dl", true); //create our youtube search string //youtube_search_string = createYoutubeSearchString(SEARCH_QUERY); ofxJSONElement youtube; //youtube.open(youtube_search_string); //you can also just open a playlist youtube.open("http://gdata.youtube.com/feeds/api/playlists/PL3ngyh53O02CnHBb69HMZNwdvWo8w3MKW?&alt=json"); //setup our video player and video cube controllers mVideoCubeController.setup(); mVideoPlayerController.setup(); // Loop through all of the feed->entry items in the feed int numVideos = min(mVideoPlayerController.getNumberOfVideos(), (int)youtube["feed"]["entry"].size()); for(int i=0; i<numVideos; i++) { // use ofToDataPath to get the complete path to the youtube-dl program // https://github.com/rg3/youtube-dl // In each one, there will be a "link" item that contains multiple "href" strings // We want the first href string inside the link item string youtube_url = youtube["feed"]["entry"][i]["link"][UInt(0)]["href"].asString(); cout << youtube_url << endl; // Assemble a command just like the one you would use on the command line // Format 18 = H264 (see http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs) string command = youtube_dl+" --get-url --format 18 "+youtube_url; ///cout << command << endl; // Get the full (nasty) URL of the raw video string vid_url = ofSystemCall(command); //cout << vid_url << endl; //create a new video player and add it to our video player vector mVideoPlayerController.addVideoPlayer(); mVideoPlayerController.addVideoURL(vid_url); } mVideoPlayerController.loadVideos(); mVideoPlayerController.playVideos(); mVideoPlayerController.muteVideos(); rgbaFboFloat.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGBA32F_ARB); rgbaFboFloat.begin(); ofClear(255,255,255, 0); rgbaFboFloat.end(); //load shaders bloomShader.load("shaders/bloom.vert", "shaders/bloom.frag"); }