Fix iTunes Store search, do not use invalid language codes.

This commit is contained in:
Damiano Galassi committed 2019-11-04 17:24:17 +01:00
1 parent 84c10609b7
commit 84e84af677
1 file changed
+7 -7
+7 -7
View File
@@ -297,7 +297,7 @@ public struct iTunesStore: MetadataService {
if searchTerm.isEmpty == false,
let store = iTunesStore.store(language: language),
let url = URL(string: "https://itunes.apple.com/search?country=\(store.country2)&lang=\(store.language2.lowercased())_\(store.country2.lowercased())&term=\(searchTerm)&media=tvShow&entity=tvEpisode&attribute=tvSeasonTerm&limit=200"),
let url = URL(string: "https://itunes.apple.com/search?country=\(store.country2)&lang=\(store.language2.lowercased())&term=\(searchTerm)&media=tvShow&entity=tvEpisode&attribute=tvSeasonTerm&limit=200"),
let results = sendJSONRequest(url: url, type: Wrapper<Artist>.self)?.results, results.isEmpty == false {
let filteredResults = results.filter { $0.artistName.isEmpty == false }
@@ -408,16 +408,16 @@ public struct iTunesStore: MetadataService {
if let seasonNum = seasonNum {
let searchTerm = "\(seriesName) \(store.season) \(seasonNum)".urlEncoded()
if relaxSearch {
return URL(string: "https://itunes.apple.com/search?term=\(searchTerm)&media=tvShow&entity=tvSeason&country=\(store.country2)&lang=\(store.language2.lowercased())_\(store.country2.lowercased())&limit=200")
return URL(string: "https://itunes.apple.com/search?term=\(searchTerm)&media=tvShow&entity=tvSeason&country=\(store.country2)&lang=\(store.language2.lowercased())&limit=200")
} else {
return URL(string: "https://itunes.apple.com/search?term=\(searchTerm)&media=tvShow&attribute=tvSeasonTerm&entity=tvSeason&country=\(store.country2)&lang=\(store.language2.lowercased())_\(store.country2.lowercased())&limit=200")
return URL(string: "https://itunes.apple.com/search?term=\(searchTerm)&media=tvShow&attribute=tvSeasonTerm&entity=tvSeason&country=\(store.country2)&lang=\(store.language2.lowercased())&limit=200")
}
} else {
let searchTerm = seriesName.urlEncoded()
if relaxSearch {
return URL(string: "https://itunes.apple.com/search?term=\(searchTerm)&media=tvShow&entity=tvSeason&country=\(store.country2)&lang=\(store.language2.lowercased())_\(store.country2.lowercased())&limit=200")
return URL(string: "https://itunes.apple.com/search?term=\(searchTerm)&media=tvShow&entity=tvSeason&country=\(store.country2)&lang=\(store.language2.lowercased())&limit=200")
} else {
return URL(string: "https://itunes.apple.com/search?term=\(searchTerm)&media=tvShow&attribute=showTerm&entity=tvShow&country=\(store.country2)&lang=\(store.language2.lowercased())_\(store.country2.lowercased())&limit=200")
return URL(string: "https://itunes.apple.com/search?term=\(searchTerm)&media=tvShow&attribute=showTerm&entity=tvShow&country=\(store.country2)&lang=\(store.language2.lowercased())&limit=200")
}
}
}()
@@ -621,7 +621,7 @@ public struct iTunesStore: MetadataService {
public func search(movie: String, language: String) -> [MetadataResult] {
guard let store = iTunesStore.store(language: language),
let url = URL(string: "https://itunes.apple.com/search?country=\(store.country2)&lang=\(store.language2.lowercased())_\(store.country2.lowercased())&term=\(movie.urlEncoded())&entity=movie&limit=150"),
let url = URL(string: "https://itunes.apple.com/search?country=\(store.country2)&lang=\(store.language2.lowercased())&term=\(movie.urlEncoded())&entity=movie&limit=150"),
let results = sendJSONRequest(url: url, type: Wrapper<Track>.self)
else { return [] }
@@ -670,7 +670,7 @@ public struct iTunesStore: MetadataService {
public func loadTVMetadata(_ metadata: MetadataResult, language: String) -> MetadataResult {
guard let store = iTunesStore.store(language: language),
let playlistID = metadata[.playlistID] as? Int,
let url = URL(string: "https://itunes.apple.com/lookup?country=\(store.country2)&lang=\(store.language2.lowercased())_\(store.country2.lowercased())&id=\(playlistID)")
let url = URL(string: "https://itunes.apple.com/lookup?country=\(store.country2)&lang=\(store.language2.lowercased())&id=\(playlistID)")
else { return metadata }
if let results = sendJSONRequest(url: url, type: Wrapper<Collection>.self) {