Auto-Validate all path components of the {plex} path
This commit is contained in:
parent
8bed1ba2df
commit
0300064ea1
|
@ -924,7 +924,7 @@ public class MediaBindingBean {
|
|||
public File getPlexStandardPath() throws Exception {
|
||||
String path = NamingStandard.Plex.getPath(infoObject);
|
||||
try {
|
||||
path = path.concat(getSubtitleTags());
|
||||
path = path.concat(getSubtitleTags()); // NPE if {subt} is undefined
|
||||
} catch (Exception e) {
|
||||
// ignore => no language tags
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package net.filebot.media;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static net.filebot.WebServices.*;
|
||||
import static net.filebot.similarity.Normalization.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.web.EpisodeFormat.*;
|
||||
import static net.filebot.web.EpisodeUtilities.*;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -15,14 +13,11 @@ import net.filebot.web.Episode;
|
|||
import net.filebot.web.EpisodeFormat;
|
||||
import net.filebot.web.Movie;
|
||||
import net.filebot.web.MoviePart;
|
||||
import net.filebot.web.MultiEpisode;
|
||||
|
||||
public enum NamingStandard {
|
||||
|
||||
Plex;
|
||||
|
||||
public static final int TITLE_MAX_LENGTH = 150;
|
||||
|
||||
public String getPath(Object o) {
|
||||
if (o instanceof Episode)
|
||||
return getPath((Episode) o);
|
||||
|
@ -36,19 +31,19 @@ public enum NamingStandard {
|
|||
|
||||
public String getPath(Episode e) {
|
||||
// enforce title length limit by default
|
||||
String episodeTitle = truncateText(SeasonEpisode.formatMultiTitle(e instanceof MultiEpisode ? ((MultiEpisode) e).getEpisodes() : singletonList(e)), TITLE_MAX_LENGTH);
|
||||
String episodeTitle = truncateText(EpisodeFormat.SeasonEpisode.formatMultiTitle(getMultiEpisodeList(e)), TITLE_MAX_LENGTH);
|
||||
|
||||
// Anime
|
||||
if (isAnime(e)) {
|
||||
String primaryTitle = e.getSeriesInfo().getName();
|
||||
String episode = String.join(" - ", primaryTitle, EpisodeFormat.SeasonEpisode.formatSxE(e), episodeTitle);
|
||||
return path("Anime", primaryTitle, episode);
|
||||
return path(getAnimeFolder(), primaryTitle, episode);
|
||||
}
|
||||
|
||||
// TV Series
|
||||
String episode = String.join(" - ", e.getSeriesName(), EpisodeFormat.SeasonEpisode.formatS00E00(e), episodeTitle);
|
||||
String season = e.getSeason() == null ? e.getSpecial() == null ? null : "Specials" : String.format("Season %02d", e.getSeason());
|
||||
return path("TV Shows", e.getSeriesName(), season, episode);
|
||||
String season = e.getSeason() == null ? e.getSpecial() == null ? null : getSpecialFolder(e.getSeason()) : getSeasonFolder(e.getSeason());
|
||||
return path(getSeriesFolder(), e.getSeriesName(), season, episode);
|
||||
}
|
||||
|
||||
public String getPath(Movie m) {
|
||||
|
@ -60,7 +55,7 @@ public enum NamingStandard {
|
|||
name = String.format("%s CD%d", name, ((MoviePart) m).getPartIndex());
|
||||
}
|
||||
|
||||
return path("Movies", m.getNameWithYear(), name);
|
||||
return path(getMovieFolder(), m.getNameWithYear(), name);
|
||||
}
|
||||
|
||||
public String getPath(AudioTrack a) {
|
||||
|
@ -72,25 +67,47 @@ public enum NamingStandard {
|
|||
name = String.format("%02d. %s", a.getTrack(), name);
|
||||
}
|
||||
|
||||
return path("Music", first(a.getAlbumArtist(), a.getArtist()), a.getAlbum(), name);
|
||||
return path(getMusicFolder(), first(a.getAlbumArtist(), a.getArtist()), a.getAlbum(), name);
|
||||
}
|
||||
|
||||
private static String path(String... name) {
|
||||
return stream(name).filter(Objects::nonNull).map(s -> {
|
||||
s = replacePathSeparators(s, " ");
|
||||
s = replaceSpace(s, " ");
|
||||
s = normalizeQuotationMarks(s);
|
||||
s = trimTrailingPunctuation(s);
|
||||
s = validateFileName(s);
|
||||
return s;
|
||||
}).collect(joining("/"));
|
||||
}).filter(s -> s.length() > 0).collect(joining("/"));
|
||||
}
|
||||
|
||||
private static String first(String... options) {
|
||||
return stream(options).filter(Objects::nonNull).findFirst().get();
|
||||
}
|
||||
|
||||
private static boolean isAnime(Episode e) {
|
||||
return AniDB.getIdentifier().equals(e.getSeriesInfo().getDatabase());
|
||||
public String getMovieFolder() {
|
||||
return "Movies";
|
||||
}
|
||||
|
||||
public String getSeriesFolder() {
|
||||
return "TV Shows";
|
||||
}
|
||||
|
||||
public String getAnimeFolder() {
|
||||
return "Anime";
|
||||
}
|
||||
|
||||
public String getMusicFolder() {
|
||||
return "Music";
|
||||
}
|
||||
|
||||
public String getSpecialFolder(Integer season) {
|
||||
return "Specials";
|
||||
}
|
||||
|
||||
public String getSeasonFolder(Integer season) {
|
||||
return String.format("Season %02d", season == null ? 0 : season);
|
||||
}
|
||||
|
||||
public static final int TITLE_MAX_LENGTH = 150;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue