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