forked from j62/ctbrec
1
0
Fork 0

Fix call of user defined pp script

This commit is contained in:
0xboobface 2019-12-25 13:18:27 +01:00
parent 8dfc4c775f
commit 67c69e3c1b
4 changed files with 39 additions and 44 deletions

View File

@ -10,18 +10,12 @@ import ctbrec.Config;
import ctbrec.OS;
import ctbrec.Recording;
import ctbrec.io.StreamRedirectThread;
import ctbrec.recorder.download.hls.AbstractHlsDownload;
public abstract class AbstractDownload implements Download {
private static final Logger LOG = LoggerFactory.getLogger(AbstractHlsDownload.class);
private static final Logger LOG = LoggerFactory.getLogger(AbstractDownload.class);
@Override
public void postprocess(Recording recording) {
runPostProcessingScript(recording);
}
private void runPostProcessingScript(Recording recording) {
protected void runPostProcessingScript(Recording recording) {
String postProcessing = Config.getInstance().getSettings().postProcessing;
if (postProcessing != null && !postProcessing.isEmpty()) {
File target = recording.getAbsoluteFile();

View File

@ -1,6 +1,6 @@
package ctbrec.recorder.download.dash;
import static ctbrec.Recording.State.POST_PROCESSING;
import static ctbrec.Recording.State.*;
import java.io.ByteArrayInputStream;
import java.io.File;
@ -341,22 +341,22 @@ public class DashDownload extends AbstractDownload {
return Duration.between(startTime, Optional.ofNullable(endTime).orElse(Instant.now()));
}
@Override
public void postprocess(Recording recording) {
try {
recording.setStatus(POST_PROCESSING);
String path = recording.getPath();
File dir = new File(Config.getInstance().getSettings().recordingsDir, path);
File file = new File(dir.getParentFile(), dir.getName().substring(0, dir.getName().length() - 5));
new FfmpegMuxer(dir, file);
targetFile = file;
recording.setPath(path.substring(0, path.length() - 5));
super.postprocess(recording);
} catch (IOException e) {
LOG.error("Error while merging dash segments", e);
recording.setStatus(State.FAILED);
}
}
@Override
public void postprocess(Recording recording) {
try {
recording.setStatus(POST_PROCESSING);
String path = recording.getPath();
File dir = new File(Config.getInstance().getSettings().recordingsDir, path);
File file = new File(dir.getParentFile(), dir.getName().substring(0, dir.getName().length() - 5));
new FfmpegMuxer(dir, file);
targetFile = file;
recording.setPath(path.substring(0, path.length() - 5));
runPostProcessingScript(recording);
} catch (IOException e) {
LOG.error("Error while merging dash segments", e);
recording.setStatus(State.FAILED);
}
}
@Override
public File getTarget() {

View File

@ -179,13 +179,13 @@ public class HlsDownload extends AbstractHlsDownload {
recording.setStatusWithEvent(State.GENERATING_PLAYLIST);
generatePlaylist(recording);
recording.setStatusWithEvent(State.POST_PROCESSING);
super.postprocess(recording);
runPostProcessingScript(recording);
}
protected void generatePlaylist(Recording recording) {
protected File generatePlaylist(Recording recording) {
File recDir = recording.getAbsoluteFile();
if(!config.getSettings().generatePlaylist) {
return;
return null;
}
PlaylistGenerator playlistGenerator = new PlaylistGenerator();
@ -197,6 +197,7 @@ public class HlsDownload extends AbstractHlsDownload {
playlistGenerator.validate(recDir);
}
recording.setProgress(-1);
return playlist;
} catch (IOException | ParseException e) {
LOG.error("Couldn't generate playlist file", e);
} catch (PlaylistException e) {
@ -217,6 +218,8 @@ public class HlsDownload extends AbstractHlsDownload {
LOG.error("Couldn't delete playlist {}", playlist, e1);
}
}
return null;
}
private boolean splitRecording() {
@ -332,16 +335,16 @@ public class HlsDownload extends AbstractHlsDownload {
private double getPlaylistLength(File playlist) throws IOException, ParseException, PlaylistException {
if (playlist.exists()) {
try(FileInputStream fin = new FileInputStream(playlist)) {
PlaylistParser playlistParser = new PlaylistParser(fin, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
Playlist m3u = playlistParser.parse();
MediaPlaylist mediaPlaylist = m3u.getMediaPlaylist();
double length = 0;
for (TrackData trackData : mediaPlaylist.getTracks()) {
length += trackData.getTrackInfo().duration;
}
return length;
}
try(FileInputStream fin = new FileInputStream(playlist)) {
PlaylistParser playlistParser = new PlaylistParser(fin, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
Playlist m3u = playlistParser.parse();
MediaPlaylist mediaPlaylist = m3u.getMediaPlaylist();
double length = 0;
for (TrackData trackData : mediaPlaylist.getTracks()) {
length += trackData.getTrackInfo().duration;
}
return length;
}
} else {
throw new FileNotFoundException(playlist.getAbsolutePath() + " does not exist");
}

View File

@ -47,12 +47,8 @@ public class MergedHlsDownload extends HlsDownload {
@Override
public void postprocess(ctbrec.Recording recording) {
super.postprocess(recording);
File dir = new File(Config.getInstance().getSettings().recordingsDir, recording.getPath());
File playlist = new File(dir, "playlist.m3u8");
if (!playlist.exists()) {
super.generatePlaylist(recording);
}
File playlist = super.generatePlaylist(recording);
File dir = playlist.getParentFile();
try {
postprocess(playlist, finalFile);
@ -62,6 +58,8 @@ public class MergedHlsDownload extends HlsDownload {
if (dir.list().length == 0) {
RecordingManager.deleteEmptyParents(dir);
}
runPostProcessingScript(recording);
} catch (PostProcessingException | IOException e) {
LOG.error("An error occurred during post-processing", e);
}