forked from j62/ctbrec
1
0
Fork 0

Fix NPE in MergedHlsDownload

This commit is contained in:
0xboobface 2019-12-26 12:51:26 +01:00
parent d48498e715
commit 5b2ddfb825
1 changed files with 6 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import java.security.NoSuchAlgorithmException;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects;
import org.jcodec.containers.mp4.MP4Util; import org.jcodec.containers.mp4.MP4Util;
import org.jcodec.containers.mp4.boxes.MovieBox; import org.jcodec.containers.mp4.boxes.MovieBox;
@ -55,18 +56,18 @@ public class MergedHlsDownload extends HlsDownload {
@Override @Override
public void postprocess(ctbrec.Recording recording) { public void postprocess(ctbrec.Recording recording) {
File playlist = super.generatePlaylist(recording);
File dir = playlist.getParentFile();
try { try {
File playlist = super.generatePlaylist(recording);
Objects.requireNonNull(playlist, "Generated playlist is null");
postprocess(playlist, finalFile); postprocess(playlist, finalFile);
String recordingsDir = Config.getInstance().getSettings().recordingsDir; String recordingsDir = Config.getInstance().getSettings().recordingsDir;
String path = finalFile.getAbsolutePath().substring(recordingsDir.length()); String path = finalFile.getAbsolutePath().substring(recordingsDir.length());
recording.setPath(path); recording.setPath(path);
File dir = playlist.getParentFile();
if (dir.list().length == 0) { if (dir.list().length == 0) {
RecordingManager.deleteEmptyParents(dir); RecordingManager.deleteEmptyParents(dir);
} }
runPostProcessingScript(recording); runPostProcessingScript(recording);
} catch (Exception e) { } catch (Exception e) {
throw new PostProcessingException(e); throw new PostProcessingException(e);
@ -93,7 +94,7 @@ public class MergedHlsDownload extends HlsDownload {
int exitCode = ffmpeg.waitFor(); int exitCode = ffmpeg.waitFor();
if (exitCode == 0) { if (exitCode == 0) {
Files.delete(playlist.toPath()); Files.delete(playlist.toPath());
File[] segments = dir.listFiles((directory, filename) -> filename.endsWith(".ts")); File[] segments = dir.listFiles((directory, filename) -> filename.endsWith(".ts") || filename.endsWith(".corrupt"));
for (File segment : segments) { for (File segment : segments) {
Files.delete(segment.toPath()); Files.delete(segment.toPath());
} }