youtube-dl commands look like this (but the name of the video is an incremented integer— 1.mp4, 2.mp4, etc):
youtube-dl -f worstvideo --max-downloads 5 -o /Users/a/Documents/of_v0.9.8_osx_release/apps/myApps/20180318_detourningTheWeb_assignment3/bin/data/vids_sky/1.mp4 "https://www.youtube.com/results?sp=CAISAhgB&search_query=sky+timelapse"
youtube-dl -f worstvideo --max-downloads 5 -o /Users/a/Documents/of_v0.9.8_osx_release/apps/myApps/20180318_detourningTheWeb_assignment3/bin/data/vids_grass/1.mp4 "https://www.youtube.com/results?search_query=grass+timelapse&sp=CAISAhgB"
I called this shell command from within my oF app with a `system()` call from a separate thread (created with the `fork()` function):
void ofApp::downloadVid(int vidType, bool _isVidDownloaded, string dir, string vidUrl, string vidId){
if(!_isVidDownloaded){
if(!forkOnce_downloadVid){
string vidName = "/Users/a/Documents/of_v0.9.8_osx_release/apps/myApps/20180318_detourningTheWeb_assignment3/bin/data/" + dir + vidId + ".mp4";
cout << "vidName = " << vidName << endl;
//youtube-dl -f worstvideo --max-downloads 5 -o /Users/a/Documents/of_v0.9.8_osx_release/apps/myApps/20180318_detourningTheWeb_assignment3/bin/data/vids/sky.mp4 "https://www.youtube.com/results?sp=CAISAhgB&search_query=sky+timelapse"
string cmd = "/usr/local/bin/youtube-dl -f worstvideo --max-downloads 1 --playlist-start " + vidId + " --recode-video mp4 -o " + vidName + " "" + vidUrl.c_str() + """;
cout << "cmd = " << cmd << endl;
int pid = fork();
switch(pid){
case -1:{
perror("fork");
_exit(EXIT_FAILURE);
break;
}
case 0:{ // child process
system(cmd.c_str());
_exit(0);
break;
}
default:{ // parent process
// wait for child process
int status = 0;
waitpid(-1, &status, WNOHANG);
printf("child status:%dn",status);
break;
}
}
forkOnce_downloadVid = true;
} else {
if(vidType == 0) {
signal(SIGCHLD,signalHandler_sky);
} else {
signal(SIGCHLD,signalHandler_grass);
}
}
}
}