forked from j62/ctbrec
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:
parent
fba3a72167
commit
75a625bbe0
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue