Search metadata directly from IDs embedded in file names
ParseFilename's movie-IMDB pattern now recognizes parenthesized years and
brace-wrapped service IDs, so names like "Movie (2024) {tmdb-1015812}" no
longer truncate to "Movie (2024) {tmdb". The ID kind is captured (imdb,
tmdb, tvdb, tt; IDs widened to 7-9 digits for modern IMDb IDs) and
emitted as an "id:<kind>:<value>" line.
Parsed IDs ride along in MetadataSearchTerms.movie as a MetadataFileID.
TheMovieDB answers direct lookups (movie/{id} for TMDb IDs, find +
external_source=imdb_id for IMDb IDs) as a movieIDSearch; the search
sheet, the queue metadata action, and the AppleScript fetch-metadata
command try the direct lookup first and fall back to the title search
when the ID is unknown or the provider doesn't support it. Index-based
AppleScript result commands keep the name search by design.
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
401584a376
commit
f20ad7ee45
10 files changed
+203
-60
No files matched your search
@@ -57,6 +57,9 @@ final class MetadataSearchController: NSViewController, NSTableViewDataSource, N
|
||||
|
||||
private var state: MetadataSearchState = .none
|
||||
|
||||
/// Service ID parsed from the file name: consumed by the first automatic movie search.
|
||||
private var pendingMovieID: MetadataFileID?
|
||||
|
||||
private var movieService: MetadataService = MetadataSearch.defaultMovieService
|
||||
private var tvShowService: MetadataService = MetadataSearch.defaultTVService
|
||||
|
||||
@@ -122,10 +125,11 @@ final class MetadataSearchController: NSViewController, NSTableViewDataSource, N
|
||||
case .none:
|
||||
updateUI()
|
||||
|
||||
case .movie(let title):
|
||||
case .movie(let title, let id):
|
||||
searchMode.selectTabViewItem(at: 0)
|
||||
movieName.stringValue = title
|
||||
tvSeriesName.stringValue = title
|
||||
pendingMovieID = id
|
||||
searchForResults(searchMovieButton)
|
||||
|
||||
case .tvShow(let tvShow, let season, let episode):
|
||||
@@ -242,8 +246,27 @@ final class MetadataSearchController: NSViewController, NSTableViewDataSource, N
|
||||
}
|
||||
|
||||
private func searchMovie() {
|
||||
let title = movieName.stringValue
|
||||
let language = movieService.languageType.tag(displayName: movieLanguage.titleOfSelectedItem ?? "en")
|
||||
|
||||
if let id = pendingMovieID {
|
||||
// The file name carried a service ID: try a direct lookup first and
|
||||
// consume it either way, so later searches follow the text field.
|
||||
pendingMovieID = nil
|
||||
let searcher = MetadataSearch.movieIDSearch(service: movieService, id: id, language: language)
|
||||
let task = searcher.search(completionHandler: { results in
|
||||
if results.isEmpty {
|
||||
// Not supported by this provider, or unknown ID: fall back to the title search.
|
||||
DispatchQueue.main.async { self.searchForResults(self.searchMovieButton) }
|
||||
}
|
||||
else {
|
||||
self.searchDone(search: searcher, results: results)
|
||||
}
|
||||
}).runAsync()
|
||||
state = .searching(search: searcher, task: task)
|
||||
return
|
||||
}
|
||||
|
||||
let title = movieName.stringValue
|
||||
let searcher = MetadataSearch.movieSeach(service: movieService, movie: title, language: language)
|
||||
let task = searcher.search(completionHandler: { self.searchDone(search: searcher, results: $0) }).runAsync()
|
||||
state = .searching(search: searcher, task: task)
|
||||
@@ -331,14 +354,14 @@ final class MetadataSearchController: NSViewController, NSTableViewDataSource, N
|
||||
switch state {
|
||||
case .searching(let search, _):
|
||||
switch search {
|
||||
case .movieSeach(let service, _, _):
|
||||
case .movieSeach(let service, _, _), .movieIDSearch(let service, _, _):
|
||||
progressText.stringValue = String.localizedStringWithFormat(NSLocalizedString("Searching %@ for movie information…", comment: ""), service.name)
|
||||
case .tvSearch(let service, _, _ , _, _):
|
||||
progressText.stringValue = String.localizedStringWithFormat(NSLocalizedString("Searching %@ for episode information…", comment: ""), service.name)
|
||||
}
|
||||
case .additionalSearch(let search, _, _):
|
||||
switch search {
|
||||
case .movieSeach:
|
||||
case .movieSeach, .movieIDSearch:
|
||||
progressText.stringValue = NSLocalizedString("Downloading additional movie metadata…", comment: "")
|
||||
case .tvSearch:
|
||||
progressText.stringValue = NSLocalizedString("Downloading additional TV metadata…", comment: "")
|
||||
|
||||
Reference in new issue
Block a user