mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
[IMPL] MkvFileCollector + FileCollector interface + new structure
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import model.FileAttribute;
|
|
||||||
import query.QueryBuilder;
|
import query.QueryBuilder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
|
||||||
|
|
||||||
|
public class AttributeUpdaterKernel {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
||||||
|
|
||||||
|
public class AttributeConfig {
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.intimpl;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface FileCollector {
|
||||||
|
List<File> loadFiles(String path);
|
||||||
|
|
||||||
|
List<FileAttribute> loadAttributes(File file);
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.intimpl;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import config.MKVToolProperties;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
public class MkvFileCollector implements FileCollector {
|
||||||
|
private ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param path Is entered path, which leads to one file directly or a directory which will be loaded recursive
|
||||||
|
* @return list of all files within the directory, if it's only a file, the file will be returned in a list
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<File> loadFiles(String path) {
|
||||||
|
File file = new File(path);
|
||||||
|
if(file.isFile() && file.getAbsolutePath().endsWith(".mkv")){
|
||||||
|
return new ArrayList<File>() {{
|
||||||
|
add(file);
|
||||||
|
}};
|
||||||
|
}else if(file.isDirectory()){
|
||||||
|
try(Stream<Path> paths = Files.walk(Paths.get(path))){
|
||||||
|
return paths
|
||||||
|
.filter(Files::isRegularFile)
|
||||||
|
.map(Path::toFile)
|
||||||
|
.filter(f -> f.getAbsolutePath().endsWith(".mkv"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}catch(IOException e){
|
||||||
|
log.error("Couldn't find file or directory!", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param file Takes the file from which the attributes will be returned
|
||||||
|
* @return list of all important attributes
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<FileAttribute> loadAttributes(File file) {
|
||||||
|
Map<String, Object> jsonMap;
|
||||||
|
List<FileAttribute> fileAttributes = new ArrayList<>();
|
||||||
|
try(InputStream inputStream =
|
||||||
|
Runtime.getRuntime().exec("\"" + MKVToolProperties.getInstance().getMkvmergePath()
|
||||||
|
+ "\" --identify --identification-format json \"" + file.getAbsolutePath() + "\"").getInputStream()){
|
||||||
|
jsonMap = mapper.readValue(inputStream, Map.class);
|
||||||
|
List<Map<String, Object>> tracks = (List<Map<String, Object>>) jsonMap.get("tracks");
|
||||||
|
|
||||||
|
for(Map<String, Object> attribute : tracks){
|
||||||
|
if(! "video".equals(attribute.get("type"))){
|
||||||
|
Map<String, Object> properties = (Map<String, Object>) attribute.get("properties");
|
||||||
|
fileAttributes.add(new FileAttribute(
|
||||||
|
(int) properties.get("number"),
|
||||||
|
(String) properties.get("language"),
|
||||||
|
(String) properties.get("track_name"),
|
||||||
|
(Boolean) properties.get("default_track"),
|
||||||
|
(Boolean) properties.get("forced_track"),
|
||||||
|
(String) attribute.get("type")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch(IOException e){
|
||||||
|
log.error("File could not be found or loaded!");
|
||||||
|
}
|
||||||
|
return fileAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean verifyFile(File file) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package query;
|
package query;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import config.MKVToolProperties;
|
import config.MKVToolProperties;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import model.FileAttribute;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|||||||
Reference in New Issue
Block a user