From 4f6663a385e0505bbe80eb6cc7c8976b282488e3 Mon Sep 17 00:00:00 2001
From: Reinhard Pointner
Date: Fri, 2 Mar 2012 07:08:54 +0000
Subject: [PATCH] * fixed various scripting issues and added tivo auto-sort
script
---
.../filebot/cli/CmdlineOperations.java | 8 ++---
.../filebot/cli/ScriptShell.lib.groovy | 7 ++--
.../filebot/media/MediaDetection.java | 5 ++-
website/naming.html | 2 +-
website/scripts/sortivo.groovy | 33 +++++++++++++++++++
5 files changed, 46 insertions(+), 9 deletions(-)
create mode 100644 website/scripts/sortivo.groovy
diff --git a/source/net/sourceforge/filebot/cli/CmdlineOperations.java b/source/net/sourceforge/filebot/cli/CmdlineOperations.java
index 2d22107a..d05e3114 100644
--- a/source/net/sourceforge/filebot/cli/CmdlineOperations.java
+++ b/source/net/sourceforge/filebot/cli/CmdlineOperations.java
@@ -405,7 +405,7 @@ public class CmdlineOperations implements CmdlineInterface {
File file = match.getValue();
Object movie = match.getCandidate();
String newName = (format != null) ? format.format(new MediaBindingBean(movie, file)) : validateFileName(MovieFormat.NameYear.format(movie));
- File newFile = new File(newName + "." + getExtension(file));
+ File newFile = new File(outputDir, newName + "." + getExtension(file));
if (isInvalidFilePath(newFile)) {
CLILogger.config("Stripping invalid characters from new path: " + newName);
@@ -680,7 +680,7 @@ public class CmdlineOperations implements CmdlineInterface {
public List findProbableMatches(final String query, Iterable extends SearchResult> searchResults, boolean strict) {
// auto-select most probable search result
- Map probableMatches = new TreeMap(String.CASE_INSENSITIVE_ORDER);
+ Map probableMatches = new LinkedHashMap();
// use name similarity metric
final SimilarityMetric metric = new NameSimilarityMetric();
@@ -689,8 +689,8 @@ public class CmdlineOperations implements CmdlineInterface {
for (SearchResult result : searchResults) {
float f = (query == null) ? 1 : metric.getSimilarity(query, result.getName());
if (f >= (strict ? 0.9 : 0.8) || (f >= 0.6 && result.getName().toLowerCase().startsWith(query.toLowerCase()))) {
- if (!probableMatches.containsKey(result.toString())) {
- probableMatches.put(result.toString(), result);
+ if (!probableMatches.containsKey(result.toString().toLowerCase())) {
+ probableMatches.put(result.toString().toLowerCase(), result);
}
}
}
diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy
index 0599c3c1..493600d0 100644
--- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy
+++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy
@@ -160,7 +160,8 @@ def parseEpisodeNumber(path, strict = true) {
}
def parseDate(path) {
- return new DateMetric().parse(path)
+ def input = path instanceof File ? path.name : path.toString()
+ return new DateMetric().parse(input)
}
def detectSeriesName(files, locale = Locale.ENGLISH) {
@@ -186,7 +187,7 @@ List.metaClass.sortBySimilarity = { prime, Closure toStringFunction = { obj -> o
// CLI bindings
def rename(args) { args = _defaults(args)
synchronized (_cli) {
- _guarded { _cli.rename(_files(args), args.query, args.format, args.db, args.order, args.lang, args.strict) }
+ _guarded { _cli.rename(_files(args), args.query, args.output, args.format, args.db, args.order, args.lang, args.strict) }
}
}
@@ -257,7 +258,7 @@ def _defaults(args) {
args.lang = args.lang ?: _args.lang
args.output = args.output ?: _args.output
args.encoding = args.encoding ?: _args.encoding
- args.strict = args.strict ?: !_args.nonStrict
+ args.strict = args.strict != null ? args.strict : !_args.nonStrict
return args
}
diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java
index ecd00888..9540de6a 100644
--- a/source/net/sourceforge/filebot/media/MediaDetection.java
+++ b/source/net/sourceforge/filebot/media/MediaDetection.java
@@ -358,6 +358,9 @@ public class MediaDetection {
// search for id in sibling nfo files
for (File folder : mapByFolder(files).keySet()) {
+ if (!folder.exists())
+ continue;
+
for (File nfo : folder.listFiles(MediaTypes.getDefaultFilter("application/nfo"))) {
String text = new String(readFile(nfo), "UTF-8");
@@ -452,7 +455,7 @@ public class MediaDetection {
public String normalize(String sequence) {
- return normalizePunctuation(sequence).toLowerCase(); // only normalize punctuation, make sure we keep the year (important for movie matching)
+ return normalizePunctuation(sequence); // only normalize punctuation, make sure we keep the year (important for movie matching)
}
}
diff --git a/website/naming.html b/website/naming.html
index d9cbcecc..b0e997fe 100644
--- a/website/naming.html
+++ b/website/naming.html
@@ -98,7 +98,7 @@
{n.space('.').lower()}.{s}{e.pad(2)}
dark.angel.301
- {n} ({y}) ({" CD$pi"})
The Man from Earth (2007) CD1
+ {n} ({y}) {" CD$pi"}
The Man from Earth (2007) CD1
{n} [{y}] {vf} {af}
The Man from Earth [2007] 720p 6ch
diff --git a/website/scripts/sortivo.groovy b/website/scripts/sortivo.groovy
new file mode 100644
index 00000000..b24a714e
--- /dev/null
+++ b/website/scripts/sortivo.groovy
@@ -0,0 +1,33 @@
+// filebot -script "http://filebot.sf.net/scripts/sortivo.groovy" [-non-strict] [--output path/to/folder]
+
+/*
+ * Move/Rename a mix of episodes and movies that are all in the same folder.
+ */
+args.getFiles{ it.isVideo() }.each{
+ def tvs = detectSeriesName(it)
+ def mov = detectMovie(it, false)
+
+ println "$it.name [series: $tvs, movie: $mov]"
+
+ // DECIDE EPISODE VS MOVIE (IF NOT CLEAR)
+ if (tvs && mov) {
+ if (it.name =~ "(?i:$tvs - .+)") {
+ println "Exclude Movie: $mov"
+ mov = null
+ }
+ if (detectMovie(it, true)) {
+ println "Exclude Series: $tvs"
+ tvs = null
+ }
+ }
+
+ // EPISODE MODE
+ if (tvs && !mov) {
+ return rename(file:it, format:'{n} - {s00e00} - {t}', db:'TheTVDB')
+ }
+
+ // MOVIE MODE
+ if (mov && !tvs) {
+ return rename(file:it, format:'{n} ({y}){" CD$pi"}', db:'TheMovieDB')
+ }
+}