mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-09 22:09:47 -04:00
* revert back to imdbapi code since it's been moved and renamed to omdbapi
This commit is contained in:
parent
649a9f1e4d
commit
e3dde62618
@ -17,6 +17,7 @@ import java.nio.charset.Charset;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -35,8 +36,6 @@ import net.sourceforge.filebot.web.TMDbClient.MovieInfo;
|
|||||||
import net.sourceforge.filebot.web.TMDbClient.MovieInfo.MovieProperty;
|
import net.sourceforge.filebot.web.TMDbClient.MovieInfo.MovieProperty;
|
||||||
import net.sourceforge.filebot.web.TMDbClient.Person;
|
import net.sourceforge.filebot.web.TMDbClient.Person;
|
||||||
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.JSONValue;
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
@ -189,14 +188,20 @@ public class IMDbClient implements MovieIdentificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public Map<String, String> getImdbApiData(Integer i, String t, String y) throws IOException {
|
public Map<String, String> getImdbApiData(Integer i, String t, String y, boolean tomatoes) throws IOException {
|
||||||
String url = i != null ? String.format("http://www.deanclatworthy.com/imdb/?id=tt%07d", i) : String.format("http://www.deanclatworthy.com/imdb/?q=%s&year=%s", encode(t), encode(y));
|
// e.g. http://www.imdbapi.com/?i=tt0379786&r=xml&tomatoes=true
|
||||||
CachedResource<JSONObject> data = new CachedResource<JSONObject>(url, JSONObject.class, 7 * 24 * 60 * 60 * 1000) {
|
String url = String.format("http://www.omdbapi.com/?i=%s&t=%s&y=%s&r=xml&tomatoes=%s", String.format(i == null ? "" : "tt%07d", i), t, y, tomatoes);
|
||||||
|
CachedResource<HashMap> data = new CachedResource<HashMap>(url, HashMap.class, 7 * 24 * 60 * 60 * 1000) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject process(ByteBuffer data) throws Exception {
|
public HashMap process(ByteBuffer data) throws Exception {
|
||||||
return (JSONObject) JSONValue.parse(Charset.forName("UTF-8").decode(data).toString());
|
Document xml = getDocument(Charset.forName("UTF-8").decode(data).toString());
|
||||||
|
HashMap attr = new HashMap();
|
||||||
|
for (Node it : selectNodes("//@*", xml)) {
|
||||||
|
attr.put(it.getNodeName(), it.getTextContent());
|
||||||
|
}
|
||||||
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -211,18 +216,47 @@ public class IMDbClient implements MovieIdentificationService {
|
|||||||
|
|
||||||
|
|
||||||
public MovieInfo getImdbApiMovieInfo(Movie movie) throws IOException {
|
public MovieInfo getImdbApiMovieInfo(Movie movie) throws IOException {
|
||||||
Map<String, String> data = movie.getImdbId() > 0 ? getImdbApiData(movie.getImdbId(), null, null) : getImdbApiData(null, movie.getName(), String.valueOf(movie.getYear()));
|
Map<String, String> data = movie.getImdbId() > 0 ? getImdbApiData(movie.getImdbId(), "", "", false) : getImdbApiData(null, movie.getName(), String.valueOf(movie.getYear()), false);
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
if (data.get("error") != null) {
|
if (!Boolean.parseBoolean(data.get("response"))) {
|
||||||
throw new IllegalArgumentException(data.get("error"));
|
throw new IllegalArgumentException("Movie not found: " + data);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<MovieProperty, String> fields = new EnumMap<MovieProperty, String>(MovieProperty.class);
|
Map<MovieProperty, String> fields = new EnumMap<MovieProperty, String>(MovieProperty.class);
|
||||||
fields.put(MovieProperty.vote_average, data.get("rating"));
|
fields.put(MovieProperty.title, data.get("title"));
|
||||||
fields.put(MovieProperty.vote_count, data.get("votes"));
|
fields.put(MovieProperty.certification, data.get("rated"));
|
||||||
fields.put(MovieProperty.imdb_id, data.get("imdbid"));
|
fields.put(MovieProperty.runtime, data.get("runtime"));
|
||||||
|
fields.put(MovieProperty.tagline, data.get("plot"));
|
||||||
|
fields.put(MovieProperty.vote_average, data.get("imdbRating"));
|
||||||
|
fields.put(MovieProperty.vote_count, data.get("imdbVotes").replaceAll("\\D", ""));
|
||||||
|
fields.put(MovieProperty.imdb_id, data.get("imdbID"));
|
||||||
|
fields.put(MovieProperty.poster_path, data.get("poster"));
|
||||||
|
|
||||||
return new MovieInfo(fields, new ArrayList<String>(0), new ArrayList<String>(0), new ArrayList<Person>(0));
|
// convert release date to yyyy-MM-dd
|
||||||
|
Date released = Date.parse(data.get("Released"), "dd MMM yyyy");
|
||||||
|
if (released != null) {
|
||||||
|
fields.put(MovieProperty.release_date, released.format("yyyy-MM-dd"));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> genres = new ArrayList<String>();
|
||||||
|
for (String it : data.get("genre").split(",")) {
|
||||||
|
genres.add(it.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Person> actors = new ArrayList<Person>();
|
||||||
|
for (String it : data.get("actors").split(",")) {
|
||||||
|
actors.add(new Person(it.trim(), null, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String director : data.get("director").split(",")) {
|
||||||
|
actors.add(new Person(director, null, "Director"));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String writer : data.get("writer").split(",")) {
|
||||||
|
actors.add(new Person(writer, null, "Writer"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MovieInfo(fields, genres, new ArrayList<String>(0), actors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -435,12 +435,8 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Integer getRuntime() {
|
public String getRuntime() {
|
||||||
try {
|
return get(MovieProperty.runtime);
|
||||||
return new Integer(get(MovieProperty.runtime));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -449,7 +445,7 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<Person> getPeope() {
|
public List<Person> getPeople() {
|
||||||
return unmodifiableList(asList(people));
|
return unmodifiableList(asList(people));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,6 +470,15 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getWriter() {
|
||||||
|
for (Person person : people) {
|
||||||
|
if (person.isWriter())
|
||||||
|
return person.getName();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<String> getActors() {
|
public List<String> getActors() {
|
||||||
List<String> actors = new ArrayList<String>();
|
List<String> actors = new ArrayList<String>();
|
||||||
for (Person actor : getCast()) {
|
for (Person actor : getCast()) {
|
||||||
@ -483,6 +488,15 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public URL getPoster() {
|
||||||
|
try {
|
||||||
|
return new URL(get(MovieProperty.poster_path));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return fields.toString();
|
return fields.toString();
|
||||||
@ -552,6 +566,11 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isWriter() {
|
||||||
|
return "Writer".equals(getJob());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return fields.toString();
|
return fields.toString();
|
||||||
|
@ -362,9 +362,14 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>info</td>
|
<td>info</td>
|
||||||
<td>TheMovieDB / TheTVDB info</td>
|
<td><a href="http://www.themoviedb.org/">TheMovieDB</a> / <a href="http://thetvdb.com/">TheTVDB</a> info</td>
|
||||||
<td><any movie / series info></td>
|
<td><any movie / series info></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>imdb</td>
|
||||||
|
<td><a href="http://www.omdbapi.com/">OMDb</a> info</td>
|
||||||
|
<td><any movie info></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>file</td>
|
<td>file</td>
|
||||||
<td>file object</td>
|
<td>file object</td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user