* 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.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -29,7 +31,6 @@ import net.sourceforge.filebot.MediaTypes;
import net.sourceforge.filebot.WebServices; import net.sourceforge.filebot.WebServices;
import net.sourceforge.filebot.similarity.SeriesNameMatcher; import net.sourceforge.filebot.similarity.SeriesNameMatcher;
import net.sourceforge.filebot.web.CachedResource; import net.sourceforge.filebot.web.CachedResource;
import net.sourceforge.filebot.web.Movie;
import net.sourceforge.filebot.web.SearchResult; import net.sourceforge.filebot.web.SearchResult;
import net.sourceforge.filebot.web.TheTVDBClient.TheTVDBSearchResult; import net.sourceforge.filebot.web.TheTVDBClient.TheTVDBSearchResult;
@ -42,8 +43,12 @@ public class ReleaseInfo {
// don't allow duplicates // don't allow duplicates
Map<String, String> names = new LinkedHashMap<String, String>(); Map<String, String> names = new LinkedHashMap<String, String>();
for (SearchResult it : releaseInfo.lookupNameByInfoFile(files, Locale.ENGLISH)) { try {
names.put(it.getName().toLowerCase(), it.getName()); 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 // match common word sequence and clean detected word sequence from unwanted elements
@ -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>(); Set<SearchResult> names = new LinkedHashSet<SearchResult>();
// search for id in sibling nfo files // search for id in sibling nfo files
@ -78,14 +83,14 @@ public class ReleaseInfo {
String text = new String(readFile(nfo), "UTF-8"); String text = new String(readFile(nfo), "UTF-8");
for (int imdbid : grepImdbId(text)) { for (int imdbid : grepImdbId(text)) {
Movie movie = WebServices.OpenSubtitles.getMovieDescriptor(imdbid, language); // movies and tv shows TheTVDBSearchResult series = WebServices.TheTVDB.lookupByIMDbID(imdbid, language);
if (movie != null) { if (series != null) {
names.add(movie); names.add(series);
} }
} }
for (int tvdbid : grepTheTvdbId(text)) { 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) { if (series != null) {
names.add(series); names.add(series);
} }

View File

@ -15,9 +15,9 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Scanner; import java.util.Scanner;
import java.util.Map.Entry;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -265,6 +265,7 @@ public class OpenSubtitlesXmlRpc {
return new Movie(name, year, imdbid); return new Movie(name, year, imdbid);
} catch (RuntimeException e) { } catch (RuntimeException e) {
// ignore, invalid response // 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; 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 { try {
URL baseRecordLocation = getResource(MirrorType.XML, "/api/" + apikey + "/series/" + id + "/all/" + language.getLanguage() + ".xml"); 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); String name = selectString("//SeriesName", baseRecord);
return new TheTVDBSearchResult(name, id); return new TheTVDBSearchResult(name, id);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// illegal series id // 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; 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 @Override
public URI getEpisodeListLink(SearchResult searchResult) { public URI getEpisodeListLink(SearchResult searchResult) {
int seriesId = ((TheTVDBSearchResult) searchResult).getSeriesId(); int seriesId = ((TheTVDBSearchResult) searchResult).getSeriesId();