diff --git a/common/src/main/java/ctbrec/recorder/LocalRecorder.java b/common/src/main/java/ctbrec/recorder/LocalRecorder.java index d47385e2..5c4de1d1 100644 --- a/common/src/main/java/ctbrec/recorder/LocalRecorder.java +++ b/common/src/main/java/ctbrec/recorder/LocalRecorder.java @@ -16,7 +16,6 @@ import java.text.SimpleDateFormat; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -51,7 +50,6 @@ import com.iheartradio.m3u8.data.TrackData; import ctbrec.Config; import ctbrec.Model; import ctbrec.MpegUtil; -import ctbrec.OS; import ctbrec.Recording; import ctbrec.Recording.State; import ctbrec.event.Event; @@ -59,7 +57,6 @@ import ctbrec.event.EventBusHolder; import ctbrec.event.ModelIsOnlineEvent; import ctbrec.event.RecordingStateChangedEvent; import ctbrec.io.HttpClient; -import ctbrec.io.StreamRedirectThread; import ctbrec.recorder.PlaylistGenerator.InvalidPlaylistException; import ctbrec.recorder.download.Download; @@ -229,38 +226,38 @@ public class LocalRecorder implements Recorder { ppThreadPool.submit(stopAndThePostProcess); } - private void postprocess(Download download) { - String postProcessing = Config.getInstance().getSettings().postProcessing; - if (postProcessing != null && !postProcessing.isEmpty()) { - Runtime rt = Runtime.getRuntime(); - try { - String[] args = new String[] { - postProcessing, - download.getTarget().getParentFile().getAbsolutePath(), - download.getTarget().getAbsolutePath(), - download.getModel().getName(), - download.getModel().getSite().getName(), - Long.toString(download.getStartTime().getEpochSecond()) - }; - LOG.debug("Running {}", Arrays.toString(args)); - Process process = rt.exec(args, OS.getEnvironment()); - // TODO maybe write these to a separate log file, e.g. recname.ts.pp.log - Thread std = new Thread(new StreamRedirectThread(process.getInputStream(), System.out)); - std.setName("Process stdout pipe"); - std.setDaemon(true); - std.start(); - Thread err = new Thread(new StreamRedirectThread(process.getErrorStream(), System.err)); - err.setName("Process stderr pipe"); - err.setDaemon(true); - err.start(); - - process.waitFor(); - LOG.debug("Process finished."); - } catch (Exception e) { - LOG.error("Error in process thread", e); - } - } - } + // private void postprocess(Download download) { + // String postProcessing = Config.getInstance().getSettings().postProcessing; + // if (postProcessing != null && !postProcessing.isEmpty()) { + // Runtime rt = Runtime.getRuntime(); + // try { + // String[] args = new String[] { + // postProcessing, + // download.getTarget().getParentFile().getAbsolutePath(), + // download.getTarget().getAbsolutePath(), + // download.getModel().getName(), + // download.getModel().getSite().getName(), + // Long.toString(download.getStartTime().getEpochSecond()) + // }; + // LOG.debug("Running {}", Arrays.toString(args)); + // Process process = rt.exec(args, OS.getEnvironment()); + // // TODO maybe write these to a separate log file, e.g. recname.ts.pp.log + // Thread std = new Thread(new StreamRedirectThread(process.getInputStream(), System.out)); + // std.setName("Process stdout pipe"); + // std.setDaemon(true); + // std.start(); + // Thread err = new Thread(new StreamRedirectThread(process.getErrorStream(), System.err)); + // err.setName("Process stderr pipe"); + // err.setDaemon(true); + // err.start(); + // + // process.waitFor(); + // LOG.debug("Process finished."); + // } catch (Exception e) { + // LOG.error("Error in process thread", e); + // } + // } + // } @Override public boolean isTracked(Model model) { @@ -782,7 +779,7 @@ public class LocalRecorder implements Recorder { boolean deleted = deleteIfTooShort(download); if(!deleted) { fireRecordingStateChanged(download.getTarget(), POST_PROCESSING, download.getModel(), download.getStartTime()); - postprocess(download); + download.postprocess(); } fireRecordingStateChanged(download.getTarget(), FINISHED, download.getModel(), download.getStartTime()); }; diff --git a/common/src/main/java/ctbrec/recorder/download/AbstractHlsDownload.java b/common/src/main/java/ctbrec/recorder/download/AbstractHlsDownload.java index 1646794e..3f5a2835 100644 --- a/common/src/main/java/ctbrec/recorder/download/AbstractHlsDownload.java +++ b/common/src/main/java/ctbrec/recorder/download/AbstractHlsDownload.java @@ -5,6 +5,7 @@ import java.io.InputStream; import java.net.URL; import java.time.Instant; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -31,8 +32,10 @@ import com.iheartradio.m3u8.data.TrackData; import ctbrec.Config; import ctbrec.Model; +import ctbrec.OS; import ctbrec.io.HttpClient; import ctbrec.io.HttpException; +import ctbrec.io.StreamRedirectThread; import ctbrec.sites.fc2live.Fc2Live; import okhttp3.Request; import okhttp3.Response; @@ -155,6 +158,44 @@ public abstract class AbstractHlsDownload implements Download { return model; } + @Override + public void postprocess() { + runPostProcessingScript(); + } + + private void runPostProcessingScript() { + String postProcessing = Config.getInstance().getSettings().postProcessing; + if (postProcessing != null && !postProcessing.isEmpty()) { + Runtime rt = Runtime.getRuntime(); + try { + String[] args = new String[] { + postProcessing, + getTarget().getParentFile().getAbsolutePath(), + getTarget().getAbsolutePath(), + getModel().getName(), + getModel().getSite().getName(), + Long.toString(getStartTime().getEpochSecond()) + }; + LOG.debug("Running {}", Arrays.toString(args)); + Process process = rt.exec(args, OS.getEnvironment()); + // TODO maybe write these to a separate log file, e.g. recname.ts.pp.log + Thread std = new Thread(new StreamRedirectThread(process.getInputStream(), System.out)); + std.setName("Process stdout pipe"); + std.setDaemon(true); + std.start(); + Thread err = new Thread(new StreamRedirectThread(process.getErrorStream(), System.err)); + err.setName("Process stderr pipe"); + err.setDaemon(true); + err.start(); + + process.waitFor(); + LOG.debug("Process finished."); + } catch (Exception e) { + LOG.error("Error in process thread", e); + } + } + } + public static class SegmentPlaylist { public String url; public int seq = 0; diff --git a/common/src/main/java/ctbrec/recorder/download/Download.java b/common/src/main/java/ctbrec/recorder/download/Download.java index 703a6a40..e8074954 100644 --- a/common/src/main/java/ctbrec/recorder/download/Download.java +++ b/common/src/main/java/ctbrec/recorder/download/Download.java @@ -14,4 +14,5 @@ public interface Download { public File getTarget(); public Model getModel(); public Instant getStartTime(); + public void postprocess(); } diff --git a/common/src/main/java/ctbrec/sites/jasmin/LiveJasminChunkedHttpDownload.java b/common/src/main/java/ctbrec/sites/jasmin/LiveJasminChunkedHttpDownload.java index b769b0c7..44d6ee01 100644 --- a/common/src/main/java/ctbrec/sites/jasmin/LiveJasminChunkedHttpDownload.java +++ b/common/src/main/java/ctbrec/sites/jasmin/LiveJasminChunkedHttpDownload.java @@ -290,4 +290,10 @@ public class LiveJasminChunkedHttpDownload implements Download { public Instant getStartTime() { return startTime; } + + @Override + public void postprocess() { + // TODO Auto-generated method stub + + } } diff --git a/common/src/main/java/ctbrec/sites/jasmin/LiveJasminWebSocketDownload.java b/common/src/main/java/ctbrec/sites/jasmin/LiveJasminWebSocketDownload.java index 19bdb665..f8627ce1 100644 --- a/common/src/main/java/ctbrec/sites/jasmin/LiveJasminWebSocketDownload.java +++ b/common/src/main/java/ctbrec/sites/jasmin/LiveJasminWebSocketDownload.java @@ -356,4 +356,10 @@ public class LiveJasminWebSocketDownload implements Download { public Instant getStartTime() { return startTime; } + + @Override + public void postprocess() { + // TODO Auto-generated method stub + + } }