1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 08:18:52 -05:00

Unify Crew/People into new interface with default methods

This commit is contained in:
Reinhard Pointner 2016-11-01 21:22:36 +08:00
parent a24192b608
commit be6f96662a
8 changed files with 63 additions and 42 deletions

View File

@ -0,0 +1,44 @@
package net.filebot.web;
import static java.util.stream.Collectors.*;
import java.util.List;
import java.util.function.Predicate;
public interface Crew {
List<Person> getCrew();
default List<Person> getCast() {
return getCrew().stream().filter(Person::isActor).collect(toList());
}
default List<String> getActors() {
return getCrewNames(Person::isActor);
}
default List<String> getDirectors() {
return getCrewNames(Person::isDirector);
}
default List<String> getWriters() {
return getCrewNames(Person::isWriter);
}
default String getDirector() {
return getCrewName(Person::isDirector);
}
default String getWriter() {
return getCrewName(Person::isWriter);
}
default String getCrewName(Predicate<Person> filter) {
return getCrew().stream().filter(filter).map(Person::getName).findFirst().orElse(null);
}
default List<String> getCrewNames(Predicate<Person> filter) {
return getCrew().stream().filter(filter).map(Person::getName).collect(toList());
}
}

View File

@ -2,14 +2,13 @@ package net.filebot.web;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.util.stream.Collectors.*;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
public class EpisodeInfo implements Serializable {
public class EpisodeInfo implements Crew, Serializable {
protected String database;
protected Integer seriesId;
@ -64,22 +63,10 @@ public class EpisodeInfo implements Serializable {
return language;
}
public List<Person> getPeople() {
public List<Person> getCrew() {
return unmodifiableList(asList(people));
}
public List<String> getDirectors() {
return stream(people).filter(Person::isDirector).map(Person::getName).collect(toList());
}
public List<String> getWriters() {
return stream(people).filter(Person::isWriter).map(Person::getName).collect(toList());
}
public List<String> getGuestStars() {
return stream(people).filter(Person::isActor).map(Person::getName).collect(toList());
}
public String getOverview() {
return overview;
}

View File

@ -15,7 +15,7 @@ public class Person implements Serializable {
protected Integer order;
protected URL image;
protected Person() {
public Person() {
// used by serializer
}
@ -57,15 +57,15 @@ public class Person implements Serializable {
}
public boolean isActor() {
return character != null || ACTOR.equals(getJob());
return character != null || ACTOR.equals(job) || GUEST_STAR.equals(job);
}
public boolean isDirector() {
return DIRECTOR.equals(getJob());
return DIRECTOR.equals(job);
}
public boolean isWriter() {
return WRITER.equals(getJob());
return WRITER.equals(job);
}
@Override
@ -76,6 +76,7 @@ public class Person implements Serializable {
public static final String WRITER = "Writer";
public static final String DIRECTOR = "Director";
public static final String ACTOR = "Actor";
public static final String GUEST_STAR = "Guest Star";
public static final Comparator<Person> CREDIT_ORDER = comparing(Person::getOrder, nullsLast(naturalOrder()));

View File

@ -13,7 +13,7 @@ public class SearchResult implements Serializable {
protected String name;
protected String[] aliasNames;
protected SearchResult() {
public SearchResult() {
// used by serializer
}

View File

@ -408,7 +408,7 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider {
adult, backdrop_path, budget, homepage, id, imdb_id, original_title, overview, popularity, poster_path, release_date, revenue, runtime, tagline, title, vote_average, vote_count, certification, collection
}
public static class MovieInfo implements Serializable {
public static class MovieInfo implements Crew, Serializable {
protected Map<MovieProperty, String> fields;
@ -422,7 +422,7 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider {
protected Person[] people;
protected Trailer[] trailers;
protected MovieInfo() {
public MovieInfo() {
// used by serializer
}
@ -534,26 +534,10 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider {
return stream(spokenLanguages).map(Locale::new).collect(toList());
}
public List<Person> getPeople() {
public List<Person> getCrew() {
return unmodifiableList(asList(people));
}
public String getDirector() {
return stream(people).filter(Person::isDirector).map(Person::getName).findFirst().orElse(null);
}
public String getWriter() {
return stream(people).filter(Person::isWriter).map(Person::getName).findFirst().orElse(null);
}
public List<Person> getCast() {
return stream(people).filter(Person::isActor).collect(toList());
}
public List<String> getActors() {
return stream(people).filter(Person::isActor).map(Person::getName).collect(toList());
}
public Map<String, String> getCertifications() {
return unmodifiableMap(certifications); // e.g. ['US': PG-13]
}
@ -578,6 +562,7 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider {
public String toString() {
return fields.toString();
}
}
public static class Trailer implements Serializable {
@ -586,6 +571,10 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider {
protected String name;
protected Map<String, String> sources;
public Trailer() {
// used by serializer
}
public Trailer(String type, String name, Map<String, String> sources) {
this.type = type;
this.name = name;

View File

@ -309,7 +309,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
people.add(new Person(it.toString(), Person.WRITER));
}
for (Object it : getArray(data, "guestStars")) {
people.add(new Person(it.toString(), Person.ACTOR));
people.add(new Person(it.toString(), Person.GUEST_STAR));
}
return new EpisodeInfo(this, locale, seriesId, id, people, overview, rating, votes);

View File

@ -115,7 +115,7 @@ public class TMDbClientTest {
@Test
public void getPeople() throws Exception {
Person p = db.getMovieInfo("16320", Locale.ENGLISH, true).getPeople().get(0);
Person p = db.getMovieInfo("16320", Locale.ENGLISH, true).getCrew().get(0);
assertEquals("Nathan Fillion", p.getName());
assertEquals("Mal", p.getCharacter());
assertEquals(null, p.getJob());

View File

@ -175,7 +175,7 @@ public class TheTVDBClientTest {
assertEquals("When Jaye Tyler is convinced by a waxed lion to chase after a shinny quarter, she finds herself returning a lost purse to a lady (who instead of thanking her, is punched in the face), meeting an attractive and sweet bartender names Eric, introducing her sister, Sharon to the EPS newly divorced bachelor, Thomas, she knows, and later discovering her sister, Sharon's sexuality.", i.getOverview().toString());
assertEquals("[Todd Holland, Bryan Fuller, Todd Holland]", i.getDirectors().toString());
assertEquals("[Todd Holland, Bryan Fuller]", i.getWriters().toString());
assertEquals("[Scotch Ellis Loring, Gerry Fiorini, Kim Roberts, Corry Karpf, Curt Wu, Bailey Stocker, Lisa Marcos, Jorge Molina, Morgan Drmaj, Chantal Purdy, Kari Matchett, Neil Grayston, Anna Starnino, Melissa Grelo, Brandon Oakes, Scotch Ellis Loring, Ted Dykstra, Kathryn Greenwood, G]", i.getGuestStars().toString());
assertEquals("[Scotch Ellis Loring, Gerry Fiorini, Kim Roberts, Corry Karpf, Curt Wu, Bailey Stocker, Lisa Marcos, Jorge Molina, Morgan Drmaj, Chantal Purdy, Kari Matchett, Neil Grayston, Anna Starnino, Melissa Grelo, Brandon Oakes, Scotch Ellis Loring, Ted Dykstra, Kathryn Greenwood, G]", i.getActors().toString());
}
}