Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Youtube_Downloader {
- private static FileOutputStream fos = null;
- /******************************************************************************************/
- public static void main(String[] args) throws Exception {
- String s = null;
- File logFile = new File("ytlog.txt");
- fos = new FileOutputStream(logFile, true); //true = append
- try {
- Process p = Runtime.getRuntime().exec("ps -ef ");
- BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
- BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
- boolean youtube_dl_running_flag = false;
- while ((s = stdInput.readLine()) != null) {
- if(s.indexOf("youtube-dl") > -1) {
- log(s);
- youtube_dl_running_flag = true;
- System.exit(-1);
- }
- }
- if(youtube_dl_running_flag == false) {
- log("youtube-dl is not running. launching now...");
- Process p2 = Runtime.getRuntime().exec("youtube-dl https://www.youtube.com/watch?v=0SZw8jpfAk0");
- log("Process launched...");
- BufferedReader stdInput2 = new BufferedReader(new InputStreamReader(p2.getInputStream()));
- BufferedReader stdError2 = new BufferedReader(new InputStreamReader(p2.getErrorStream()));
- int exitVal = p2.waitFor();
- log("WaitFor() complete. exitVal=" + exitVal );
- while ((s = stdInput2.readLine()) != null) {
- System.out.println(s);
- }
- while ((s = stdError2.readLine()) != null) {
- System.out.println(s);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- System.exit(-1);
- } finally {
- fos.close();
- }
- }
- /******************************************************************************************/
- public static void log(Object obj) throws Exception {
- fos.write((new Date() + " : " + obj.toString() + "\r\n").getBytes());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment