MrLetsplay 34f0b5b5fe
All checks were successful
Build and push container / Build-Docker-Container (push) Successful in 3m53s
Add more file types, Fix LibraryMetadata
2025-02-18 21:31:54 +01:00

64 lines
1.6 KiB
Java

package me.mrletsplay.videobase.library;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.mrletsplay.mrcore.json.JSONObject;
import me.mrletsplay.mrcore.json.JSONType;
import me.mrletsplay.mrcore.json.converter.JSONConstructor;
import me.mrletsplay.mrcore.json.converter.JSONConverter;
import me.mrletsplay.mrcore.json.converter.JSONConvertible;
import me.mrletsplay.mrcore.json.converter.JSONListType;
import me.mrletsplay.mrcore.json.converter.JSONValue;
public class LibraryMetadata implements JSONConvertible {
@JSONValue("default")
private VideoMetadata defaultMetadata;
@JSONValue
@JSONListType(JSONType.STRING)
private List<String> excludePaths;
private Map<String, VideoMetadata> overrides;
@JSONConstructor
public LibraryMetadata() {
this.overrides = new HashMap<>();
}
public VideoMetadata getDefault() {
return defaultMetadata;
}
public List<String> getExcludePaths() {
return excludePaths == null ? Collections.emptyList() : excludePaths;
}
public Map<String, VideoMetadata> getOverrides() {
return overrides;
}
@Override
public void preDeserialize(JSONObject object) {
JSONObject ov = object.optJSONObject("overrides").orElse(null);
if(ov != null) {
for(String key : ov.keys()) {
overrides.put(key, JSONConverter.decodeObject(ov.getJSONObject(key), VideoMetadata.class));
}
}
}
@Override
public void preSerialize(JSONObject object) {
JSONObject ov = new JSONObject();
for(String key : overrides.keySet()) {
ov.put(key, overrides.get(key).toJSON());
}
object.put("overrides", ov);
}
}