+ introduce {meta} tvseries/movie metadata binding

This commit is contained in:
Reinhard Pointner 2012-02-08 12:24:36 +00:00
parent 7633260147
commit f6dbc24caf
4 changed files with 151 additions and 4 deletions

View File

@ -33,6 +33,7 @@ public class MediaBindingBean {
private final Object infoObject;
private final File mediaFile;
private MediaInfo mediaInfo;
private Object metaInfo;
public MediaBindingBean(Object infoObject, File mediaFile) {
@ -303,6 +304,19 @@ public class MediaBindingBean {
}
@Define("meta")
public synchronized Object getMetaInfo() throws Exception {
if (metaInfo == null) {
if (infoObject instanceof Episode)
metaInfo = WebServices.TheTVDB.getSeriesInfoByName(((Episode) infoObject).getSeriesName(), Locale.ENGLISH);
if (infoObject instanceof Movie)
metaInfo = WebServices.TMDb.getMovieInfo((Movie) infoObject, Locale.ENGLISH);
}
return metaInfo;
}
@Define("media")
public Object getGeneralMediaInfo() {
return new AssociativeScriptObject(getMediaInfo().snapshot(StreamKind.General, 0));

View File

@ -23,12 +23,14 @@ import java.util.logging.Logger;
import javax.swing.Icon;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.filebot.web.TMDbClient.Artwork.ArtworkProperty;
import net.sourceforge.filebot.web.TMDbClient.MovieInfo.MovieProperty;
import net.sourceforge.filebot.web.TMDbClient.Person.PersonProperty;
public class TMDbClient implements MovieIdentificationService {
@ -138,12 +140,37 @@ public class TMDbClient implements MovieIdentificationService {
public MovieInfo getMovieInfo(Movie movie, Locale locale) throws Exception {
return getMovieInfoByIMDbID(movie.getImdbId(), locale);
if (movie.getImdbId() >= 0) {
return getMovieInfoByIMDbID(movie.getImdbId(), Locale.ENGLISH);
} else {
return getMovieInfoByName(movie.getName(), movie.getYear(), Locale.ENGLISH);
}
}
public MovieInfo getMovieInfoByName(String name, int year, Locale locale) throws Exception {
for (Movie it : searchMovie(name, locale)) {
if (name.equalsIgnoreCase(it.getName()) && year == it.getYear()) {
return getMovieInfo(it, locale);
}
}
return null;
}
public MovieInfo getMovieInfoByIMDbID(int imdbid, Locale locale) throws Exception {
if (imdbid < 0)
throw new IllegalArgumentException("Illegal IMDb ID: " + imdbid);
URL resource = getResource("Movie.imdbLookup", String.format("tt%07d", imdbid), locale);
Document dom = getDocument(resource);
// get complete movie info via tmdbid lookup
resource = getResource("Movie.getInfo", selectString("//movie/id", dom), locale);
dom = getDocument(resource);
// select info from xml
Node node = selectNode("//movie", getDocument(resource));
Map<MovieProperty, String> movieProperties = new EnumMap<MovieProperty, String>(MovieProperty.class);
@ -165,7 +192,16 @@ public class TMDbClient implements MovieIdentificationService {
artwork.add(new Artwork(artworkProperties));
}
return new MovieInfo(movieProperties, genres, artwork);
List<Person> cast = new ArrayList<Person>();
for (Node image : selectNodes("//person", node)) {
Map<PersonProperty, String> personProperties = new EnumMap<PersonProperty, String>(PersonProperty.class);
for (PersonProperty property : PersonProperty.values()) {
personProperties.put(property, getAttribute(property.name(), image));
}
cast.add(new Person(personProperties));
}
return new MovieInfo(movieProperties, genres, cast, artwork);
}
@ -175,6 +211,7 @@ public class TMDbClient implements MovieIdentificationService {
translated,
adult,
language,
original_name,
name,
type,
id,
@ -183,6 +220,7 @@ public class TMDbClient implements MovieIdentificationService {
overview,
votes,
rating,
tagline,
certification,
released,
runtime
@ -191,6 +229,7 @@ public class TMDbClient implements MovieIdentificationService {
protected Map<MovieProperty, String> fields;
protected String[] genres;
protected Person[] cast;
protected Artwork[] images;
@ -199,9 +238,10 @@ public class TMDbClient implements MovieIdentificationService {
}
protected MovieInfo(Map<MovieProperty, String> fields, List<String> genres, List<Artwork> images) {
protected MovieInfo(Map<MovieProperty, String> fields, List<String> genres, List<Person> cast, List<Artwork> images) {
this.fields = new EnumMap<MovieProperty, String>(fields);
this.genres = genres.toArray(new String[0]);
this.cast = cast.toArray(new Person[0]);
this.images = images.toArray(new Artwork[0]);
}
@ -235,6 +275,11 @@ public class TMDbClient implements MovieIdentificationService {
}
public String getOriginalName() {
return get(MovieProperty.original_name);
}
public String getName() {
return get(MovieProperty.name);
}
@ -296,6 +341,11 @@ public class TMDbClient implements MovieIdentificationService {
}
public String getTagline() {
return get(MovieProperty.tagline);
}
public String getCertification() {
// e.g. PG-13
return get(MovieProperty.certification);
@ -322,6 +372,11 @@ public class TMDbClient implements MovieIdentificationService {
}
public List<Person> getCast() {
return unmodifiableList(asList(cast));
}
public List<Artwork> getImages() {
return unmodifiableList(asList(images));
}
@ -411,4 +466,69 @@ public class TMDbClient implements MovieIdentificationService {
}
}
public static class Person implements Serializable {
public static enum PersonProperty {
name,
character,
job,
thumb,
department
}
protected Map<PersonProperty, String> fields;
protected Person() {
// used by serializer
}
protected Person(Map<PersonProperty, String> fields) {
this.fields = new EnumMap<PersonProperty, String>(fields);
}
public String get(Object key) {
return fields.get(PersonProperty.valueOf(key.toString()));
}
public String get(PersonProperty key) {
return fields.get(key);
}
public String getName() {
return get(PersonProperty.name);
}
public String getJob() {
return get(PersonProperty.job);
}
public String getDepartment() {
return get(PersonProperty.department);
}
public URL getThumb() {
try {
return new URL(get(PersonProperty.thumb));
} catch (Exception e) {
return null;
}
}
@Override
public String toString() {
return fields.toString();
}
}
}

View File

@ -403,6 +403,17 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
}
public SeriesInfo getSeriesInfoByName(String name, Locale locale) throws Exception {
for (SearchResult it : search(name, locale)) {
if (name.equalsIgnoreCase(it.getName())) {
return getSeriesInfo((TheTVDBSearchResult) it, locale);
}
}
return null;
}
public SeriesInfo getSeriesInfo(TheTVDBSearchResult searchResult, Locale locale) throws Exception {
// check cache first
SeriesInfo cachedItem = getCache().getData("seriesInfo", searchResult.seriesId, locale, SeriesInfo.class);

View File

@ -23,7 +23,7 @@ public class TMDbClientTest {
List<Movie> result = tmdb.searchMovie("Serenity", Locale.CHINESE);
Movie movie = result.get(0);
assertEquals("冲出宁静号", movie.getName());
assertEquals("冲出���", movie.getName());
assertEquals(2005, movie.getYear());
assertEquals(379786, movie.getImdbId());
}
@ -57,6 +57,8 @@ public class TMDbClientTest {
assertEquals("Transformers", movie.getName());
assertEquals("2007-07-03", movie.getReleased().toString());
assertEquals("Adventure", movie.getGenres().get(0));
assertEquals("Deborah Lynn Scott", movie.getCast().get(0).getName());
assertEquals("Costume Design", movie.getCast().get(0).getJob());
assertEquals("thumb", movie.getImages().get(0).getSize());
assertEquals("http://cf2.imgobject.com/t/p/w92/bgSHbGEA1OM6qDs3Qba4VlSZsNG.jpg", movie.getImages().get(0).getUrl().toString());
}