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:
Scott GarrettandClaude Code committed 2026-11-28 13:10:25 -05:00
1 parent 401584a376
commit f20ad7ee45
10 files changed
+203 -60

No files matched your search

+62 -42
View File
@@ -150,48 +150,66 @@ class SBFetchMetadataScriptCommand: NSScriptCommand, ScriptCommandDocumentTarget
let preferredArtworkSize = ArtworkSize(rawValue: queuePrefs.providerArtworkSize) ?? .standard
switch terms {
case let .movie(title):
let movieSearch = MetadataSearch.movieSeach(service: movieService, movie: title, language: MetadataSearch.defaultLanguage(service: movieService, type: .movie))
_ = movieSearch.search(completionHandler: { results in
if let result = results.first {
_ = movieSearch.loadAdditionalMetadata(result, completionHandler: { additionalMetadata in
metadata = additionalMetadata
// Handle artwork similar to QueueMetadataAction
if let metadataResult = metadata {
let artworks = metadataResult.remoteArtworks
if preferredArtwork != .none && artworks.isEmpty == false {
let artwork: Artwork? = {
let type = preferredArtwork.isMovieType ? preferredArtwork : .poster
if let artwork = artworks.first(by: type, size: preferredArtworkSize, service: movieService.name) {
return artwork
} else if let artwork = artworks.first(by: .poster, size: .standard, service: movieService.name) {
return artwork
} else {
return artworks.first
}
}()
// Load and add artwork to metadata result BEFORE mapping
if let url = artwork?.url, let artworkData = URLSession.data(from: url) {
let mp42Image = MP42Image(data: artworkData, type: MP42_ART_JPEG)
metadataResult.artworks.append(mp42Image)
}
case let .movie(title, id):
let language = MetadataSearch.defaultLanguage(service: movieService, type: .movie)
// Shared continuation for both the ID lookup and the title search
let completeWith: (MetadataResult, MetadataSearch) -> Void = { result, search in
_ = search.loadAdditionalMetadata(result, completionHandler: { metadataResult in
// Handle artwork similar to QueueMetadataAction
let artworks = metadataResult.remoteArtworks
if preferredArtwork != .none && artworks.isEmpty == false {
let artwork: Artwork? = {
let type = preferredArtwork.isMovieType ? preferredArtwork : .poster
if let artwork = artworks.first(by: type, size: preferredArtworkSize, service: movieService.name) {
return artwork
} else if let artwork = artworks.first(by: .poster, size: .standard, service: movieService.name) {
return artwork
} else {
return artworks.first
}
// Map the metadata using the same logic as QueueAction (now includes artwork)
let map = metadataResult.mediaKind == .movie ? MetadataPrefs.movieResultMap : MetadataPrefs.tvShowResultMap
let mappedMetadata = metadataResult.mappedMetadata(to: map, keepEmptyKeys: false)
completion(mappedMetadata)
} else {
completion(nil)
}()
// Load and add artwork to metadata result BEFORE mapping
if let url = artwork?.url, let artworkData = URLSession.data(from: url) {
let mp42Image = MP42Image(data: artworkData, type: MP42_ART_JPEG)
metadataResult.artworks.append(mp42Image)
}
}).run()
} else {
completion(nil)
}
}).run()
}
// Map the metadata using the same logic as QueueAction (now includes artwork)
let map = metadataResult.mediaKind == .movie ? MetadataPrefs.movieResultMap : MetadataPrefs.tvShowResultMap
let mappedMetadata = metadataResult.mappedMetadata(to: map, keepEmptyKeys: false)
completion(mappedMetadata)
}).run()
}
let searchByName: () -> Void = {
let movieSearch = MetadataSearch.movieSeach(service: movieService, movie: title, language: language)
_ = movieSearch.search(completionHandler: { results in
if let result = results.first {
completeWith(result, movieSearch)
} else {
completion(nil)
}
}).run()
}
if let id = id {
// The file name carries a service ID: try the direct lookup first,
// falling back to the title search when it doesn't resolve.
let idSearch = MetadataSearch.movieIDSearch(service: movieService, id: id, language: language)
_ = idSearch.search(completionHandler: { results in
if let result = results.first {
completeWith(result, idSearch)
} else {
searchByName()
}
}).run()
} else {
searchByName()
}
case let .tvShow(seriesName, season, episode):
let tvSearch = MetadataSearch.tvSearch(service: tvShowService, tvShow: seriesName, season: season, episode: episode, language: MetadataSearch.defaultLanguage(service: tvShowService, type: .tvShow))
@@ -634,7 +652,7 @@ class SBFetchMetadataResultsScriptCommand: NSScriptCommand, ScriptCommandDocumen
// Perform the search based on media type
switch terms {
case .movie(let title):
case .movie(let title, _):
let results = movieService.search(movie: title, language: searchLanguage)
// Convert MetadataResult to SBMetadataResult
@@ -784,8 +802,10 @@ class SBFetchAndSetMetadataResultScriptCommand: NSScriptCommand, ScriptCommandDo
let preferredArtworkSize = ArtworkSize(rawValue: queuePrefs.providerArtworkSize) ?? .standard
// Perform the search based on media type
// (Title search by design: the caller indexes into the list returned by the
// earlier fetch-metadata-results command, so no ID shortcut here.)
switch terms {
case let .movie(title):
case let .movie(title, _):
let movieSearch = MetadataSearch.movieSeach(service: movieService, movie: title, language: searchLanguage)
_ = movieSearch.search(completionHandler: { results in
if resultIndex >= 0 && resultIndex < results.count {