Skip to content

Commit 6358001

Browse files
committed
Add Watch Providers service with methods for movies and TV shows
1 parent bd0b413 commit 6358001

File tree

8 files changed

+125
-35
lines changed

8 files changed

+125
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Next version
44

55
* Add TV season translations method by @laurentblue in https://github.com/UweTrottmann/tmdb-java/pull/108
6+
* Add Watch Providers service with methods for movies and TV shows.
67

78
## 2.12.0 - 2025-08-08
89

src/main/java/com/uwetrottmann/tmdb2/Tmdb.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.uwetrottmann.tmdb2.services.TvEpisodesService;
3434
import com.uwetrottmann.tmdb2.services.TvSeasonsService;
3535
import com.uwetrottmann.tmdb2.services.TvService;
36+
import com.uwetrottmann.tmdb2.services.WatchProvidersService;
3637
import java.io.IOException;
3738
import javax.annotation.Nullable;
3839
import okhttp3.Interceptor;
@@ -309,6 +310,14 @@ public DiscoverService discoverService() {
309310
return getRetrofit().create(DiscoverService.class);
310311
}
311312

313+
public DiscoverMovieBuilder discoverMovie() {
314+
return new DiscoverMovieBuilder(discoverService());
315+
}
316+
317+
public DiscoverTvBuilder discoverTv() {
318+
return new DiscoverTvBuilder(discoverService());
319+
}
320+
312321
public FindService findService() {
313322
return getRetrofit().create(FindService.class);
314323
}
@@ -369,12 +378,8 @@ public TrendingService trendingService() {
369378
return getRetrofit().create(TrendingService.class);
370379
}
371380

372-
public DiscoverMovieBuilder discoverMovie() {
373-
return new DiscoverMovieBuilder(discoverService());
374-
}
375-
376-
public DiscoverTvBuilder discoverTv() {
377-
return new DiscoverTvBuilder(discoverService());
381+
public WatchProvidersService watchProvidersService() {
382+
return getRetrofit().create(WatchProvidersService.class);
378383
}
379384

380385
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright 2025 Uwe Trottmann
3+
4+
package com.uwetrottmann.tmdb2.entities;
5+
6+
7+
import java.util.List;
8+
9+
public class WatchProvidersResults {
10+
11+
public List<WatchProviders.WatchProvider> results;
12+
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright 2025 Uwe Trottmann
3+
4+
package com.uwetrottmann.tmdb2.services;
5+
6+
7+
import com.uwetrottmann.tmdb2.entities.WatchProvidersResults;
8+
import retrofit2.Call;
9+
import retrofit2.http.GET;
10+
import retrofit2.http.Query;
11+
12+
public interface WatchProvidersService {
13+
14+
/**
15+
* See <a href="https://developer.themoviedb.org/reference/watch-providers-movie-list">Movie Providers</a>.
16+
*/
17+
@GET("watch/providers/movie")
18+
Call<WatchProvidersResults> movie(
19+
@Query("language") String language,
20+
@Query("watch_region") String watchRegion
21+
);
22+
23+
/**
24+
* See <a href="https://developer.themoviedb.org/reference/watch-provider-tv-list">TV Providers</a>.
25+
*/
26+
@GET("watch/providers/tv")
27+
Call<WatchProvidersResults> tv(
28+
@Query("language") String language,
29+
@Query("watch_region") String watchRegion
30+
);
31+
32+
}

src/test/java/com/uwetrottmann/tmdb2/assertions/GenericAssertions.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.uwetrottmann.tmdb2.entities.Videos;
2323
import com.uwetrottmann.tmdb2.entities.WatchProviders;
2424
import java.util.List;
25+
import java.util.Map;
2526

2627
public class GenericAssertions {
2728

@@ -50,6 +51,16 @@ public static void assertVideos(Videos videos) {
5051
}
5152
}
5253

54+
public static void assertWatchProviders(WatchProviders providers) {
55+
assertThat(providers.results).isNotNull();
56+
for (Map.Entry<String, WatchProviders.CountryInfo> entry : providers.results.entrySet()) {
57+
assertThat(entry.getKey()).isNotEmpty();
58+
WatchProviders.CountryInfo countryInfo = entry.getValue();
59+
assertThat(countryInfo.link).isNotEmpty();
60+
assertWatchProviderCountryInfo(countryInfo);
61+
}
62+
}
63+
5364
public static void assertWatchProviderCountryInfo(WatchProviders.CountryInfo info) {
5465
assertWatchProviders(info.flatrate);
5566
assertWatchProviders(info.free);
@@ -58,7 +69,7 @@ public static void assertWatchProviderCountryInfo(WatchProviders.CountryInfo inf
5869
assertWatchProviders(info.rent);
5970
}
6071

61-
private static void assertWatchProviders(List<WatchProviders.WatchProvider> providers) {
72+
public static void assertWatchProviders(List<WatchProviders.WatchProvider> providers) {
6273
for (WatchProviders.WatchProvider provider : providers) {
6374
assertThat(provider).isNotNull();
6475
assertThat(provider.display_priority).isGreaterThanOrEqualTo(0);

src/test/java/com/uwetrottmann/tmdb2/services/MoviesServiceTest.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import static com.uwetrottmann.tmdb2.assertions.GenericAssertions.assertImages;
1313
import static com.uwetrottmann.tmdb2.assertions.GenericAssertions.assertTranslations;
1414
import static com.uwetrottmann.tmdb2.assertions.GenericAssertions.assertVideos;
15-
import static com.uwetrottmann.tmdb2.assertions.GenericAssertions.assertWatchProviderCountryInfo;
15+
import static com.uwetrottmann.tmdb2.assertions.GenericAssertions.assertWatchProviders;
1616
import static com.uwetrottmann.tmdb2.assertions.KeywordAssertions.assertKeywords;
1717
import static com.uwetrottmann.tmdb2.assertions.ListAssertions.assertListResultsPage;
1818
import static com.uwetrottmann.tmdb2.assertions.MovieAssertions.assertMovie;
@@ -43,7 +43,6 @@
4343
import com.uwetrottmann.tmdb2.enumerations.AppendToResponseItem;
4444
import java.io.IOException;
4545
import java.util.HashMap;
46-
import java.util.Map;
4746
import org.junit.Test;
4847
import retrofit2.Call;
4948

@@ -238,21 +237,15 @@ public void test_videos() throws IOException {
238237

239238
@Test
240239
public void watchProviders() throws IOException {
241-
Call<WatchProviders> call = getUnauthenticatedInstance().moviesService().watchProviders(
242-
testMovie.id
243-
);
244-
245-
WatchProviders providers = call.execute().body();
240+
WatchProviders providers = getUnauthenticatedInstance()
241+
.moviesService()
242+
.watchProviders(testMovie.id)
243+
.execute()
244+
.body();
246245

247246
assertThat(providers).isNotNull();
247+
assertWatchProviders(providers);
248248
assertThat(providers.id).isEqualTo(testMovie.id);
249-
assertThat(providers.results).isNotNull();
250-
for (Map.Entry<String, WatchProviders.CountryInfo> entry : providers.results.entrySet()) {
251-
assertThat(entry.getKey()).isNotEmpty();
252-
WatchProviders.CountryInfo countryInfo = entry.getValue();
253-
assertThat(countryInfo.link).isNotEmpty();
254-
assertWatchProviderCountryInfo(countryInfo);
255-
}
256249
}
257250

258251
@Test

src/test/java/com/uwetrottmann/tmdb2/services/TvServiceTest.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import static com.uwetrottmann.tmdb2.assertions.GenericAssertions.assertImages;
1414
import static com.uwetrottmann.tmdb2.assertions.GenericAssertions.assertTranslations;
1515
import static com.uwetrottmann.tmdb2.assertions.GenericAssertions.assertVideos;
16-
import static com.uwetrottmann.tmdb2.assertions.GenericAssertions.assertWatchProviderCountryInfo;
16+
import static com.uwetrottmann.tmdb2.assertions.GenericAssertions.assertWatchProviders;
1717
import static com.uwetrottmann.tmdb2.assertions.KeywordAssertions.assertKeywords;
1818
import static com.uwetrottmann.tmdb2.assertions.TvAssertions.assertTvShow;
1919
import static com.uwetrottmann.tmdb2.assertions.TvAssertions.assertTvShowDataIntegrity;
@@ -43,7 +43,6 @@
4343
import com.uwetrottmann.tmdb2.enumerations.AppendToResponseItem;
4444
import java.io.IOException;
4545
import java.util.HashMap;
46-
import java.util.Map;
4746
import org.junit.Test;
4847
import retrofit2.Call;
4948

@@ -295,21 +294,15 @@ public void test_videos() throws IOException {
295294

296295
@Test
297296
public void watchProviders() throws IOException {
298-
Call<WatchProviders> call = getUnauthenticatedInstance().tvService().watchProviders(
299-
testTvShow.id
300-
);
301-
302-
WatchProviders providers = call.execute().body();
297+
WatchProviders providers = getUnauthenticatedInstance()
298+
.tvService()
299+
.watchProviders(testTvShow.id)
300+
.execute()
301+
.body();
303302

304303
assertThat(providers).isNotNull();
305304
assertThat(providers.id).isEqualTo(testTvShow.id);
306-
assertThat(providers.results).isNotNull();
307-
for (Map.Entry<String, WatchProviders.CountryInfo> entry : providers.results.entrySet()) {
308-
assertThat(entry.getKey()).isNotEmpty();
309-
WatchProviders.CountryInfo countryInfo = entry.getValue();
310-
assertThat(countryInfo.link).isNotEmpty();
311-
assertWatchProviderCountryInfo(countryInfo);
312-
}
305+
assertWatchProviders(providers);
313306
}
314307

315308
@Test
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright 2025 Uwe Trottmann
3+
4+
package com.uwetrottmann.tmdb2.services;
5+
6+
7+
import static com.uwetrottmann.tmdb2.assertions.GenericAssertions.assertWatchProviders;
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
import com.uwetrottmann.tmdb2.BaseTestCase;
11+
import com.uwetrottmann.tmdb2.entities.WatchProvidersResults;
12+
import java.io.IOException;
13+
import org.junit.Test;
14+
15+
public class WatchProvidersServiceTest extends BaseTestCase {
16+
17+
@Test
18+
public void movies() throws IOException {
19+
WatchProvidersResults results = getUnauthenticatedInstance()
20+
.watchProvidersService()
21+
.movie(null, null)
22+
.execute()
23+
.body();
24+
25+
assertThat(results).isNotNull();
26+
assertThat(results.results).isNotEmpty();
27+
assertWatchProviders(results.results);
28+
}
29+
30+
@Test
31+
public void tv() throws IOException {
32+
WatchProvidersResults results = getUnauthenticatedInstance()
33+
.watchProvidersService()
34+
.tv(null, null)
35+
.execute()
36+
.body();
37+
38+
assertThat(results).isNotNull();
39+
assertThat(results.results).isNotEmpty();
40+
assertWatchProviders(results.results);
41+
}
42+
}

0 commit comments

Comments
 (0)