Skip to content

Commit da0345b

Browse files
committed
Sync: add watched episodes method
1 parent 03a4436 commit da0345b

5 files changed

Lines changed: 118 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Address upcoming [Trakt pagination requirements](https://github.com/trakt/trakt-api/discussions/775) for watched methods:
66
* Add paginated variants of `Sync.watchedMovies()`, `Sync.watchedShows()`, `Users.watchedMovies()` and
77
`Users.watchedShows()` with required `page` and `limit` parameters. The original methods are deprecated.
8+
* Add `Sync.watchedEpisodes()`
89

910
## 6.18.0 - 2026-03-06
1011

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright © 2026 Uwe Trottmann <uwe@uwetrottmann.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.uwetrottmann.trakt5.entities;
18+
19+
20+
import org.threeten.bp.OffsetDateTime;
21+
22+
public class WatchedEpisode {
23+
24+
public Integer plays;
25+
/**
26+
* Warning: Trakt is planning to only store and return minute-precision timestamps for watched_at. So seconds and
27+
* nanoseconds will always be zero.
28+
*/
29+
public OffsetDateTime last_watched_at;
30+
public OffsetDateTime last_updated_at;
31+
32+
public Episode episode;
33+
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright © 2026 Uwe Trottmann <uwe@uwetrottmann.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.uwetrottmann.trakt5.enums;
18+
19+
public class ExtendedEpisodesWatched implements TraktEnum {
20+
21+
/**
22+
* Return details, like overview and rating.
23+
*/
24+
public static final ExtendedEpisodesWatched FULL = new ExtendedEpisodesWatched("full");
25+
26+
private final String value;
27+
28+
private ExtendedEpisodesWatched(String value) {
29+
this.value = value;
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return value;
35+
}
36+
}

src/main/java/com/uwetrottmann/trakt5/services/Sync.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
import com.uwetrottmann.trakt5.entities.SyncItems;
3030
import com.uwetrottmann.trakt5.entities.SyncResponse;
3131
import com.uwetrottmann.trakt5.entities.UserSlug;
32+
import com.uwetrottmann.trakt5.entities.WatchedEpisode;
3233
import com.uwetrottmann.trakt5.entities.WatchlistedEpisode;
3334
import com.uwetrottmann.trakt5.entities.WatchlistedSeason;
3435
import com.uwetrottmann.trakt5.enums.Extended;
36+
import com.uwetrottmann.trakt5.enums.ExtendedEpisodesWatched;
3537
import com.uwetrottmann.trakt5.enums.ExtendedMoviesWatched;
3638
import com.uwetrottmann.trakt5.enums.ExtendedShowsWatched;
3739
import com.uwetrottmann.trakt5.enums.HistoryType;
@@ -281,6 +283,21 @@ Call<List<BaseShow>> watchedShows(
281283
@Query(value = "extended", encoded = true) ExtendedShowsWatched extended
282284
);
283285

286+
/**
287+
* <b>OAuth {@link TraktV2#accessToken(String) access token} required</b>
288+
* <p>
289+
* Returns all episodes a user has watched.
290+
*
291+
* @param page Number of page of results to be returned.
292+
* @param limit Number of results to return per page.
293+
*/
294+
@GET("sync/watched/episodes")
295+
Call<List<WatchedEpisode>> watchedEpisodes(
296+
@Query("page") int page,
297+
@Query("limit") int limit,
298+
@Query(value = "extended", encoded = true) ExtendedEpisodesWatched extended
299+
);
300+
284301
/**
285302
* <b>OAuth {@link TraktV2#accessToken(String) access token} required</b>
286303
* <p>

src/test/java/com/uwetrottmann/trakt5/services/SyncTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
import com.uwetrottmann.trakt5.entities.SyncResponse;
4444
import com.uwetrottmann.trakt5.entities.SyncSeason;
4545
import com.uwetrottmann.trakt5.entities.SyncShow;
46+
import com.uwetrottmann.trakt5.entities.WatchedEpisode;
4647
import com.uwetrottmann.trakt5.entities.WatchlistedEpisode;
4748
import com.uwetrottmann.trakt5.entities.WatchlistedSeason;
4849
import com.uwetrottmann.trakt5.enums.Extended;
50+
import com.uwetrottmann.trakt5.enums.ExtendedEpisodesWatched;
4951
import com.uwetrottmann.trakt5.enums.ExtendedMoviesWatched;
5052
import com.uwetrottmann.trakt5.enums.ExtendedShowsWatched;
5153
import com.uwetrottmann.trakt5.enums.HistoryType;
@@ -362,6 +364,34 @@ public void test_watchedShows_extended() throws IOException {
362364
assertWatchedShowsFullNoSeasons(shows);
363365
}
364366

367+
@Test
368+
public void test_watchedEpisodes() throws IOException {
369+
Response<List<WatchedEpisode>> response = executeCallWithoutReadingBody(
370+
getTrakt().sync().watchedEpisodes(PAGE_ONE, LIMIT_MAX, null));
371+
372+
// As of 2026-04-29, pagination is not supported, yet
373+
// assertListPaginationHeaders(response);
374+
assertThat(response.body())
375+
.isNotEmpty()
376+
.allSatisfy(episode -> {
377+
assertThat(episode.plays).isPositive();
378+
assertThat(episode.episode).isNotNull();
379+
});
380+
}
381+
382+
@Test
383+
public void test_watchedEpisodes_extended() throws IOException {
384+
List<WatchedEpisode> episodes = executeCall(
385+
getTrakt().sync().watchedEpisodes(PAGE_ONE, LIMIT_MAX, ExtendedEpisodesWatched.FULL));
386+
387+
assertThat(episodes)
388+
.isNotEmpty()
389+
.allSatisfy(episode -> {
390+
assertThat(episode.episode).isNotNull();
391+
assertThat(episode.episode.rating).isNotNull();
392+
});
393+
}
394+
365395
@Test
366396
public void test_addItemsToWatchedHistory() throws IOException {
367397
// movie

0 commit comments

Comments
 (0)