Files

28 lines
573 B
Dart
Raw Permalink Normal View History

2026-07-14 11:11:36 +08:00
import '../../core/contracts/library.dart';
TmdbLibraryHit? selectPrimaryTmdbHit(
List<TmdbLibraryHit> hits, {
String? activeServerId,
}) {
if (hits.isEmpty) return null;
int score(TmdbLibraryHit h) {
var s = 0;
if ((h.playbackPositionTicks ?? 0) > 0) s += 2;
if (activeServerId != null && h.serverId == activeServerId) s += 1;
return s;
}
var best = hits.first;
var bestScore = score(best);
for (final h in hits.skip(1)) {
final s = score(h);
if (s > bestScore) {
best = h;
bestScore = s;
}
}
return best;
}