forked from j62/ctbrec
Move post-processing from LocalRecorder to Download
This commit is contained in:
parent
4bc92a9dda
commit
6e6597d372
|
@ -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());
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -14,4 +14,5 @@ public interface Download {
|
|||
public File getTarget();
|
||||
public Model getModel();
|
||||
public Instant getStartTime();
|
||||
public void postprocess();
|
||||
}
|
||||
|
|
|
@ -290,4 +290,10 @@ public class LiveJasminChunkedHttpDownload implements Download {
|
|||
public Instant getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postprocess() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -356,4 +356,10 @@ public class LiveJasminWebSocketDownload implements Download {
|
|||
public Instant getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postprocess() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue