addToHistory method
Add items to a user's watch history.
Accepts shows, seasons, episodes and movies. If only a show is passed, all episodes for the show will be added. If seasons are specified, only episodes in those seasons will be added.
Send a watched_at UTC datetime to mark items as watched in the past. This is useful for syncing past watches from a media center.
movies
- a list of tuples consisting of a Movie and optional watched_at to be added.
shows
- a list of tuples consisting of a Show and optional watched_at to be added.
🔒 OAuth Required
Implementation
Future<AddToSyncResponse> addToHistory({
List<Tuple2<Movie, String?>> movies = const [],
List<Tuple2<Show, String?>> shows = const [],
List<Tuple2<Season, String?>> seasons = const [],
List<Tuple2<Episode, String?>> episodes = const [],
}) async {
Map<String, dynamic> body = {};
if (movies.isNotEmpty) {
body["movies"] = movies.map((tuple) {
final meta = tuple.item1.metadata;
if (tuple.item2 != null) {
meta["watched_at"] = tuple.item2;
}
return meta;
}).toList();
}
if (shows.isNotEmpty) {
body["shows"] = shows.map((tuple) {
final meta = tuple.item1.metadata;
if (tuple.item2 != null) {
meta["watched_at"] = tuple.item2;
}
return meta;
}).toList();
}
if (seasons.isNotEmpty) {
body["seasons"] = seasons.map((tuple) {
final meta = tuple.item1.metadata;
if (tuple.item2 != null) {
meta["watched_at"] = tuple.item2;
}
return meta;
}).toList();
}
if (episodes.isNotEmpty) {
body["episodes"] = episodes.map((tuple) {
final meta = tuple.item1.metadata;
if (tuple.item2 != null) {
meta["watched_at"] = tuple.item2;
}
return meta;
}).toList();
}
return await _manager._authenticatedPost<AddToSyncResponse>("sync/history",
body: jsonEncode(body));
}