diff --git a/common/src/main/java/ctbrec/Recording.java b/common/src/main/java/ctbrec/Recording.java index 10ef3c2e..b003799c 100644 --- a/common/src/main/java/ctbrec/Recording.java +++ b/common/src/main/java/ctbrec/Recording.java @@ -1,6 +1,7 @@ package ctbrec; import java.io.File; +import java.io.Serializable; import java.time.Duration; import java.time.Instant; import java.time.LocalDateTime; @@ -12,7 +13,7 @@ import ctbrec.event.EventBusHolder; import ctbrec.event.RecordingStateChangedEvent; import ctbrec.recorder.download.Download; -public class Recording { +public class Recording implements Serializable { private Model model; private transient Download download; private Instant startDate; @@ -191,11 +192,15 @@ public class Recording { private long getSize() { File rec = new File(Config.getInstance().getSettings().recordingsDir, getPath()); - if(rec.isDirectory()) { + if (rec.isDirectory()) { return getDirectorySize(rec); } else { - if(!rec.exists()) { - return getDirectorySize(rec.getParentFile()); + if (!rec.exists()) { + if (rec.getName().endsWith(".m3u8")) { + return getDirectorySize(rec.getParentFile()); + } else { + return -1; + } } else { return rec.length(); } @@ -204,12 +209,14 @@ public class Recording { private long getDirectorySize(File dir) { long size = 0; - File[] files = dir.listFiles(); - if (files == null) { - return 0; - } - for (File file : files) { - size += file.length(); + if (dir.exists()) { + File[] files = dir.listFiles(); + if (files == null) { + return 0; + } + for (File file : files) { + size += file.length(); + } } return size; } diff --git a/common/src/main/java/ctbrec/StringUtil.java b/common/src/main/java/ctbrec/StringUtil.java index 06e30f49..589e296b 100644 --- a/common/src/main/java/ctbrec/StringUtil.java +++ b/common/src/main/java/ctbrec/StringUtil.java @@ -3,6 +3,8 @@ package ctbrec; import java.text.DecimalFormat; public class StringUtil { + private StringUtil() {} + public static boolean isBlank(String s) { return s == null || s.trim().isEmpty(); } @@ -12,16 +14,20 @@ public class StringUtil { } public static String formatSize(Number sizeInByte) { + if (sizeInByte.longValue() < 0) { + return "n/a"; + } + DecimalFormat df = new DecimalFormat("0.00"); String unit = "Bytes"; double size = sizeInByte.doubleValue(); - if(size > 1024.0 * 1024 * 1024) { + if (size > 1024.0 * 1024 * 1024) { size = size / 1024.0 / 1024 / 1024; unit = "GiB"; - } else if(size > 1024.0 * 1024) { + } else if (size > 1024.0 * 1024) { size = size / 1024.0 / 1024; unit = "MiB"; - } else if(size > 1024.0) { + } else if (size > 1024.0) { size = size / 1024.0; unit = "KiB"; }