Check language in Artwork.matches() as well
This commit is contained in:
parent
90ecf3c0a7
commit
260f93e671
|
@ -15,7 +15,7 @@ public class Artwork implements Serializable {
|
|||
|
||||
private String database;
|
||||
|
||||
private String[] category;
|
||||
private String[] tags;
|
||||
private URL url;
|
||||
|
||||
private String language;
|
||||
|
@ -25,9 +25,9 @@ public class Artwork implements Serializable {
|
|||
// used by serializer
|
||||
}
|
||||
|
||||
public Artwork(Datasource database, Stream<?> category, URL url, Locale language, Double rating) {
|
||||
public Artwork(Datasource database, Stream<?> tags, URL url, Locale language, Double rating) {
|
||||
this.database = database.getIdentifier();
|
||||
this.category = category.filter(Objects::nonNull).map(Object::toString).toArray(String[]::new);
|
||||
this.tags = tags.filter(Objects::nonNull).map(Object::toString).toArray(String[]::new);
|
||||
this.url = url;
|
||||
this.language = language == null || language.getLanguage().isEmpty() ? null : language.getLanguage();
|
||||
this.rating = rating == null ? 0 : rating;
|
||||
|
@ -37,8 +37,8 @@ public class Artwork implements Serializable {
|
|||
return database;
|
||||
}
|
||||
|
||||
public List<String> getCategory() {
|
||||
return unmodifiableList(asList(category));
|
||||
public List<String> getTags() {
|
||||
return unmodifiableList(asList(tags));
|
||||
}
|
||||
|
||||
public URL getUrl() {
|
||||
|
@ -55,7 +55,7 @@ public class Artwork implements Serializable {
|
|||
|
||||
public boolean matches(String... tags) {
|
||||
return stream(tags).filter(Objects::nonNull).allMatch(tag -> {
|
||||
return stream(category).anyMatch(tag::equalsIgnoreCase) || tag.equalsIgnoreCase(language);
|
||||
return stream(tags).anyMatch(tag::equalsIgnoreCase) || tag.equalsIgnoreCase(language);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class Artwork implements Serializable {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asList(String.join("/", category), language, new DecimalFormat("0.##").format(rating), url).toString();
|
||||
return asList(String.join("/", tags), language, new DecimalFormat("0.##").format(rating), url).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -343,7 +343,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
|
|||
debug.log(Level.WARNING, e, e::getMessage);
|
||||
return null;
|
||||
}
|
||||
}).filter(Objects::nonNull).filter(it -> it.getCategory().contains(category)).collect(toList());
|
||||
}).filter(Objects::nonNull).filter(it -> it.getTags().contains(category)).collect(toList());
|
||||
}
|
||||
|
||||
protected TypedCache<SearchResult> getLookupCache(String type, Locale language) {
|
||||
|
|
|
@ -89,7 +89,7 @@ public class TMDbClientTest {
|
|||
@Test
|
||||
public void getArtwork() throws Exception {
|
||||
Artwork a = tmdb.getArtwork(16320, "backdrops", Locale.ROOT).get(0);
|
||||
assertEquals("[backdrops, 1920x1080]", a.getCategory().toString());
|
||||
assertEquals("[backdrops, 1920x1080]", a.getTags().toString());
|
||||
assertEquals("https://image.tmdb.org/t/p/original/424MxHQe5Hfu92hTeRvZb5Giv0X.jpg", a.getUrl().toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ public class TheTVDBClient2Test {
|
|||
public void getImages() throws Exception {
|
||||
Artwork i = thetvdb.getArtwork(buffy.getId(), "fanart", Locale.ENGLISH).get(0);
|
||||
|
||||
assertEquals("[fanart, 1280x720]", i.getCategory().toString());
|
||||
assertEquals("[fanart, 1280x720]", i.getTags().toString());
|
||||
assertEquals("http://thetvdb.com/banners/fanart/original/70327-1.jpg", i.getUrl().toString());
|
||||
assertTrue(i.matches("fanart", "1280x720"));
|
||||
assertFalse(i.matches("fanart", "1280x720", "1"));
|
||||
|
|
|
@ -144,11 +144,11 @@ public class TheTVDBClientTest {
|
|||
@Test
|
||||
public void getBanner() throws Exception {
|
||||
Artwork banner = thetvdb.getArtwork(buffy.getId(), "season", Locale.ROOT).stream().filter(it -> {
|
||||
return it.getCategory().contains("season") && it.getCategory().contains("seasonwide") && it.getCategory().contains("7") && it.getLanguage().equals("en");
|
||||
return it.getTags().contains("season") && it.getTags().contains("seasonwide") && it.getTags().contains("7") && it.getLanguage().equals("en");
|
||||
}).findFirst().get();
|
||||
|
||||
assertEquals("season", banner.getCategory().get(0));
|
||||
assertEquals("seasonwide", banner.getCategory().get(1));
|
||||
assertEquals("season", banner.getTags().get(0));
|
||||
assertEquals("seasonwide", banner.getTags().get(1));
|
||||
assertEquals("http://thetvdb.com/banners/seasonswide/70327-7.jpg", banner.getUrl().toString());
|
||||
assertEquals(99712, WebRequest.fetch(banner.getUrl()).remaining(), 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue