From d745be08ab4957b4b774a62981f184f14938bf60 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 20 Sep 2016 13:56:10 +0800 Subject: [PATCH] Helper for adding custom tags to the standard Plex name (after name but before subtitle language tag) e.g. plex.derive{" by $director"}{" [$vc, $ac]"} --- .../format/ExpressionFormatMethods.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/net/filebot/format/ExpressionFormatMethods.java b/source/net/filebot/format/ExpressionFormatMethods.java index f0497fe6..84c67679 100644 --- a/source/net/filebot/format/ExpressionFormatMethods.java +++ b/source/net/filebot/format/ExpressionFormatMethods.java @@ -1,7 +1,9 @@ package net.filebot.format; import static java.util.regex.Pattern.*; +import static net.filebot.MediaTypes.*; import static net.filebot.format.ExpressionFormatFunctions.*; +import static net.filebot.media.MediaDetection.*; import java.io.File; import java.io.IOException; @@ -377,6 +379,23 @@ public class ExpressionFormatMethods { /** * File utilities */ + public static File derive(File self, Object tag, Object... tagN) { + // e.g. plex.derive{" by $director"}{" [$vc, $ac]"} + String name = FileUtilities.getName(self); + String extension = self.getName().substring(name.length()); + + // e.g. Avatar (2009).eng.srt => Avatar (2009) 1080p.eng.srt + if (SUBTITLE_FILES.accept(self)) { + Matcher nameMatcher = releaseInfo.getSubtitleLanguageTagPattern().matcher(name); + if (nameMatcher.find()) { + extension = name.substring(nameMatcher.start() - 1) + extension; + name = name.substring(0, nameMatcher.start() - 1); + } + } + + return new File(self.getParentFile(), concat(name, concat(tag, null, tagN), extension)); + } + public static File getRoot(File self) { return FileUtilities.listPath(self).get(0); }