Skip to content

Commit e364c9d

Browse files
committed
Sync: add playback methods that accept start/end and pagination #161
1 parent 53544e1 commit e364c9d

4 files changed

Lines changed: 96 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
and `Users.collectionShows()` with required `page` and `limit` parameters. The original methods without pagination
77
parameters are deprecated.
88
* Add history endpoints to `Sync`. Thanks @defhead! [#125](https://github.com/UweTrottmann/trakt-java/pull/125)
9+
* Add `Sync.playback()` that also accepts start and end times and supports pagination. The existing `getPlayback()`
10+
methods are deprecated.
911

1012
## 6.16.0 - 2024-11-07
1113

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 enum PlaybackType implements TraktEnum {
20+
21+
MOVIES("movies"),
22+
EPISODES("episodes");
23+
24+
private final String value;
25+
26+
PlaybackType(String value) {
27+
this.value = value;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
return value;
33+
}
34+
35+
}

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.uwetrottmann.trakt5.entities.WatchlistedSeason;
3333
import com.uwetrottmann.trakt5.enums.Extended;
3434
import com.uwetrottmann.trakt5.enums.HistoryType;
35+
import com.uwetrottmann.trakt5.enums.PlaybackType;
3536
import com.uwetrottmann.trakt5.enums.RatingsFilter;
3637
import org.threeten.bp.OffsetDateTime;
3738
import retrofit2.Call;
@@ -150,11 +151,62 @@ Call<List<BaseMovie>> watchedMovies(
150151
@Query(value = "extended", encoded = true) Extended extended
151152
);
152153

154+
/**
155+
* <b>OAuth Required</b>
156+
* <p>
157+
* Whenever a scrobble is paused, the playback progress is saved. Use this progress to sync up playback across
158+
* different media centers or apps. For example, you can start watching a movie in a media center, stop it, then
159+
* resume on your tablet from the same spot. Each item will have the progress percentage between 0 and 100.
160+
* <p>
161+
* Use {@link #playback(PlaybackType, OffsetDateTime, OffsetDateTime, Integer, Integer)} to specify a type to only
162+
* get movies or episodes.
163+
* <p>
164+
* By default, all results will be returned. Pagination is optional and can be used for something like an "on deck"
165+
* feature, or if you only need a limited data set.
166+
* <p>
167+
* Note: Trakt only saves playback progress for the last 6 months.
168+
*
169+
* @see #playback(PlaybackType, OffsetDateTime, OffsetDateTime, Integer, Integer)
170+
*/
171+
@GET("sync/playback")
172+
Call<List<PlaybackResponse>> playback(
173+
@Query("start_at") OffsetDateTime startAt,
174+
@Query("end_at") OffsetDateTime endAt,
175+
@Query("page") Integer page,
176+
@Query("limit") Integer limit
177+
);
178+
179+
/**
180+
* <b>OAuth Required</b>
181+
* <p>
182+
* Whenever a scrobble is paused, the playback progress is saved. Use this progress to sync up playback across
183+
* different media centers or apps. For example, you can start watching a movie in a media center, stop it, then
184+
* resume on your tablet from the same spot. Each item will have the progress percentage between 0 and 100.
185+
* <p>
186+
* By default, all results will be returned. Pagination is optional and can be used for something like an "on deck"
187+
* feature, or if you only need a limited data set.
188+
* <p>
189+
* Note: Trakt only saves playback progress for the last 6 months.
190+
*
191+
* @see #playback(OffsetDateTime, OffsetDateTime, Integer, Integer)
192+
*/
193+
@GET("sync/playback/{type}")
194+
Call<List<PlaybackResponse>> playback(
195+
@Path("type") PlaybackType type,
196+
@Query("start_at") OffsetDateTime startAt,
197+
@Query("end_at") OffsetDateTime endAt,
198+
@Query("page") Integer page,
199+
@Query("limit") Integer limit
200+
);
201+
153202
/**
154203
* <b>OAuth Required</b>
155204
*
156205
* <p> Returns all playbacks;
206+
*
207+
* @deprecated Use {@link #playback(OffsetDateTime, OffsetDateTime, Integer, Integer)} instead.
157208
*/
209+
@Deprecated
158210
@GET("sync/playback")
159211
Call<List<PlaybackResponse>> getPlayback(
160212
@Query("limit") Integer limit
@@ -164,7 +216,10 @@ Call<List<PlaybackResponse>> getPlayback(
164216
* <b>OAuth Required</b>
165217
*
166218
* <p> Returns all playbacks;
219+
*
220+
* @deprecated Use {@link #playback(PlaybackType, OffsetDateTime, OffsetDateTime, Integer, Integer)} instead.
167221
*/
222+
@Deprecated
168223
@GET("sync/playback/episodes")
169224
Call<List<PlaybackResponse>> getPlaybackEpisodes(
170225
@Query("limit") Integer limit
@@ -174,7 +229,10 @@ Call<List<PlaybackResponse>> getPlaybackEpisodes(
174229
* <b>OAuth Required</b>
175230
*
176231
* <p> Returns all playbacks;
232+
*
233+
* @deprecated Use {@link #playback(PlaybackType, OffsetDateTime, OffsetDateTime, Integer, Integer)} instead.
177234
*/
235+
@Deprecated
178236
@GET("sync/playback/movies")
179237
Call<List<PlaybackResponse>> getPlaybackMovies(
180238
@Query("limit") Integer limit

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void test_getPlayback() throws IOException, InterruptedException {
106106
// Give the server some time to process the request.
107107
Thread.sleep(1500);
108108

109-
List<PlaybackResponse> playbacks = executeCall(getTrakt().sync().getPlayback(10));
109+
List<PlaybackResponse> playbacks = executeCall(getTrakt().sync().playback(null, null, null, 10));
110110
assertThat(playbacks).isNotNull();
111111
boolean foundEpisode = false;
112112
boolean foundMovie = false;

0 commit comments

Comments
 (0)