* use thetvdb for tvseries imdb lookups

This commit is contained in:
Reinhard Pointner 2011-12-14 01:19:36 +00:00
parent 710010b4d7
commit 66af29de7f
3 changed files with 76 additions and 56 deletions

View File

@ -22,6 +22,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -29,7 +31,6 @@ import net.sourceforge.filebot.MediaTypes;
import net.sourceforge.filebot.WebServices;
import net.sourceforge.filebot.similarity.SeriesNameMatcher;
import net.sourceforge.filebot.web.CachedResource;
import net.sourceforge.filebot.web.Movie;
import net.sourceforge.filebot.web.SearchResult;
import net.sourceforge.filebot.web.TheTVDBClient.TheTVDBSearchResult;
@ -42,9 +43,13 @@ public class ReleaseInfo {
// don't allow duplicates
Map<String, String> names = new LinkedHashMap<String, String>();
for (SearchResult it : releaseInfo.lookupNameByInfoFile(files, Locale.ENGLISH)) {
try {
for (SearchResult it : releaseInfo.lookupSeriesNameByInfoFile(files, Locale.ENGLISH)) {
names.put(it.getName().toLowerCase(), it.getName());
}
} catch (Exception e) {
Logger.getLogger(ReleaseInfo.class.getClass().getName()).log(Level.WARNING, "Failed to lookup info by id: " + e.getMessage());
}
// match common word sequence and clean detected word sequence from unwanted elements
Collection<String> matches = new SeriesNameMatcher().matchAll(files.toArray(new File[files.size()]));
@ -69,7 +74,7 @@ public class ReleaseInfo {
}
public Set<SearchResult> lookupNameByInfoFile(Collection<File> files, Locale language) throws Exception {
public Set<SearchResult> lookupSeriesNameByInfoFile(Collection<File> files, Locale language) throws Exception {
Set<SearchResult> names = new LinkedHashSet<SearchResult>();
// search for id in sibling nfo files
@ -78,14 +83,14 @@ public class ReleaseInfo {
String text = new String(readFile(nfo), "UTF-8");
for (int imdbid : grepImdbId(text)) {
Movie movie = WebServices.OpenSubtitles.getMovieDescriptor(imdbid, language); // movies and tv shows
if (movie != null) {
names.add(movie);
TheTVDBSearchResult series = WebServices.TheTVDB.lookupByIMDbID(imdbid, language);
if (series != null) {
names.add(series);
}
}
for (int tvdbid : grepTheTvdbId(text)) {
TheTVDBSearchResult series = WebServices.TheTVDB.lookup(tvdbid, language); // just tv shows
TheTVDBSearchResult series = WebServices.TheTVDB.lookupByID(tvdbid, language);
if (series != null) {
names.add(series);
}

View File

@ -15,9 +15,9 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
@ -265,6 +265,7 @@ public class OpenSubtitlesXmlRpc {
return new Movie(name, year, imdbid);
} catch (RuntimeException e) {
// ignore, invalid response
Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Failed to lookup movie by imdbid %s: %s", imdbid, e.getMessage()));
}
return null;

View File

@ -184,21 +184,35 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
}
public TheTVDBSearchResult lookup(int id, Locale language) throws Exception {
public TheTVDBSearchResult lookupByID(int id, Locale language) throws Exception {
try {
URL baseRecordLocation = getResource(MirrorType.XML, "/api/" + apikey + "/series/" + id + "/all/" + language.getLanguage() + ".xml");
Document baseRecord = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(baseRecordLocation.openStream());
Document baseRecord = getDocument(baseRecordLocation);
String name = selectString("//SeriesName", baseRecord);
return new TheTVDBSearchResult(name, id);
} catch (FileNotFoundException e) {
// illegal series id
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to retrieve base series record", e);
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to retrieve base series record: " + e.getMessage());
return null;
}
}
public TheTVDBSearchResult lookupByIMDbID(int imdbid, Locale language) throws Exception {
URL query = getResource(MirrorType.XML, "/api/GetSeriesByRemoteID.php?imdbid=" + imdbid + "&language=" + language.getLanguage());
Document dom = getDocument(query);
String id = selectString("//seriesid", dom);
String name = selectString("//SeriesName", dom);
if (id == null || id.isEmpty() || name == null || name.isEmpty())
return null;
return new TheTVDBSearchResult(name, Integer.parseInt(id));
}
@Override
public URI getEpisodeListLink(SearchResult searchResult) {
int seriesId = ((TheTVDBSearchResult) searchResult).getSeriesId();