Rank metadata search results and honor filename IDs on tagged files
extractSearchTerms dropped a filename's {tmdb-…} ID whenever the movie was
already tagged (name+release-date+media-kind present), returning a bare title
and ignoring the embedded ID — so a search on a tagged or previously-searched
file came back as a fuzzy title list. That branch now also parses the filename,
so the direct ID lookup fires regardless of prior tagging.
Also rank movie title-search results so exact title matches sort to the top of
the fuzzy provider list, and recover the release year from the filename
(ParseFilename strips it from the title without reporting it) to pick the
default entry: exact+year, then exact, then year-only, then the provider's own
order (a stable sort, so relevance survives within each band). Applied in the
search sheet, the queue metadata action, and both AppleScript commands with
identical ranking so scripted indexes stay aligned; the sheet now highlights
the default pick. Bracketed years win over bare dot/space years so
resolutions like .1920.1080p don't win.
Bump the fork version to 1.9.5mkv2.
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
a153763019
commit
13255140e9
8 files changed
+148
-23
No files matched your search
@@ -60,6 +60,10 @@ final class MetadataSearchController: NSViewController, NSTableViewDataSource, N
|
||||
/// Service ID parsed from the file name: consumed by the first automatic movie search.
|
||||
private var pendingMovieID: MetadataFileID?
|
||||
|
||||
/// Release year parsed from the file name: consumed by the first completed
|
||||
/// movie search, so it only steers the search seeded by the file name.
|
||||
private var pendingMovieYear: Int?
|
||||
|
||||
private var movieService: MetadataService = MetadataSearch.defaultMovieService
|
||||
private var tvShowService: MetadataService = MetadataSearch.defaultTVService
|
||||
|
||||
@@ -125,11 +129,12 @@ final class MetadataSearchController: NSViewController, NSTableViewDataSource, N
|
||||
case .none:
|
||||
updateUI()
|
||||
|
||||
case .movie(let title, let id):
|
||||
case .movie(let title, let id, let year):
|
||||
searchMode.selectTabViewItem(at: 0)
|
||||
movieName.stringValue = title
|
||||
tvSeriesName.stringValue = title
|
||||
pendingMovieID = id
|
||||
pendingMovieYear = year
|
||||
searchForResults(searchMovieButton)
|
||||
|
||||
case .tvShow(let tvShow, let season, let episode):
|
||||
@@ -295,6 +300,14 @@ final class MetadataSearchController: NSViewController, NSTableViewDataSource, N
|
||||
|
||||
private func searchDone(search: MetadataSearch, results: [MetadataResult]) {
|
||||
DispatchQueue.main.async {
|
||||
var results = results
|
||||
if search.type == .movie {
|
||||
// Exact title matches first, the file-name year preferred among
|
||||
// them; the parsed year steers only the search seeded by the
|
||||
// file name, so it is consumed here.
|
||||
results = rankMovieResults(results, title: self.movieName.stringValue, year: self.pendingMovieYear)
|
||||
self.pendingMovieYear = nil
|
||||
}
|
||||
if let first = results.first {
|
||||
self.state = .completed(search: search, results: results, selectedResult: first)
|
||||
}
|
||||
@@ -418,9 +431,14 @@ final class MetadataSearchController: NSViewController, NSTableViewDataSource, N
|
||||
startProgressReport()
|
||||
reloadTableData()
|
||||
swithDefaultButton(from: addButton, to: visibleSearchButton(), disableOldButton: true)
|
||||
case .completed:
|
||||
case .completed(_, let results, let selectedResult):
|
||||
stopProgressReport()
|
||||
reloadTableData()
|
||||
// Highlight the default pick (the ranked first result) so the
|
||||
// user sees what Add would apply.
|
||||
if let index = results.firstIndex(where: { $0 === selectedResult }) {
|
||||
resultsTable.selectRowIndexes(IndexSet(integer: index), byExtendingSelection: false)
|
||||
}
|
||||
swithDefaultButton(from: searchMovieButton, to: addButton, disableOldButton: nil)
|
||||
swithDefaultButton(from: searchTvButton, to: addButton, disableOldButton: nil)
|
||||
updateSearchButtonVisibility()
|
||||
|
||||
Reference in new issue
Block a user