Generate thumbnails for Jellyfin shows
This commit is contained in:
@@ -30,6 +30,8 @@ public class ThumbnailService {
|
|||||||
FileInfo fileInfo = (FileInfo) fileInfoBase;
|
FileInfo fileInfo = (FileInfo) fileInfoBase;
|
||||||
if (fileInfo.filename.endsWith(".zip")) {
|
if (fileInfo.filename.endsWith(".zip")) {
|
||||||
return this.generateThumbnailFromZip(fileInfo, thumbPath);
|
return this.generateThumbnailFromZip(fileInfo, thumbPath);
|
||||||
|
} else {
|
||||||
|
return this.generateThumbnailForFile(fileInfo, thumbPath);
|
||||||
}
|
}
|
||||||
} else if (fileInfoBase instanceof FolderInfo) {
|
} else if (fileInfoBase instanceof FolderInfo) {
|
||||||
return this.generateThumbnailForFolder((FolderInfo) fileInfoBase, thumbPath);
|
return this.generateThumbnailForFolder((FolderInfo) fileInfoBase, thumbPath);
|
||||||
@@ -37,6 +39,32 @@ public class ThumbnailService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean generateThumbnailForFile(FileInfo fileInfo, Path thumbPath) {
|
||||||
|
Path filePath = Paths.get(fileApiConfiguration.directory()
|
||||||
|
+ URLDecoder.decode(fileInfo.directUrl, StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
Path imgPath = filePath.resolveSibling(
|
||||||
|
filePath.getFileName().toString().replaceAll("\\.[^.]*$", "-thumb.jpg"));
|
||||||
|
if (Files.exists(imgPath)) {
|
||||||
|
try {
|
||||||
|
thumbPath.getParent().toFile().mkdirs();
|
||||||
|
|
||||||
|
ConvertCmd convert = new ConvertCmd();
|
||||||
|
IMOperation op = new IMOperation();
|
||||||
|
op.addImage(imgPath.toString());
|
||||||
|
op.resize(200, null);
|
||||||
|
op.addImage(thumbPath.toString());
|
||||||
|
convert.run(op);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (IOException | InterruptedException | IM4JavaException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean generateThumbnailFromZip(FileInfo fileInfo, Path thumbPath) {
|
public boolean generateThumbnailFromZip(FileInfo fileInfo, Path thumbPath) {
|
||||||
Path zipPath = Paths.get(fileApiConfiguration.directory()
|
Path zipPath = Paths.get(fileApiConfiguration.directory()
|
||||||
+ URLDecoder.decode(fileInfo.directUrl, StandardCharsets.UTF_8));
|
+ URLDecoder.decode(fileInfo.directUrl, StandardCharsets.UTF_8));
|
||||||
@@ -77,10 +105,30 @@ public class ThumbnailService {
|
|||||||
+ URLDecoder.decode(folderInfo.directUrl, StandardCharsets.UTF_8));
|
+ URLDecoder.decode(folderInfo.directUrl, StandardCharsets.UTF_8));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Optional<Path> imgPath = Files.list(folderPath).sorted()
|
Optional<Path> imgPath;
|
||||||
|
|
||||||
|
Path posterPath = folderPath.resolve("poster.jpg");
|
||||||
|
if (Files.exists(posterPath)) {
|
||||||
|
// Check for series poster
|
||||||
|
imgPath = Optional.of(posterPath);
|
||||||
|
} else if (folderPath.getFileName().toString().startsWith("Season ")
|
||||||
|
|| (folderPath.getFileName().toString().equals("Specials"))) {
|
||||||
|
// Season folder
|
||||||
|
String folderName = folderPath.getFileName().toString();
|
||||||
|
if (folderName.startsWith("Season ")) {
|
||||||
|
String seasonNumber =
|
||||||
|
String.format("%02d", Integer.parseInt(folderName.substring(7)));
|
||||||
|
imgPath = Optional
|
||||||
|
.of(folderPath.resolveSibling("season" + seasonNumber + "-poster.jpg"));
|
||||||
|
} else {
|
||||||
|
imgPath = Optional.of(folderPath.resolveSibling("season-specials-poster.jpg"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
imgPath = Files.list(folderPath).sorted()
|
||||||
.filter(p -> !Files.isDirectory(p)
|
.filter(p -> !Files.isDirectory(p)
|
||||||
&& (p.toString().endsWith(".png") || p.toString().endsWith(".jpg")))
|
&& (p.toString().endsWith(".png") || p.toString().endsWith(".jpg")))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
}
|
||||||
if (imgPath.isPresent()) {
|
if (imgPath.isPresent()) {
|
||||||
thumbPath.getParent().toFile().mkdirs();
|
thumbPath.getParent().toFile().mkdirs();
|
||||||
|
|
||||||
@@ -93,8 +141,8 @@ public class ThumbnailService {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (IOException | InterruptedException | IM4JavaException ignored) {
|
} catch (IOException | InterruptedException | IM4JavaException e) {
|
||||||
ignored.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user