From cde062524245de5637aa2372263fa11450ecff92 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Mon, 26 Oct 2020 10:12:18 +0100 Subject: [PATCH] Return the first show with the exact title match. --- Classes/MetadataImporters/AppleTV.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Classes/MetadataImporters/AppleTV.swift b/Classes/MetadataImporters/AppleTV.swift index 5c53187..e25a511 100644 --- a/Classes/MetadataImporters/AppleTV.swift +++ b/Classes/MetadataImporters/AppleTV.swift @@ -94,6 +94,16 @@ private extension MetadataResult { } } +private extension Array where Element == AppleTV.Item { + func match(title: String) -> AppleTV.Item? { + if let match = self.first(where: { $0.title?.caseInsensitiveCompare(title) == .orderedSame }) { + return match + } else { + return self.first + } + } +} + public struct AppleTV: MetadataService { public var languages: [String] { @@ -171,7 +181,7 @@ public struct AppleTV: MetadataService { let tvShows = search(term: tvShow, store: store, type: .tvShow(season: nil)) - if let tvShow = tvShows.first { + if let tvShow = tvShows.match(title: tvShow) { let seasons = fetchSeasons(id: tvShow.id, store: store) let seasonIndex = seasons.firstIndex(where: {$0.seasonNumber == season}) ?? -1 if seasons.count >= seasonIndex, seasonIndex > -1 {