Skip to content

Commit

Permalink
Merge pull request #98 from UweTrottmann/tv-aggregate-credits
Browse files Browse the repository at this point in the history
TvService: support aggregate credits
  • Loading branch information
UweTrottmann authored Jun 7, 2024
2 parents 5fa0ae0 + c0d046f commit 3785d12
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/uwetrottmann/tmdb2/entities/BaseTvCredit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.uwetrottmann.tmdb2.entities;

public class BaseTvCredit {

public Integer id;

public Boolean adult;
public Integer gender;
public String known_for_department;
public String name;
public String original_name;
public Double popularity;
public String profile_path;
public Integer total_episode_count;

}
16 changes: 16 additions & 0 deletions src/main/java/com/uwetrottmann/tmdb2/entities/TvCastCredit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.uwetrottmann.tmdb2.entities;

import java.util.List;

public class TvCastCredit extends BaseTvCredit {

public List<Role> roles;
public Integer order;

public static class Role {
public String credit_id;
public String character;
public Integer episode_count;
}

}
12 changes: 12 additions & 0 deletions src/main/java/com/uwetrottmann/tmdb2/entities/TvCredits.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.uwetrottmann.tmdb2.entities;

import java.util.List;

public class TvCredits {

public Integer id;

public List<TvCastCredit> cast;
public List<TvCrewCredit> crew;

}
17 changes: 17 additions & 0 deletions src/main/java/com/uwetrottmann/tmdb2/entities/TvCrewCredit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.uwetrottmann.tmdb2.entities;

import java.util.List;

public class TvCrewCredit extends BaseTvCredit {

public List<Job> jobs;
public String department;

public static class Job {
public String credit_id;
public String job;
public Integer episode_count;
}

}

16 changes: 11 additions & 5 deletions src/main/java/com/uwetrottmann/tmdb2/services/TvService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.uwetrottmann.tmdb2.entities.Status;
import com.uwetrottmann.tmdb2.entities.TmdbDate;
import com.uwetrottmann.tmdb2.entities.Translations;
import com.uwetrottmann.tmdb2.entities.TvCredits;
import com.uwetrottmann.tmdb2.entities.TvExternalIds;
import com.uwetrottmann.tmdb2.entities.TvShow;
import com.uwetrottmann.tmdb2.entities.TvShowResultsPage;
Expand Down Expand Up @@ -121,11 +122,16 @@ Call<Changes> changes(
);

/**
* Get the cast and crew information about a TV series. Just like the website, we pull this information from the
* last season of the series.
*
* @param tvShowId A Tv Show TMDb id.
* @param language <em>Optional.</em> ISO 639-1 code.
* @see <a href="https://developer.themoviedb.org/reference/tv-series-aggregate-credits">Aggregate Credits</a>
*/
@GET("tv/{tv_id}/aggregate_credits")
Call<TvCredits> aggregateCredits(
@Path("tv_id") int tvShowId,
@Query("language") String language
);

/**
* @see <a href="https://developer.themoviedb.org/reference/tv-series-credits">Credits</a>
*/
@GET("tv/{tv_id}/credits")
Call<Credits> credits(
Expand Down
53 changes: 51 additions & 2 deletions src/test/java/com/uwetrottmann/tmdb2/services/TvServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
import com.uwetrottmann.tmdb2.assertions.TvAssertions;
import com.uwetrottmann.tmdb2.entities.AlternativeTitles;
import com.uwetrottmann.tmdb2.entities.AppendToResponse;
import com.uwetrottmann.tmdb2.entities.BaseTvCredit;
import com.uwetrottmann.tmdb2.entities.Changes;
import com.uwetrottmann.tmdb2.entities.ContentRatings;
import com.uwetrottmann.tmdb2.entities.Credits;
import com.uwetrottmann.tmdb2.entities.Images;
import com.uwetrottmann.tmdb2.entities.Keywords;
import com.uwetrottmann.tmdb2.entities.TmdbDate;
import com.uwetrottmann.tmdb2.entities.Translations;
import com.uwetrottmann.tmdb2.entities.TvCastCredit;
import com.uwetrottmann.tmdb2.entities.TvCredits;
import com.uwetrottmann.tmdb2.entities.TvCrewCredit;
import com.uwetrottmann.tmdb2.entities.TvExternalIds;
import com.uwetrottmann.tmdb2.entities.TvShow;
import com.uwetrottmann.tmdb2.entities.TvShowResultsPage;
Expand Down Expand Up @@ -140,15 +144,60 @@ public void test_alternative_titles() throws IOException {
assertAlternativeTitles(titles);
}

@Test
public void test_aggregateCredits() throws IOException {
Call<TvCredits> call =
getUnauthenticatedInstance().tvService().aggregateCredits(1416 /* Grey's Anatomy */, null);
TvCredits credits = call.execute().body();
assertThat(credits).isNotNull();
assertThat(credits.id).isPositive();

assertThat(credits.cast).isNotEmpty();
// cast is ordered, so Ellen which has all values is always first
TvCastCredit ellenPompeo = credits.cast.get(0);
assertThat(ellenPompeo.order).isEqualTo(0);
assertTvCredit(ellenPompeo);
assertThat(ellenPompeo.roles).isNotEmpty();
TvCastCredit.Role role = ellenPompeo.roles.get(0);
assertThat(role.credit_id).isNotNull();
assertThat(role.character).isNotNull();
assertThat(role.episode_count).isPositive();

assertThat(credits.crew).isNotEmpty();
for (TvCrewCredit credit : credits.crew) {
// Shonda Rhimes does have all values, unlikely to be removed
if ("Shonda Rhimes".equals(credit.name)) {
assertTvCredit(credit);
assertThat(credit.jobs).isNotEmpty();
TvCrewCredit.Job job = credit.jobs.get(0);
assertThat(job.credit_id).isNotNull();
assertThat(job.job).isNotNull();
assertThat(job.episode_count).isPositive();
assertThat(credit.department).isNotNull();
break;
}
}
}

private static void assertTvCredit(BaseTvCredit credit) {
assertThat(credit.id).isPositive();
assertThat(credit.adult).isNotNull();
assertThat(credit.gender).isNotNull();
assertThat(credit.known_for_department).isNotNull();
assertThat(credit.name).isNotNull();
assertThat(credit.original_name).isNotNull();
assertThat(credit.popularity).isPositive();
assertThat(credit.profile_path).isNotNull();
assertThat(credit.total_episode_count).isPositive();
}

@Test
public void test_credits() throws IOException {
Call<Credits> call = getUnauthenticatedInstance().tvService().credits(
testTvShow.id,
null
);

Credits credits = call.execute().body();

assertCredits(credits);
}

Expand Down

0 comments on commit 3785d12

Please sign in to comment.