Initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user