forked from j62/ctbrec
Reset state to WAITING for FAILED, PP and GENERATING_PLAYLIST on start
This commit is contained in:
parent
a59313df49
commit
6fcbdab174
|
@ -1,10 +1,11 @@
|
|||
package ctbrec.recorder;
|
||||
|
||||
import static ctbrec.Recording.State.*;
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static java.nio.file.StandardOpenOption.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.file.Files;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
|
@ -26,7 +27,7 @@ import ctbrec.io.ModelJsonAdapter;
|
|||
import ctbrec.sites.Site;
|
||||
|
||||
public class RecordingManager {
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(RecordingManager.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RecordingManager.class);
|
||||
|
||||
private Config config;
|
||||
private Moshi moshi;
|
||||
|
@ -45,7 +46,7 @@ public class RecordingManager {
|
|||
loadRecordings();
|
||||
}
|
||||
|
||||
public void add(Recording rec) throws UnsupportedEncodingException, IOException {
|
||||
public void add(Recording rec) throws IOException {
|
||||
saveRecording(rec);
|
||||
recordingsLock.lock();
|
||||
try {
|
||||
|
@ -55,14 +56,14 @@ public class RecordingManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void saveRecording(Recording rec) throws UnsupportedEncodingException, IOException {
|
||||
public void saveRecording(Recording rec) throws IOException {
|
||||
String json = adapter.toJson(rec);
|
||||
File recordingsMetaDir = getDir();
|
||||
String filename = rec.toString() + ".json";
|
||||
File recordingMetaData = new File(recordingsMetaDir, filename);
|
||||
rec.setMetaDataFile(recordingMetaData.getAbsolutePath());
|
||||
Files.createDirectories(recordingsMetaDir.toPath());
|
||||
Files.write(recordingMetaData.toPath(), json.getBytes("utf-8"), CREATE, WRITE, TRUNCATE_EXISTING);
|
||||
Files.write(recordingMetaData.toPath(), json.getBytes(UTF_8), CREATE, WRITE, TRUNCATE_EXISTING);
|
||||
}
|
||||
|
||||
private void loadRecordings() throws IOException {
|
||||
|
@ -70,11 +71,11 @@ public class RecordingManager {
|
|||
File[] metaFiles = recordingsMetaDir.listFiles((file, name) -> name.endsWith(".json"));
|
||||
if (metaFiles != null) {
|
||||
for (File file : metaFiles) {
|
||||
String json = new String(Files.readAllBytes(file.toPath()), "utf-8");
|
||||
String json = new String(Files.readAllBytes(file.toPath()), UTF_8);
|
||||
try {
|
||||
Recording recording = adapter.fromJson(json);
|
||||
if (recording.getStatus() == State.RECORDING) {
|
||||
recording.setStatus(State.WAITING);
|
||||
if (recording.getStatus() == RECORDING || recording.getStatus() == GENERATING_PLAYLIST || recording.getStatus() == POST_PROCESSING) {
|
||||
recording.setStatus(WAITING);
|
||||
}
|
||||
if (recordingExists(recording)) {
|
||||
recordings.add(recording);
|
||||
|
|
Loading…
Reference in New Issue