mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-25 01:08:52 -05:00
refactor number parsing
This commit is contained in:
parent
49561dd944
commit
9cc353e981
@ -1,11 +1,12 @@
|
|||||||
package net.filebot.archive;
|
package net.filebot.archive;
|
||||||
|
|
||||||
|
import static net.filebot.util.StringUtilities.*;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -94,8 +95,8 @@ public class Archive implements Closeable {
|
|||||||
|
|
||||||
Matcher matcher = volume.matcher(path.getName());
|
Matcher matcher = volume.matcher(path.getName());
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
Scanner scanner = new Scanner(matcher.group()).useDelimiter("\\D+");
|
Integer i = matchInteger(matcher.group());
|
||||||
if (!scanner.hasNext() || scanner.nextInt() != 1) {
|
if (i == null || i != 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,7 @@ public class MediaDetection {
|
|||||||
for (File path : listPathTail(f, 2, true)) {
|
for (File path : listPathTail(f, 2, true)) {
|
||||||
String fn = getName(path);
|
String fn = getName(path);
|
||||||
// ignore non-strict series name parsing if there are movie year patterns
|
// ignore non-strict series name parsing if there are movie year patterns
|
||||||
if (!strict && parseMovieYear(fn).equals(parseNumbers(fn))) {
|
if (!strict && parseMovieYear(fn).equals(matchIntegers(fn))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
String sn = seriesNameMatcher.matchByEpisodeIdentifier(fn);
|
String sn = seriesNameMatcher.matchByEpisodeIdentifier(fn);
|
||||||
@ -763,27 +763,7 @@ public class MediaDetection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<Integer> parseMovieYear(String name) {
|
public static List<Integer> parseMovieYear(String name) {
|
||||||
List<Integer> years = new ArrayList<Integer>();
|
return matchIntegers(name).stream().filter(year -> 1950 < year && year < 2050).collect(Collectors.toList());
|
||||||
for (String it : name.split("\\D+")) {
|
|
||||||
if (it.length() == 4) {
|
|
||||||
int year = Integer.parseInt(it);
|
|
||||||
if (1950 < year && year < 2050) {
|
|
||||||
years.add(year);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return years;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Integer> parseNumbers(String name) {
|
|
||||||
List<Integer> numbers = new ArrayList<Integer>();
|
|
||||||
for (String it : name.split("\\D+")) {
|
|
||||||
if (it.length() > 0) {
|
|
||||||
int n = Integer.parseInt(it);
|
|
||||||
numbers.add(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return numbers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String reduceMovieName(String name, boolean strict) throws IOException {
|
public static String reduceMovieName(String name, boolean strict) throws IOException {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.filebot.similarity;
|
package net.filebot.similarity;
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
import static java.lang.Math.*;
|
||||||
|
import static java.util.Arrays.*;
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
import static java.util.regex.Pattern.*;
|
import static java.util.regex.Pattern.*;
|
||||||
import static net.filebot.media.MediaDetection.*;
|
import static net.filebot.media.MediaDetection.*;
|
||||||
@ -19,7 +20,6 @@ import java.util.LinkedHashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -451,11 +451,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// simplify file name if possible and extract numbers
|
// simplify file name if possible and extract numbers
|
||||||
List<String> numbers = new ArrayList<String>(4);
|
List<Integer> numbers = matchIntegers(normalizeObject(object));
|
||||||
Scanner scanner = new Scanner(normalizeObject(object)).useDelimiter("\\D+");
|
|
||||||
while (scanner.hasNextInt()) {
|
|
||||||
numbers.add(String.valueOf(scanner.nextInt()));
|
|
||||||
}
|
|
||||||
return join(numbers, " ");
|
return join(numbers, " ");
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
|
|
||||||
package net.filebot.similarity;
|
package net.filebot.similarity;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import uk.ac.shef.wit.simmetrics.similaritymetrics.AbstractStringMetric;
|
import uk.ac.shef.wit.simmetrics.similaritymetrics.AbstractStringMetric;
|
||||||
import uk.ac.shef.wit.simmetrics.similaritymetrics.QGramsDistance;
|
import uk.ac.shef.wit.simmetrics.similaritymetrics.QGramsDistance;
|
||||||
@ -13,78 +12,65 @@ import uk.ac.shef.wit.simmetrics.tokenisers.InterfaceTokeniser;
|
|||||||
import uk.ac.shef.wit.simmetrics.wordhandlers.DummyStopTermHandler;
|
import uk.ac.shef.wit.simmetrics.wordhandlers.DummyStopTermHandler;
|
||||||
import uk.ac.shef.wit.simmetrics.wordhandlers.InterfaceTermHandler;
|
import uk.ac.shef.wit.simmetrics.wordhandlers.InterfaceTermHandler;
|
||||||
|
|
||||||
|
|
||||||
public class NumericSimilarityMetric implements SimilarityMetric {
|
public class NumericSimilarityMetric implements SimilarityMetric {
|
||||||
|
|
||||||
private final AbstractStringMetric metric;
|
private final AbstractStringMetric metric;
|
||||||
|
|
||||||
|
|
||||||
public NumericSimilarityMetric() {
|
public NumericSimilarityMetric() {
|
||||||
// I don't exactly know why, but I get a good matching behavior
|
// I don't exactly know why, but I get a good matching behavior
|
||||||
// when using QGramsDistance or BlockDistance
|
// when using QGramsDistance or BlockDistance
|
||||||
metric = new QGramsDistance(new NumberTokeniser());
|
metric = new QGramsDistance(new NumberTokeniser());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getSimilarity(Object o1, Object o2) {
|
public float getSimilarity(Object o1, Object o2) {
|
||||||
return metric.getSimilarity(normalize(o1), normalize(o2));
|
return metric.getSimilarity(normalize(o1), normalize(o2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected String normalize(Object object) {
|
protected String normalize(Object object) {
|
||||||
// no need to do anything special here, because we don't care about anything but number patterns anyway
|
// no need to do anything special here, because we don't care about anything but number patterns anyway
|
||||||
return object.toString();
|
return object.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class NumberTokeniser implements InterfaceTokeniser {
|
private static class NumberTokeniser implements InterfaceTokeniser {
|
||||||
|
|
||||||
private final String delimiter = "\\D+";
|
private static final Pattern DIGIT = Pattern.compile("\\d+");
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<String> tokenizeToArrayList(String input) {
|
public ArrayList<String> tokenizeToArrayList(String s) {
|
||||||
ArrayList<String> tokens = new ArrayList<String>();
|
ArrayList<String> tokens = new ArrayList<String>();
|
||||||
|
|
||||||
// scan for number patterns, use non-number pattern as delimiter
|
Matcher m = DIGIT.matcher(s);
|
||||||
Scanner scanner = new Scanner(input).useDelimiter(delimiter);
|
while (m.find()) {
|
||||||
|
// remove leading zeros
|
||||||
while (scanner.hasNextInt()) {
|
tokens.add(new Integer(m.group()).toString());
|
||||||
// remove leading zeros from number tokens by scanning for Integers
|
|
||||||
tokens.add(String.valueOf(scanner.nextInt()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDelimiters() {
|
||||||
|
return "\\D+";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> tokenizeToSet(String input) {
|
public Set<String> tokenizeToSet(String input) {
|
||||||
return new LinkedHashSet<String>(tokenizeToArrayList(input));
|
return new LinkedHashSet<String>(tokenizeToArrayList(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getShortDescriptionString() {
|
public String getShortDescriptionString() {
|
||||||
return getClass().getSimpleName();
|
return getClass().getSimpleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDelimiters() {
|
|
||||||
return delimiter;
|
|
||||||
}
|
|
||||||
|
|
||||||
private InterfaceTermHandler stopWordHandler = new DummyStopTermHandler();
|
private InterfaceTermHandler stopWordHandler = new DummyStopTermHandler();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InterfaceTermHandler getStopWordHandler() {
|
public InterfaceTermHandler getStopWordHandler() {
|
||||||
return stopWordHandler;
|
return stopWordHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStopWordHandler(InterfaceTermHandler stopWordHandler) {
|
public void setStopWordHandler(InterfaceTermHandler stopWordHandler) {
|
||||||
this.stopWordHandler = stopWordHandler;
|
this.stopWordHandler = stopWordHandler;
|
||||||
|
@ -3,6 +3,7 @@ package net.filebot.similarity;
|
|||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
import static java.util.regex.Pattern.*;
|
import static java.util.regex.Pattern.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
import static net.filebot.util.FileUtilities.*;
|
||||||
|
import static net.filebot.util.StringUtilities.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -10,7 +11,6 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.MatchResult;
|
import java.util.regex.MatchResult;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -54,9 +54,9 @@ public class SeasonEpisodeMatcher {
|
|||||||
@Override
|
@Override
|
||||||
protected Collection<SxE> process(MatchResult match) {
|
protected Collection<SxE> process(MatchResult match) {
|
||||||
List<SxE> matches = new ArrayList<SxE>(2);
|
List<SxE> matches = new ArrayList<SxE>(2);
|
||||||
Scanner epno = new Scanner(match.group(2)).useDelimiter("\\D+");
|
int seasonNumber = Integer.parseInt(match.group(1));
|
||||||
while (epno.hasNext()) {
|
for (int episodeNumber : matchIntegers(match.group(2))) {
|
||||||
matches.add(new SxE(match.group(1), epno.next()));
|
matches.add(new SxE(seasonNumber, episodeNumber));
|
||||||
}
|
}
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
@ -68,9 +68,9 @@ public class SeasonEpisodeMatcher {
|
|||||||
@Override
|
@Override
|
||||||
protected Collection<SxE> process(MatchResult match) {
|
protected Collection<SxE> process(MatchResult match) {
|
||||||
List<SxE> matches = new ArrayList<SxE>(2);
|
List<SxE> matches = new ArrayList<SxE>(2);
|
||||||
String[] num = match.group(0).split("\\D+");
|
String[] numbers = NON_DIGIT.split(match.group(0));
|
||||||
for (int i = 0; i < num.length; i += 2) {
|
for (int i = 0; i < numbers.length; i += 2) {
|
||||||
matches.add(new SxE(num[i], num[i + 1])); // SxE-SxE-SxE
|
matches.add(new SxE(numbers[i], numbers[i + 1])); // SxE-SxE-SxE
|
||||||
}
|
}
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
@ -82,9 +82,9 @@ public class SeasonEpisodeMatcher {
|
|||||||
@Override
|
@Override
|
||||||
protected Collection<SxE> process(MatchResult match) {
|
protected Collection<SxE> process(MatchResult match) {
|
||||||
List<SxE> matches = new ArrayList<SxE>(2);
|
List<SxE> matches = new ArrayList<SxE>(2);
|
||||||
Scanner epno = new Scanner(match.group(2)).useDelimiter("\\D+");
|
int seasonNumber = Integer.parseInt(match.group(1));
|
||||||
while (epno.hasNext()) {
|
for (int episodeNumber : matchIntegers(match.group(2))) {
|
||||||
matches.add(new SxE(match.group(1), epno.next()));
|
matches.add(new SxE(seasonNumber, episodeNumber));
|
||||||
}
|
}
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
@ -96,9 +96,9 @@ public class SeasonEpisodeMatcher {
|
|||||||
@Override
|
@Override
|
||||||
protected Collection<SxE> process(MatchResult match) {
|
protected Collection<SxE> process(MatchResult match) {
|
||||||
List<SxE> matches = new ArrayList<SxE>(2);
|
List<SxE> matches = new ArrayList<SxE>(2);
|
||||||
Scanner epno = new Scanner(match.group(2)).useDelimiter("\\D+");
|
int seasonNumber = Integer.parseInt(match.group(1));
|
||||||
while (epno.hasNext()) {
|
for (int episodeNumber : matchIntegers(match.group(2))) {
|
||||||
matches.add(new SxE(match.group(1), epno.next()));
|
matches.add(new SxE(seasonNumber, episodeNumber));
|
||||||
}
|
}
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,44 @@
|
|||||||
package net.filebot.util;
|
package net.filebot.util;
|
||||||
|
|
||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.*;
|
||||||
|
import static java.util.Collections.*;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class StringUtilities {
|
public final class StringUtilities {
|
||||||
|
|
||||||
|
public static final Pattern DIGIT = Pattern.compile("\\d+");
|
||||||
|
public static final Pattern NON_DIGIT = Pattern.compile("\\D+");
|
||||||
|
|
||||||
|
public static List<Integer> matchIntegers(CharSequence s) {
|
||||||
|
if (s == null || s.length() == 0) {
|
||||||
|
return emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Integer> numbers = new ArrayList<Integer>();
|
||||||
|
Matcher matcher = DIGIT.matcher(s);
|
||||||
|
while (matcher.find()) {
|
||||||
|
numbers.add(new Integer(matcher.group()));
|
||||||
|
}
|
||||||
|
return numbers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer matchInteger(CharSequence s) {
|
||||||
|
if (s == null || s.length() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher matcher = DIGIT.matcher(s);
|
||||||
|
if (matcher.find()) {
|
||||||
|
return new Integer(matcher.group());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static String asString(Object object) {
|
public static String asString(Object object) {
|
||||||
return object == null ? null : object.toString();
|
return object == null ? null : object.toString();
|
||||||
}
|
}
|
||||||
@ -28,7 +60,7 @@ public final class StringUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String joinSorted(Object[] values, CharSequence delimiter, Comparator<Object> sort, CharSequence start, CharSequence end) {
|
public static String joinSorted(Object[] values, CharSequence delimiter, Comparator<Object> sort, CharSequence start, CharSequence end) {
|
||||||
return join(Arrays.stream(values).sorted(sort)::iterator, delimiter, start, end);
|
return join(stream(values).sorted(sort)::iterator, delimiter, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String join(Iterable<?> values, CharSequence delimiter, CharSequence start, CharSequence end) {
|
public static String join(Iterable<?> values, CharSequence delimiter, CharSequence start, CharSequence end) {
|
||||||
|
@ -3,8 +3,6 @@ package net.filebot.util;
|
|||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
import javax.xml.xpath.XPathConstants;
|
import javax.xml.xpath.XPathConstants;
|
||||||
@ -126,14 +124,6 @@ public final class XPathUtilities {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Integer getInteger(String textContent) {
|
|
||||||
try {
|
|
||||||
return new Scanner(textContent).useDelimiter("\\D+").nextInt();
|
|
||||||
} catch (NumberFormatException | NoSuchElementException | NullPointerException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Double getDecimal(String textContent) {
|
public static Double getDecimal(String textContent) {
|
||||||
try {
|
try {
|
||||||
return new Double(textContent);
|
return new Double(textContent);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.filebot.web;
|
package net.filebot.web;
|
||||||
|
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
|
import static net.filebot.util.StringUtilities.*;
|
||||||
import static net.filebot.util.XPathUtilities.*;
|
import static net.filebot.util.XPathUtilities.*;
|
||||||
import static net.filebot.web.EpisodeUtilities.*;
|
import static net.filebot.web.EpisodeUtilities.*;
|
||||||
import static net.filebot.web.WebRequest.*;
|
import static net.filebot.web.WebRequest.*;
|
||||||
@ -123,7 +124,7 @@ public class AnidbClient extends AbstractEpisodeListProvider {
|
|||||||
|
|
||||||
seriesInfo.setName(selectString("anime/titles/title[@type='main']", dom));
|
seriesInfo.setName(selectString("anime/titles/title[@type='main']", dom));
|
||||||
seriesInfo.setRating(getDecimal(selectString("anime/ratings/permanent", dom)));
|
seriesInfo.setRating(getDecimal(selectString("anime/ratings/permanent", dom)));
|
||||||
seriesInfo.setRatingCount(getInteger(getTextContent("anime/ratings/permanent/@count", dom)));
|
seriesInfo.setRatingCount(matchInteger(getTextContent("anime/ratings/permanent/@count", dom)));
|
||||||
seriesInfo.setStartDate(SimpleDate.parse(selectString("anime/startdate", dom), "yyyy-MM-dd"));
|
seriesInfo.setStartDate(SimpleDate.parse(selectString("anime/startdate", dom), "yyyy-MM-dd"));
|
||||||
|
|
||||||
// add categories ordered by weight as genres
|
// add categories ordered by weight as genres
|
||||||
@ -132,7 +133,7 @@ public class AnidbClient extends AbstractEpisodeListProvider {
|
|||||||
// * limit to 5 genres
|
// * limit to 5 genres
|
||||||
seriesInfo.setGenres(selectNodes("anime/categories/category", dom).stream().map(categoryNode -> {
|
seriesInfo.setGenres(selectNodes("anime/categories/category", dom).stream().map(categoryNode -> {
|
||||||
String name = getTextContent("name", categoryNode);
|
String name = getTextContent("name", categoryNode);
|
||||||
Integer weight = getInteger(getAttribute("weight", categoryNode));
|
Integer weight = matchInteger(getAttribute("weight", categoryNode));
|
||||||
return new SimpleImmutableEntry<String, Integer>(name, weight);
|
return new SimpleImmutableEntry<String, Integer>(name, weight);
|
||||||
}).filter(nw -> {
|
}).filter(nw -> {
|
||||||
return nw.getKey() != null && nw.getValue() != null && nw.getKey().length() > 0 && nw.getValue() >= 400;
|
return nw.getKey() != null && nw.getValue() != null && nw.getKey().length() > 0 && nw.getValue() >= 400;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package net.filebot.web;
|
package net.filebot.web;
|
||||||
|
|
||||||
|
import static net.filebot.util.StringUtilities.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -83,15 +83,7 @@ public class ID3Lookup implements MusicIdentificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Integer getInteger(MediaInfo mediaInfo, String field) {
|
private Integer getInteger(MediaInfo mediaInfo, String field) {
|
||||||
String value = getString(mediaInfo, field);
|
return matchInteger(getString(mediaInfo, field));
|
||||||
if (value != null) {
|
|
||||||
try {
|
|
||||||
return new Scanner(value).useDelimiter("\\D+").nextInt();
|
|
||||||
} catch (NumberFormatException | NoSuchElementException e) {
|
|
||||||
Logger.getLogger(ID3Lookup.class.getName()).log(Level.WARNING, e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.filebot.web;
|
package net.filebot.web;
|
||||||
|
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
|
import static net.filebot.util.StringUtilities.*;
|
||||||
import static net.filebot.web.WebRequest.*;
|
import static net.filebot.web.WebRequest.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -17,7 +18,6 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -123,7 +123,7 @@ public class OMDbClient implements MovieIdentificationService {
|
|||||||
public Movie getMovie(Map<String, String> info) {
|
public Movie getMovie(Map<String, String> info) {
|
||||||
try {
|
try {
|
||||||
String name = info.get("Title");
|
String name = info.get("Title");
|
||||||
int year = new Scanner(info.get("Year")).useDelimiter("\\D+").nextInt();
|
int year = matchInteger(info.get("Year"));
|
||||||
int imdbid = Integer.parseInt(info.get("imdbID").replace("tt", ""));
|
int imdbid = Integer.parseInt(info.get("imdbID").replace("tt", ""));
|
||||||
|
|
||||||
if (name.length() <= 0 || year <= 1900 || imdbid <= 0)
|
if (name.length() <= 0 || year <= 1900 || imdbid <= 0)
|
||||||
|
@ -2,6 +2,7 @@ package net.filebot.web;
|
|||||||
|
|
||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.*;
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
|
import static net.filebot.util.StringUtilities.*;
|
||||||
import static net.filebot.web.WebRequest.*;
|
import static net.filebot.web.WebRequest.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -22,7 +23,6 @@ import java.util.LinkedHashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -110,7 +110,7 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
id = Float.valueOf(it.get("id").toString()).intValue();
|
id = Float.valueOf(it.get("id").toString()).intValue();
|
||||||
try {
|
try {
|
||||||
String release = (String) it.get("release_date");
|
String release = (String) it.get("release_date");
|
||||||
year = new Scanner(release).useDelimiter("\\D+").nextInt();
|
year = matchInteger(release);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException("Missing data: release date");
|
throw new IllegalArgumentException("Missing data: release date");
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package net.filebot.web;
|
|||||||
|
|
||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.*;
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
|
import static net.filebot.util.StringUtilities.*;
|
||||||
import static net.filebot.util.XPathUtilities.*;
|
import static net.filebot.util.XPathUtilities.*;
|
||||||
import static net.filebot.web.EpisodeUtilities.*;
|
import static net.filebot.web.EpisodeUtilities.*;
|
||||||
import static net.filebot.web.WebRequest.*;
|
import static net.filebot.web.WebRequest.*;
|
||||||
@ -104,7 +105,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||||||
Map<Integer, TheTVDBSearchResult> resultSet = new LinkedHashMap<Integer, TheTVDBSearchResult>();
|
Map<Integer, TheTVDBSearchResult> resultSet = new LinkedHashMap<Integer, TheTVDBSearchResult>();
|
||||||
|
|
||||||
for (Node node : nodes) {
|
for (Node node : nodes) {
|
||||||
int sid = getInteger(getTextContent("seriesid", node));
|
int sid = matchInteger(getTextContent("seriesid", node));
|
||||||
String seriesName = getTextContent("SeriesName", node);
|
String seriesName = getTextContent("SeriesName", node);
|
||||||
|
|
||||||
List<String> aliasNames = new ArrayList<String>();
|
List<String> aliasNames = new ArrayList<String>();
|
||||||
@ -144,8 +145,8 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||||||
seriesInfo.setStatus(getTextContent("Status", seriesNode));
|
seriesInfo.setStatus(getTextContent("Status", seriesNode));
|
||||||
|
|
||||||
seriesInfo.setRating(getDecimal(getTextContent("Rating", seriesNode)));
|
seriesInfo.setRating(getDecimal(getTextContent("Rating", seriesNode)));
|
||||||
seriesInfo.setRatingCount(getInteger(getTextContent("RatingCount", seriesNode)));
|
seriesInfo.setRatingCount(matchInteger(getTextContent("RatingCount", seriesNode)));
|
||||||
seriesInfo.setRuntime(getInteger(getTextContent("Runtime", seriesNode)));
|
seriesInfo.setRuntime(matchInteger(getTextContent("Runtime", seriesNode)));
|
||||||
seriesInfo.setActors(getListContent("Actors", "\\|", seriesNode));
|
seriesInfo.setActors(getListContent("Actors", "\\|", seriesNode));
|
||||||
seriesInfo.setGenres(getListContent("Genre", "\\|", seriesNode));
|
seriesInfo.setGenres(getListContent("Genre", "\\|", seriesNode));
|
||||||
seriesInfo.setStartDate(SimpleDate.parse(getTextContent("FirstAired", seriesNode), "yyyy-MM-dd"));
|
seriesInfo.setStartDate(SimpleDate.parse(getTextContent("FirstAired", seriesNode), "yyyy-MM-dd"));
|
||||||
@ -162,17 +163,17 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||||||
|
|
||||||
for (Node node : nodes) {
|
for (Node node : nodes) {
|
||||||
String episodeName = getTextContent("EpisodeName", node);
|
String episodeName = getTextContent("EpisodeName", node);
|
||||||
Integer absoluteNumber = getInteger(getTextContent("absolute_number", node));
|
Integer absoluteNumber = matchInteger(getTextContent("absolute_number", node));
|
||||||
SimpleDate airdate = SimpleDate.parse(getTextContent("FirstAired", node), "yyyy-MM-dd");
|
SimpleDate airdate = SimpleDate.parse(getTextContent("FirstAired", node), "yyyy-MM-dd");
|
||||||
|
|
||||||
// default numbering
|
// default numbering
|
||||||
Integer episodeNumber = getInteger(getTextContent("EpisodeNumber", node));
|
Integer episodeNumber = matchInteger(getTextContent("EpisodeNumber", node));
|
||||||
Integer seasonNumber = getInteger(getTextContent("SeasonNumber", node));
|
Integer seasonNumber = matchInteger(getTextContent("SeasonNumber", node));
|
||||||
|
|
||||||
// adjust for DVD numbering if possible
|
// adjust for DVD numbering if possible
|
||||||
if (sortOrder == SortOrder.DVD) {
|
if (sortOrder == SortOrder.DVD) {
|
||||||
Integer dvdSeasonNumber = getInteger(getTextContent("DVD_season", node));
|
Integer dvdSeasonNumber = matchInteger(getTextContent("DVD_season", node));
|
||||||
Integer dvdEpisodeNumber = getInteger(getTextContent("DVD_episodenumber", node));
|
Integer dvdEpisodeNumber = matchInteger(getTextContent("DVD_episodenumber", node));
|
||||||
|
|
||||||
// require both values to be valid integer numbers
|
// require both values to be valid integer numbers
|
||||||
if (dvdSeasonNumber != null && dvdEpisodeNumber != null) {
|
if (dvdSeasonNumber != null && dvdEpisodeNumber != null) {
|
||||||
@ -185,7 +186,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
|||||||
if (seasonNumber == null || seasonNumber == 0) {
|
if (seasonNumber == null || seasonNumber == 0) {
|
||||||
// handle as special episode
|
// handle as special episode
|
||||||
for (String specialSeasonTag : new String[] { "airsafter_season", "airsbefore_season" }) {
|
for (String specialSeasonTag : new String[] { "airsafter_season", "airsbefore_season" }) {
|
||||||
Integer specialSeason = getInteger(getTextContent(specialSeasonTag, node));
|
Integer specialSeason = matchInteger(getTextContent(specialSeasonTag, node));
|
||||||
if (specialSeason != null && specialSeason != 0) {
|
if (specialSeason != null && specialSeason != 0) {
|
||||||
seasonNumber = specialSeason;
|
seasonNumber = specialSeason;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user