Skip to content

Commit 8f91cf0

Browse files
committed
[Jellystat] Find multiple watch references, if several media server IDs match
1 parent 82758b0 commit 8f91cf0

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/main/kotlin/com/github/schaka/janitorr/jellystat/JellystatRestService.kt

+7-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ class JellystatRestService(
3333
// TODO: if at all possible, we shouldn't populate the list with media server ids differently, but recognize a season and treat show as a whole as per application properties
3434
// example: grab show id for season id, get watchHistory based on show instead of season
3535

36-
for (item in items.filter { it.mediaServerId != null }) {
36+
for (item in items.filter { it.mediaServerIds.isNotEmpty() }) {
3737
// every movie, show, season and episode has its own unique ID, so every request will only consider what's passed to it here
38-
val watchHistory = jellystatClient.getRequests(ItemRequest(item.mediaServerId!!))
39-
.filter { it.PlaybackDuration > 60 }
40-
.maxByOrNull { toDate(it.ActivityDateInserted) } // most recent date
38+
val watchHistory = item.mediaServerIds
39+
.map(::ItemRequest)
40+
.flatMap(jellystatClient::getRequests)
41+
.filter { it.PlaybackDuration > 60 }
42+
.maxByOrNull { toDate(it.ActivityDateInserted) } // most recent date
4143

4244
// only count view if at least one minute of content was watched - could be user adjustable later
4345
if (watchHistory != null) {
@@ -48,7 +50,7 @@ class JellystatRestService(
4850
}
4951

5052
if (log.isTraceEnabled) {
51-
for (item in items.filter { it.mediaServerId == null }) {
53+
for (item in items.filter { it.mediaServerIds.isEmpty() }) {
5254
log.trace("Could not find any matching media server id for ${item.filePath} IMDB: ${item.imdbId} TMDB: ${item.tmdbId} TVDB: ${item.tvdbId} Season: ${item.season}")
5355
}
5456
}

src/main/kotlin/com/github/schaka/janitorr/mediaserver/BaseMediaServerService.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ abstract class BaseMediaServerService(
8686
for (show: LibraryItem in items) {
8787
mediaServerShows.firstOrNull { tvShowMatches(show, it, useSeason) }
8888
?.let { mediaServerContent ->
89-
show.mediaServerId = mediaServerContent.Id
89+
show.mediaServerIds += mediaServerContent.Id
9090
}
9191
}
9292
}
@@ -116,7 +116,7 @@ abstract class BaseMediaServerService(
116116
for (movie: LibraryItem in items) {
117117
mediaServerMovies.firstOrNull { mediaMatches(MOVIES, movie, it) }
118118
?.let { mediaServerContent ->
119-
movie.mediaServerId = mediaServerContent.Id
119+
movie.mediaServerIds += mediaServerContent.Id
120120
}
121121
}
122122
}

src/main/kotlin/com/github/schaka/janitorr/servarr/LibraryItem.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data class LibraryItem(
2020
val season: Int? = null,
2121

2222
// references the id (usually some uuid) inside Jellyfin/Emby - can refer to a movie, tv show, season or episode
23-
var mediaServerId: String? = null,
23+
var mediaServerIds: MutableList<String> = mutableListOf(),
2424
var seeding: Boolean = false,
2525
var lastSeen: LocalDateTime? = null,
2626

0 commit comments

Comments
 (0)