forked from j62/ctbrec
1
0
Fork 0

Improve deleteIfTooShort method

If a directory does not exist, it returns true. If the directory is
empty, it deletes the directory and empty parent directories and returns
true.
This commit is contained in:
0xboobface 2019-02-13 22:07:34 +01:00
parent fba3a72167
commit 75a625bbe0
1 changed files with 17 additions and 8 deletions

View File

@ -792,24 +792,33 @@ public class LocalRecorder implements Recorder {
// TODO maybe get file size and bitrate and check, if the values are plausible
// we could also compare the length with the time elapsed since starting the recording
private boolean deleteIfTooShort(Download download) {
long minimumLengthInSeconds = Config.getInstance().getSettings().minimumLengthInSeconds;
if(minimumLengthInSeconds <= 0) {
return false;
}
try {
LOG.debug("Determining video length for {}", download.getTarget());
File target = download.getTarget();
if(!target.exists()) {
return true;
}
if(target.isDirectory()) {
if(!target.exists() || target.list() == null || target.list().length == 0) {
if(target.list() == null || target.list().length == 0) {
deleteDirectory(target);
deleteEmptyParents(target);
return true;
}
} else {
if(!target.exists() || target.length() == 0) {
if(target.length() == 0) {
Files.delete(target.toPath());
deleteEmptyParents(target.getParentFile());
return true;
}
}
long minimumLengthInSeconds = Config.getInstance().getSettings().minimumLengthInSeconds;
if(minimumLengthInSeconds <= 0) {
return false;
}
LOG.debug("Determining video length for {}", download.getTarget());
double duration = 0;
if(target.isDirectory()) {
File playlist = new File(target, "playlist.m3u8");