refine media scanning and episode details

This commit is contained in:
ngfchl
2026-07-19 12:33:27 +08:00
parent 3daceb1859
commit 13ab2ce103
2 changed files with 260 additions and 30 deletions
+26 -2
View File
@@ -589,14 +589,27 @@ class MediaLibraryNotifier extends StateNotifier<MediaLibraryState> {
(existing.id == file.id ||
(file.gcid?.isNotEmpty == true &&
file.gcid == existing.file.gcid));
var item = existing == null || !sameCloudResource
// Keep complete entries during a rescan. New resources and rows
// missing scraped metadata follow the same automatic recognition,
// detail hydration and canonical naming path as detail-page media
// recognition.
final shouldRecognize =
existing == null ||
!sameCloudResource ||
_needsMediaRefresh(existing);
var item = shouldRecognize
? await _recognizeMediaItem(
fallback,
tmdbApiKey,
proxyHost: tmdbProxyHost,
proxyPort: tmdbProxyPort,
)
: existing.copyWith(file: file);
: existing.copyWith(file: file, updatedAt: DateTime.now());
// Do not lose an existing match solely because a transient TMDB
// lookup failed while filling an incomplete record.
if (item.tmdbID == null && existing?.tmdbID != null) {
item = existing!.copyWith(file: file, updatedAt: DateTime.now());
}
item = await _renameMatchedMediaFile(item);
unique[file.id] = item;
completed += 1;
@@ -1637,6 +1650,17 @@ class MediaLibraryNotifier extends StateNotifier<MediaLibraryState> {
}
}
bool _needsMediaRefresh(MediaLibraryItem item) {
return item.tmdbID == null ||
item.mediaKind == null ||
item.title.trim().isEmpty ||
item.originalTitle.trim().isEmpty ||
item.overview.trim().isEmpty ||
item.releaseDate.trim().isEmpty ||
item.posterPath?.isEmpty != false ||
item.backdropPath?.isEmpty != false;
}
Future<List<Map<String, dynamic>>> _tmdbCandidatesForItem(
MediaLibraryItem fallback,
String apiKey, {