use of xmlwise.XmlParseException in project UniversalMediaServer by UniversalMediaServer.
the class RootFolder method getApertureFolder.
/**
* Returns Aperture folder. Used by manageRoot, so it is usually used as
* a folder at the root folder. Only works when PMS is run on Mac OS X.
* TODO: Requirements for Aperture.
*/
private DLNAResource getApertureFolder() {
VirtualFolder res = null;
if (Platform.isMac()) {
Process process = null;
try {
process = Runtime.getRuntime().exec("defaults read com.apple.iApps ApertureLibraries");
try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
// Every line entry is one aperture library. We want all of them as a dlna folder.
String line;
res = new VirtualFolder("Aperture libraries", null);
while ((line = in.readLine()) != null) {
if (line.startsWith("(") || line.startsWith(")")) {
continue;
}
// remove extra spaces
line = line.trim();
// remove quotes and spaces
line = line.substring(1, line.lastIndexOf('"'));
VirtualFolder apertureLibrary = createApertureDlnaLibrary(line);
if (apertureLibrary != null) {
res.addChild(apertureLibrary);
}
}
}
} catch (IOException | XmlParseException | URISyntaxException e) {
LOGGER.error("Something went wrong with the aperture library scan: ", e);
} finally {
// Avoid zombie processes, or open stream failures
if (process != null) {
try {
// The process seems to always finish, so we can wait for it.
// If the result code is not read by parent. The process might turn into a zombie (they are real!)
process.waitFor();
} catch (InterruptedException e) {
LOGGER.warn("Interrupted while waiting for stream for process" + e.getMessage());
}
try {
process.getErrorStream().close();
} catch (Exception e) {
LOGGER.warn("Could not close stream for output process", e);
}
try {
process.getInputStream().close();
} catch (Exception e) {
LOGGER.warn("Could not close stream for output process", e);
}
try {
process.getOutputStream().close();
} catch (Exception e) {
LOGGER.warn("Could not close stream for output process", e);
}
}
}
}
return res;
}
use of xmlwise.XmlParseException in project UniversalMediaServer by UniversalMediaServer.
the class RootFolder method getiPhotoFolder.
/**
* Creates, populates and returns a virtual folder mirroring the
* contents of the system's iPhoto folder.
* Mac OS X only.
*
* @return iPhotoVirtualFolder the populated <code>VirtualFolder</code>, or null if one couldn't be created.
*/
private DLNAResource getiPhotoFolder() {
VirtualFolder iPhotoVirtualFolder = null;
if (Platform.isMac()) {
LOGGER.debug("Adding iPhoto folder");
InputStream inputStream = null;
try {
// This command will show the XML files for recently opened iPhoto databases
Process process = Runtime.getRuntime().exec("defaults read com.apple.iApps iPhotoRecentDatabases");
inputStream = process.getInputStream();
List<String> lines = IOUtils.readLines(inputStream);
LOGGER.debug("iPhotoRecentDatabases: {}", lines);
if (lines.size() >= 2) {
// we want the 2nd line
String line = lines.get(1);
// Remove extra spaces
line = line.trim();
// Remove quotes
line = line.substring(1, line.length() - 1);
URI uri = new URI(line);
URL url = uri.toURL();
File file = FileUtils.toFile(url);
LOGGER.debug("Resolved URL to file: {} -> {}", url, file.getAbsolutePath());
// Load the properties XML file.
Map<String, Object> iPhotoLib = Plist.load(file);
// The list of all photos
Map<?, ?> photoList = (Map<?, ?>) iPhotoLib.get("Master Image List");
// The list of events (rolls)
List<Map<?, ?>> listOfRolls = (List<Map<?, ?>>) iPhotoLib.get("List of Rolls");
iPhotoVirtualFolder = new VirtualFolder("iPhoto Library", null);
for (Map<?, ?> roll : listOfRolls) {
Object rollName = roll.get("RollName");
if (rollName != null) {
VirtualFolder virtualFolder = new VirtualFolder(rollName.toString(), null);
// List of photos in an event (roll)
List<?> rollPhotos = (List<?>) roll.get("KeyList");
for (Object photo : rollPhotos) {
Map<?, ?> photoProperties = (Map<?, ?>) photoList.get(photo);
if (photoProperties != null) {
Object imagePath = photoProperties.get("ImagePath");
if (imagePath != null) {
RealFile realFile = new RealFile(new File(imagePath.toString()));
virtualFolder.addChild(realFile);
}
}
}
iPhotoVirtualFolder.addChild(virtualFolder);
}
}
} else {
LOGGER.info("iPhoto folder not found");
}
} catch (XmlParseException | URISyntaxException | IOException e) {
LOGGER.error("Something went wrong with the iPhoto Library scan: ", e);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
return iPhotoVirtualFolder;
}
Aggregations