diff --git a/Alpha2.json b/Alpha2.json new file mode 100644 index 0000000..e4058ce --- /dev/null +++ b/Alpha2.json @@ -0,0 +1,251 @@ +{ + "AF": "Afghanistan", + "AX": "Aland Islands", + "AL": "Albania", + "DZ": "Algeria", + "AS": "American Samoa", + "AD": "Andorra", + "AO": "Angola", + "AI": "Anguilla", + "AQ": "Antarctica", + "AG": "Antigua and Barbuda", + "AR": "Argentina", + "AM": "Armenia", + "AW": "Aruba", + "AU": "Australia", + "AT": "Austria", + "AZ": "Azerbaijan", + "BS": "Bahamas", + "BH": "Bahrain", + "BD": "Bangladesh", + "BB": "Barbados", + "BY": "Belarus", + "BE": "Belgium", + "BZ": "Belize", + "BJ": "Benin", + "BM": "Bermuda", + "BT": "Bhutan", + "BO": "Bolivia", + "BQ": "Bonaire, Sint Eustatius and Saba", + "BA": "Bosnia and Herzegovina", + "BW": "Botswana", + "BV": "Bouvet Island", + "BR": "Brazil", + "IO": "British Indian Ocean Territory", + "BN": "Brunei Darussalam", + "BG": "Bulgaria", + "BF": "Burkina Faso", + "BI": "Burundi", + "CV": "Cabo Verde", + "KH": "Cambodia", + "CM": "Cameroon", + "CA": "Canada", + "KY": "Cayman Islands", + "CF": "Central African Republic", + "TD": "Chad", + "CL": "Chile", + "CN": "China", + "CX": "Christmas Island", + "CC": "Cocos Keeling Islands", + "CO": "Colombia", + "KM": "Comoros", + "CG": "Congo", + "CD": "Congo, DR", + "CK": "Cook Islands", + "CR": "Costa Rica", + "CI": "Cote d'Ivoire", + "HR": "Croatia", + "CU": "Cuba", + "CY": "Cyprus", + "CZ": "Czechia", + "DK": "Denmark", + "DJ": "Djibouti", + "DM": "Dominica", + "DO": "Dominican Republic", + "EC": "Ecuador", + "EG": "Egypt", + "SV": "El Salvador", + "GQ": "Equatorial Guinea", + "ER": "Eritrea", + "EE": "Estonia", + "SZ": "Eswatini", + "ET": "Ethiopia", + "FK": "Falkland Islands Malvinas", + "FO": "Faroe Islands", + "FJ": "Fiji", + "FI": "Finland", + "FR": "France", + "GF": "French Guiana", + "PF": "French Polynesia", + "TF": "French Southern Territories", + "GA": "Gabon", + "GM": "Gambia", + "GE": "Georgia", + "DE": "Germany", + "GH": "Ghana", + "GI": "Gibraltar", + "GR": "Greece", + "GL": "Greenland", + "GD": "Grenada", + "GP": "Guadeloupe", + "GU": "Guam", + "GT": "Guatemala", + "GG": "Guernsey", + "GN": "Guinea", + "GW": "Guinea Bissau", + "GY": "Guyana", + "HT": "Haiti", + "HM": "Heard Island and Mcdonald Islands", + "VA": "Holy See", + "HN": "Honduras", + "HK": "Hong Kong", + "HU": "Hungary", + "IS": "Iceland", + "IN": "India", + "ID": "Indonesia", + "IR": "Iran", + "IQ": "Iraq", + "IE": "Ireland", + "IM": "Isle of Man", + "IL": "Israel", + "IT": "Italy", + "JM": "Jamaica", + "JP": "Japan", + "JE": "Jersey", + "JO": "Jordan", + "KZ": "Kazakhstan", + "KE": "Kenya", + "KI": "Kiribati", + "KR": "Korea", + "KP": "Korea, DPR", + "KW": "Kuwait", + "KG": "Kyrgyzstan", + "LA": "Lao People's Democratic Republic", + "LV": "Latvia", + "LB": "Lebanon", + "LS": "Lesotho", + "LR": "Liberia", + "LY": "Libya", + "LI": "Liechtenstein", + "LT": "Lithuania", + "LU": "Luxembourg", + "MO": "Macao", + "MG": "Madagascar", + "MW": "Malawi", + "MY": "Malaysia", + "MV": "Maldives", + "ML": "Mali", + "MT": "Malta", + "MH": "Marshall Islands", + "MQ": "Martinique", + "MR": "Mauritania", + "MU": "Mauritius", + "YT": "Mayotte", + "MX": "Mexico", + "FM": "Micronesia", + "MD": "Moldova", + "MC": "Monaco", + "MN": "Mongolia", + "ME": "Montenegro", + "MS": "Montserrat", + "MA": "Morocco", + "MZ": "Mozambique", + "MM": "Myanmar", + "NA": "Namibia", + "NR": "Nauru", + "NP": "Nepal", + "NL": "Netherlands", + "NT": "Neutral Zone", + "NC": "New Caledonia", + "NZ": "New Zealand", + "NI": "Nicaragua", + "NE": "Niger", + "NG": "Nigeria", + "NU": "Niue", + "NF": "Norfolk Island", + "MK": "North Macedonia", + "MP": "Northern Mariana Islands", + "NO": "Norway", + "OM": "Oman", + "PK": "Pakistan", + "PW": "Palau", + "PS": "Palestine", + "PA": "Panama", + "PG": "Papua New Guinea", + "PY": "Paraguay", + "PE": "Peru", + "PH": "Philippines", + "PN": "Pitcairn", + "PL": "Poland", + "PT": "Portugal", + "PR": "Puerto Rico", + "QA": "Qatar", + "RE": "Reunion", + "RO": "Romania", + "RU": "Russian Federation", + "RW": "Rwanda", + "BL": "Saint Barthelemy", + "SH": "Saint Helena, Ascension and Tristan da Cunha", + "KN": "Saint Kitts and Nevis", + "LC": "Saint Lucia", + "MF": "Saint Martin", + "PM": "Saint Pierre and Miquelon", + "VC": "Saint Vincent and the Grenadines", + "WS": "Samoa", + "SM": "San Marino", + "ST": "Sao Tome and Principe", + "SA": "Saudi Arabia", + "SN": "Senegal", + "RS": "Serbia", + "SC": "Seychelles", + "SL": "Sierra Leone", + "SG": "Singapore", + "SX": "Sint Maarten", + "SK": "Slovakia", + "SI": "Slovenia", + "SB": "Solomon Islands", + "SO": "Somalia", + "ZA": "South Africa", + "GS": "South Georgia And South Sandwich Islands", + "SS": "South Sudan", + "ES": "Spain", + "LK": "Sri Lanka", + "SD": "Sudan", + "SR": "Suriname", + "SJ": "Svalbard and Jan Mayen", + "SE": "Sweden", + "CH": "Switzerland", + "SY": "Syrian Arab Republic", + "TW": "Taiwan", + "TJ": "Tajikistan", + "TZ": "Tanzania", + "TH": "Thailand", + "TL": "Timor-Leste", + "TG": "Togo", + "TK": "Tokelau", + "TO": "Tonga", + "TT": "Trinidad and Tobago", + "TN": "Tunisia", + "TR": "Turkiye", + "TM": "Turkmenistan", + "TC": "Turks and Caicos Islands", + "TV": "Tuvalu", + "UG": "Uganda", + "UA": "Ukraine", + "AE": "United Arab Emirates", + "GB": "United Kingdom", + "US": "United States of America", + "UM": "United States Minor Outlying Islands", + "UY": "Uruguay", + "UZ": "Uzbekistan", + "VU": "Vanuatu", + "VE": "Venezuela", + "VN": "Viet Nam", + "VG": "Virgin Islands, British", + "VI": "Virgin Islands, U.S.", + "WF": "Wallis and Futuna", + "EH": "Western Sahara", + "YE": "Yemen", + "ZM": "Zambia", + "ZW": "Zimbabwe" +} diff --git a/Classes/MetadataImporters/AppleTVv3.swift b/Classes/MetadataImporters/AppleTVv3.swift new file mode 100644 index 0000000..050da6b --- /dev/null +++ b/Classes/MetadataImporters/AppleTVv3.swift @@ -0,0 +1,1002 @@ +// +// AppleTVv3.swift +// +// Created by Are Digranes on 04/11/2022. +// + +import Foundation +import MP42Foundation + +extension URLComponents { + init(staticString string: StaticString) { + guard let url = URLComponents(string: "\(string)") else { + preconditionFailure("Invalid static URL string: \(string)") + } + self = url + } +} + +extension String { + func unCamel() -> String { + return unicodeScalars.reduce("") { + if CharacterSet.uppercaseLetters.contains($1) && $0.count > 0 { return $0 + " " + String($1) } else if $0.count == 0 { return String($1).uppercased()} + return $0 + String($1) + } + } +} + +private extension MetadataResult { + convenience init(item: AppleTVv3.Item, content: AppleTVv3.Content? = nil ) { + self.init() + switch item.type { + + case "Movie": + + self.mediaKind = .movie + self[.name] = item.title + self[.serviceSeriesID] = item.id + + self[.genre] = item.genres?.first?.name + + if let releaseDate = item.releaseDate { + self[.releaseDate] = ISO8601DateFormatter().string(from: Date(timeIntervalSince1970: (releaseDate / 1000))) + } + + // Images + if let artworks = item.images?.compactMap( { $0.value.addArtwork(type: .poster, title: $0.key.replacingOccurrences(of: "16X9", with: "Widescreen").unCamel()) } ) { + self.remoteArtworks += artworks + } + // itunes + let group = DispatchGroup() + DispatchQueue.global().async(group: group) { + if let iTunesMetadata = iTunesStore.quickiTunesSearch(movieName: item.title ?? "") { + self.remoteArtworks += iTunesMetadata.remoteArtworks + } + } + group.wait() + self.remoteArtworks = Artwork.unique(artworks: self.remoteArtworks) + + + case "Show": + + self.mediaKind = .tvShow + self[.seriesName] = item.title + self[.serviceSeriesID] = item.id + + self[.genre] = item.genres?.first?.name + + if let episode = content { + + self[.serviceEpisodeID] = episode.id + + self[.name] = episode.title + self[.season] = episode.seasonNumber + self[.episodeNumber] = episode.episodeNumber + self[.genre] = episode.genres?.first?.name + self[.copyright] = episode.copyright + self[.network] = episode.network + self[.description] = episode.description + + self[.serviceAdditionalSeriesID] = episode.seasonId + + self[.episodeID] = String(format: "S%02dE%02d", episode.seasonNumber ?? 0, episode.episodeNumber ?? 0) + self[.cast] = episode.rolesSummary?.cast?.joined(separator: ", ") + self[.director] = episode.rolesSummary?.directors?.joined(separator: ", ") + + if let releaseDate = episode.releaseDate { + self[.releaseDate] = ISO8601DateFormatter().string(from: Date(timeIntervalSince1970: (releaseDate / 1000))) + } + + if let rating = episode.rating { + let prefix = rating.system + /*.replacingOccurrences(of: "_", with: "-")*/ + .uppercased() + self[.rating] = "\(prefix)|\(rating.displayName)|\(rating.value)|" + } + + // Images + if let artworks = item.images?.compactMap( { $0.value.addArtwork(type: .poster, title: $0.key.replacingOccurrences(of: "16X9", with: "Widescreen").unCamel()) } ) { + self.remoteArtworks += artworks + } + if let artworks = episode.images?.compactMap( { $0.value.addArtwork(type: .episode, title: $0.key.replacingOccurrences(of: "16X9", with: "Widescreen").unCamel()) } ) { + self.remoteArtworks += artworks + } + // itunes + let group = DispatchGroup() + DispatchQueue.global().async(group: group) { + if let iTunesMetadata = iTunesStore.quickiTunesSearch(tvSeriesName: item.title ?? "", seasonNum: episode.seasonNumber ?? 1, episodeNum: episode.episodeNumber ?? 1) { + self.remoteArtworks += iTunesMetadata.remoteArtworks + } + } + group.wait() + self.remoteArtworks = Artwork.unique(artworks: self.remoteArtworks) + } + + default: + + self[.name] = item.title + self[.serviceSeriesID] = item.id + self[.description] = item.type + + if let releaseDate = item.releaseDate { + self[.releaseDate] = ISO8601DateFormatter().string(from: Date(timeIntervalSince1970: (releaseDate / 1000))) + } + } + } + + func insert(contentOf content: AppleTVv3.Content) { + + self[.copyright] = content.copyright + self[.studio] = content.studio + self[.network] = content.network + + self[.cast] = content.rolesSummary?.cast?.joined(separator: ", ") + self[.director] = content.rolesSummary?.directors?.joined(separator: ", ") + + if let rating = content.rating { + let prefix = rating.system + /*.replacingOccurrences(of: "_", with: "-")*/ + .uppercased() + self[.rating] = "\(prefix)|\(rating.displayName)|\(rating.value)|" + } + + if self[.releaseDate] == nil { + if let releaseDate = content.releaseDate { + self[.releaseDate] = ISO8601DateFormatter().string(from: Date(timeIntervalSince1970: (releaseDate / 1000))) + } + } + + switch content.type { + case "Movie": + + self[.description] = content.description + + if let artworks = content.images?.compactMap( { $0.value.addArtwork(type: .poster, title: $0.key.replacingOccurrences(of: "16X9", with: "Widescreen").unCamel()) } ) { + self.remoteArtworks += artworks + } + self.remoteArtworks = Artwork.unique(artworks: self.remoteArtworks) + + case "Season": + + self[.seriesDescription] = content.description + // FIXME +// self[.seasonTitle] = content.title + + if let artworks = content.images?.compactMap( { $0.value.addArtwork(type: .season, title: $0.key.replacingOccurrences(of: "16X9", with: "Widescreen").unCamel()) } ) { + self.remoteArtworks += artworks + } + self.remoteArtworks = Artwork.unique(artworks: self.remoteArtworks) + + default: + print(content.type) + } + } + + func insert(contentOf items: [AppleTVv3.Item]) { + +// print("===== Cast & Crew =====") + + var cast: [String] = [] + var directors: [String] = [] + var producers: [String] = [] + var execProducers: [String] = [] + var writers: [String] = [] + var composers: [String] = [] + var creators: [String] = [] + var performers: [String] = [] + + for item in items { + +// print("[\(item.type)] \(item.roleTitle ?? "nil"): \(item.title ?? "nil") (\(item.characterName ?? "nil"))") + + if item.type == "Person" { + // TODO: roleTitle is localized so need some solution + if item.characterName != nil { + cast.append(item.title ?? "??") + } else { + + if item.roleTitle == "Actor" + || item.roleTitle == "演員" + || item.roleTitle == "演员" + || item.roleTitle == "出演者" + || item.roleTitle == "Interprete" + || item.roleTitle == "Reparto" + || item.roleTitle == "Schauspieler:in" + || item.roleTitle == "Interprétation" + || item.roleTitle == "الممثل" + || item.roleTitle == "Herec/herečka" + || item.roleTitle == "Skuespiller" + || item.roleTitle == "Näyttelijä" + || item.roleTitle == "Ηθοποιός" + || item.roleTitle == "Színész" + || item.roleTitle == "कलाकार" + || item.roleTitle == "Pemeran" + || item.roleTitle == "Pelakon" + || item.roleTitle == "משחק" + || item.roleTitle == "배우" + || item.roleTitle == "Acteur" + || item.roleTitle == "Aktor" + || item.roleTitle == "Elenco" + || item.roleTitle == "Актер/актриса" + || item.roleTitle == "Актор" + || item.roleTitle == "Skådespelare" + || item.roleTitle == "นักแสดง" + || item.roleTitle == "Aktör" + || item.roleTitle == "Diễn Viên" + || item.roleTitle == "Repartiment" { cast.append(item.title ?? "??")} + if item.roleTitle == "Voice" + || item.roleTitle == "配音" + || item.roleTitle == "声の出演" + || item.roleTitle == "Voce" + || item.roleTitle == "Stimmen" + || item.roleTitle == "Voix" + || item.roleTitle == "Veu" + || item.roleTitle == "الصوت" + || item.roleTitle == "Hlas" + || item.roleTitle == "Stemme" + || item.roleTitle == "Ääni" + || item.roleTitle == "Φωνή" + || item.roleTitle == "Narrátor" + || item.roleTitle == "קול" + || item.roleTitle == "성우" + || item.roleTitle == "Stem" + || item.roleTitle == "Głos" + || item.roleTitle == "Голос" + || item.roleTitle == "Озвучення" + || item.roleTitle == "Röst" + || item.roleTitle == "Seslendiren" + || item.roleTitle == "Lồng Tiếng" + || item.roleTitle == "Voz" { cast.append(item.title ?? "??")} + if item.roleTitle == "Self" + || item.roleTitle == "本人" + || item.roleTitle == "Als sich selbst" + || item.roleTitle == "Ell/a mateix/a" + || item.roleTitle == "Se stesso" + || item.roleTitle == "Dans son propre rôle" + || item.roleTitle == "ذاتي" + || item.roleTitle == "Osobně" + || item.roleTitle == "Osobne" + || item.roleTitle == "Sig selv" + || item.roleTitle == "Omana itsenään" + || item.roleTitle == "Αυτοπροσώπως" + || item.roleTitle == "Önmaga" + || item.roleTitle == "עצמי" + || item.roleTitle == "본인" + || item.roleTitle == "Zichzelf" + || item.roleTitle == "Seg selv" + || item.roleTitle == "W roli własnej" + || item.roleTitle == "Próprio papel" + || item.roleTitle == "В роли себя" + || item.roleTitle == "У ролі себе" + || item.roleTitle == "Sig själv" + || item.roleTitle == "Kendisi" + || item.roleTitle == "Bản Thân" + || item.roleTitle == "Rol propio" { cast.append(item.title ?? "??")} + if item.roleTitle == "Guest star" + || item.roleTitle == "Gaststar" + || item.roleTitle == "Estrella convidada" + || item.roleTitle == "Estrella invitada" { cast.append(item.title ?? "??")} + if item.roleTitle == "Director" + || item.roleTitle == "導演" + || item.roleTitle == "导演" + || item.roleTitle == "監督" + || item.roleTitle == "Regista" + || item.roleTitle == "Regie" + || item.roleTitle == "Réalisation" + || item.roleTitle == "Dirección" + || item.roleTitle == "إخراج" + || item.roleTitle == "Režie" + || item.roleTitle == "Réžia" + || item.roleTitle == "Instruktør" + || item.roleTitle == "Ohjaaja" + || item.roleTitle == "Σκηνοθέτης" + || item.roleTitle == "Rendező" + || item.roleTitle == "निर्देशक" + || item.roleTitle == "Sutradara" + || item.roleTitle == "Pengarah" + || item.roleTitle == "בימוי" + || item.roleTitle == "감독" + || item.roleTitle == "Regisseur" + || item.roleTitle == "Regissør" + || item.roleTitle == "Reżyser" + || item.roleTitle == "Realização" + || item.roleTitle == "Direção" + || item.roleTitle == "Режиссер" + || item.roleTitle == "Режисер" + || item.roleTitle == "Regissör" + || item.roleTitle == "ผู้กำกับ" + || item.roleTitle == "Yönetmen" + || item.roleTitle == "Đạo Diễn" + || item.roleTitle == "Direcció" { directors.append(item.title ?? "??")} + if item.roleTitle == "Producer" + || item.roleTitle == "製作人" + || item.roleTitle == "制作人" + || item.roleTitle == "プロデューサー" + || item.roleTitle == "Produzione" + || item.roleTitle == "Produzent:in" + || item.roleTitle == "Production" + || item.roleTitle == "Producción" + || item.roleTitle == "انتاج" + || item.roleTitle == "Produkce" + || item.roleTitle == "Produkcia" + || item.roleTitle == "Tuottaja" + || item.roleTitle == "Παραγωγός" + || item.roleTitle == "निर्माता" + || item.roleTitle == "Produser" + || item.roleTitle == "Penerbit" + || item.roleTitle == "הפקה" + || item.roleTitle == "제작" + || item.roleTitle == "Producent" + || item.roleTitle == "Produsent" + || item.roleTitle == "Produção" + || item.roleTitle == "Продюсер" + || item.roleTitle == "ผู้อำนวยการสร้าง" + || item.roleTitle == "Yapımcı" + || item.roleTitle == "Nhà Sản Xuất" + || item.roleTitle == "Producció" { producers.append(item.title ?? "??") } + if item.roleTitle == "Executive Producer" + || item.roleTitle == "Produzione esecutiva" + || item.roleTitle == "Producción ejecutiva" + || item.roleTitle == "Produção executiva" + || item.roleTitle == "Producció executiva" { execProducers.append(item.title ?? "??") } + if item.roleTitle == "Writer" + || item.roleTitle == "作者" + || item.roleTitle == "編劇" + || item.roleTitle == "编剧" + || item.roleTitle == "脚本" + || item.roleTitle == "Sceneggiatura" + || item.roleTitle == "Drehbuchautor:in" + || item.roleTitle == "Scénario" + || item.roleTitle == "Escritor" + || item.roleTitle == "Guió" + || item.roleTitle == "كتابة" + || item.roleTitle == "Scénář" + || item.roleTitle == "Scenár" + || item.roleTitle == "Manuskriptforfatter" + || item.roleTitle == "Käsikirjoittaja" + || item.roleTitle == "Συγγραφέας" + || item.roleTitle == "Író" + || item.roleTitle == "लेखक" + || item.roleTitle == "Penulis" + || item.roleTitle == "כתיבה" + || item.roleTitle == "작가" + || item.roleTitle == "Schrijver" + || item.roleTitle == "Manusforfatter" + || item.roleTitle == "Scenarzysta" + || item.roleTitle == "Argumento" + || item.roleTitle == "Roteiro" + || item.roleTitle == "Сценарист" + || item.roleTitle == "Författare" + || item.roleTitle == "ผู้เขียนบท" + || item.roleTitle == "Yazan" + || item.roleTitle == "Tác Giả" + || item.roleTitle == "Guion" { writers.append(item.title ?? "??")} + if item.roleTitle == "Music" + || item.roleTitle == "音樂" + || item.roleTitle == "音乐" + || item.roleTitle == "音楽" + || item.roleTitle == "음악" + || item.roleTitle == "Musik" + || item.roleTitle == "Musica" + || item.roleTitle == "الموسيقى" + || item.roleTitle == "מוזיקה" + || item.roleTitle == "Hudba" + || item.roleTitle == "Muzyka" + || item.roleTitle == "Muziek" + || item.roleTitle == "Musikk" + || item.roleTitle == "Musiikki" + || item.roleTitle == "Μουσική" + || item.roleTitle == "Zene" + || item.roleTitle == "संगीत" + || item.roleTitle == "ดนตรี" + || item.roleTitle == "Müzik" + || item.roleTitle == "Музыка" + || item.roleTitle == "Музика" + || item.roleTitle == "Nhạc" + || item.roleTitle == "Música" { composers.append(item.title ?? "??")} + if item.roleTitle == "Creator" + || item.roleTitle == "Creazione" + || item.roleTitle == "Creación" + || item.roleTitle == "Creació" { creators.append(item.title ?? "??")} + if item.roleTitle == "Performer" + || item.roleTitle == "演出者" + || item.roleTitle == "Artista" + || item.roleTitle == "Künstler" + || item.roleTitle == "Interprète" + || item.roleTitle == "Intérprete" { performers.append(item.title ?? "??")} + if item.roleTitle == "Narrator" + || item.roleTitle == "旁白" + || item.roleTitle == "叙述者" + || item.roleTitle == "ナレーター" + || item.roleTitle == "내레이터" + || item.roleTitle == "Narració" + || item.roleTitle == "الراوي" + || item.roleTitle == "קריינות" + || item.roleTitle == "Narrazione" + || item.roleTitle == "Verteller" + || item.roleTitle == "Narrátor" + || item.roleTitle == "Erzähler" + || item.roleTitle == "Αφηγητής" + || item.roleTitle == "Vypráví" + || item.roleTitle == "Narator" + || item.roleTitle == "Rozpráva" + || item.roleTitle == "Kertoja" + || item.roleTitle == "Fortæller" + || item.roleTitle == "Fortellerstemme" + || item.roleTitle == "Berättarröst" + || item.roleTitle == "कथावाचक" + || item.roleTitle == "Рассказчик" + || item.roleTitle == "Диктор" + || item.roleTitle == "Anlatıcı" + || item.roleTitle == "Narração" + || item.roleTitle == "Người Dẫn Chuyện" + || item.roleTitle == "Narración" { cast.append(item.title ?? "??")} + if item.roleTitle == "Host" + || item.roleTitle == "Presentador/a" + || item.roleTitle == "Conducció" + || item.roleTitle == "Presentatore" + || item.roleTitle == "Moderator:in" + || item.roleTitle == "Presentación" { cast.append(item.title ?? "??")} + } + } + + self[.cast] = cast.joined(separator: ", ") + self[.director] = directors.joined(separator: ", ") + self[.producers] = producers.joined(separator: ", ") + self[.executiveProducer] = execProducers.joined(separator: ", ") + self[.screenwriters] = writers.joined(separator: ", ") + self[.composer] = composers.joined(separator: ", ") + + + if let artworks = item.images?.compactMap( { $0.value.addArtwork(type: .person, title: item.title ?? $0.key.unCamel() ) } ) { + self.remoteArtworks += artworks + } + self.remoteArtworks = Artwork.unique(artworks: self.remoteArtworks) + + } + + } +} + +public struct AppleTVv3: MetadataService { + + // MARK: Static constants + + private static let AppleTVAPI = "Apple TV" + private static let DefaultCountry = "US" + private static let DefaultLanguageCode = "en_US" + private static let StorefrontsFile = "Storefronts" + private static let Alpha2File = "Alpha2" + private static let TypeJSON = "json" + + private static let FullsizeArtwork = "1600x1600.jpg" + private static let ThumbnailArtwork = "330x330.jpg" + + // MARK: Set up URL + private static let defaultVersion = "82" + private static let defaultCaller = "js" + + private static let castShelfId = "uts.col.CastAndCrew" + + public enum searchFilter { + case movies + case tvshows + case sports + case channels + case castcrew + case topresults + + var filter: String { + switch self { + case .castcrew: return "uts.col.search.PN" + case .channels: return "uts.col.search.BR" + case .movies: return "uts.col.search.MV" + case .sports: return "uts.col.search.SE" + case .topresults: return "uts.col.search.TR" + case .tvshows: return "uts.col.search.SH" + } + } + } + + private static let urlComponents = URLComponents(staticString: "https://uts-api.itunes.apple.com/") + + private static let configurationsPath = "/uts/v3/configurations" + private static let searchPath = "/uts/v3/search" + private static let showsPath = "/uts/v3/shows" + private static let seasonsPath = "/uts/v3/seasons" + private static let episodesPath = "/uts/v3/episodes/" + private static let moviesPath = "/uts/v3/movies" + + private static let qualifierEpisodes = "/episodes" + private static let qualifierMetadata = "/metadata" + + private func JSONRequest(components: URLComponents, type: T.Type) -> T? where T : Decodable { + guard let url = components.url else { return nil } + //print(url) + do { + guard let data = URLSession.data(from: url) else { return nil } + return try JSONDecoder().decode(type, from: data) + } catch { + print(error) + return nil + } + } + + // MARK: Configuration + + private var current = CurrentConfiguration() + + private class CurrentConfiguration { + var config: [String:String?] = [ + "caller":defaultCaller, + "v":defaultVersion, + "locale":"auto" + ] + + public func set(store: (Int, String)) { + config["sf"] = String(store.0) + config["locale"] = store.1 + } + + public func set(key: String, value: String) { + config[key] = value + } + + public func get(key: String) -> String? { + if let value = config[key] { return value } + return nil + } + + public func configurationRequired() -> Bool { + return (get(key: "utsk") == nil) || (get(key: "utscf") == nil) || (get(key: "pfm") == nil) + } + + public func configuration() -> [URLQueryItem] { + return config.compactMap({URLQueryItem(name: $0.key, value: $0.value)}) + } + } + + private func urlConfiguration(storefront: Int, language: String = "auto") { + + current.set(store: (storefront,language)) + + guard current.configurationRequired() else { return } + + var components = AppleTVv3.urlComponents + components.path = AppleTVv3.configurationsPath + components.queryItems = current.configuration() + + if let results = JSONRequest(components: components, type: DataWrapper.self)? + .data.applicationProps.requiredParamsMap.Default { + current.set(key: "utsk", value: results.utsk) + current.set(key: "utscf", value: results.utscf) + current.set(key: "pfm", value: results.pfm) + } + + } + + // Create list of all Apple storefronts + struct Storefront: Codable { + + fileprivate let data: [String:StorefrontDetail] + + fileprivate struct StorefrontDetail: Codable { + let localesSupported: [String] + let storefrontId: Int + } + + fileprivate static let storefronts: Storefront? = { + guard let url = Bundle.main.url(forResource: StorefrontsFile, withExtension: TypeJSON) else { return nil } + return try? JSONDecoder().decode(Storefront.self, from: try Data(contentsOf: url)) + }() + + fileprivate static func language(from countryCode: String, countryLanguages: [String]) -> [String] { return countryLanguages.map { "\(getCountryName(countryCode) ?? "Unknown") (\(languageDecode($0)))" } + } + + public static func getCountryCode(storefront: Int) -> String? { + guard let country = Storefront.storefronts?.data.filter({ $0.value.storefrontId == storefront }).first else { return nil } + return country.key + } + + public static func getCountryCode(name: String) -> String? { + guard let url = Bundle.main.url(forResource: Alpha2File, withExtension: TypeJSON) else { return nil } + if let results = try? JSONDecoder().decode([String:String].self, from: try Data(contentsOf: url)).filter({ $0.value == name }) { + return results.first?.key ?? nil + } + return nil + } + + public static func getCountryName(_ code: String) -> String? { + guard let url = Bundle.main.url(forResource: Alpha2File, withExtension: TypeJSON) else { return nil } + if let results = try? JSONDecoder().decode([String:String].self, from: try Data(contentsOf: url)).filter({ $0.key == code }) { + return results.first?.value ?? nil + } + return nil + } + + private static func languageDecode(_ code: String) -> String { + let code = code.split(separator: "_") + guard code.count == 2 else { return "" } + return "\(MP42Languages.defaultManager .localizedLang(forExtendedTag: String(code[0]))) \(String(code[1]))" + } + + public static func getStorefront(from country: String) -> (Int, String)? { + let split = country.components(separatedBy: " (") + guard let storefront = storefronts?.data.first(where: { + getCountryName($0.key) == split[0] } ), + let language = storefront.value.localesSupported.first(where: { "\(languageDecode($0)))" == split[1] }) else { return nil } + return (storefront.value.storefrontId, language) + } + } + + + public var languageType: LanguageType { return .custom } + + public var languages: [String] { + get { + guard let results = Storefront.storefronts?.data + .compactMap({ Storefront.language(from: $0.key, countryLanguages: $0.value.localesSupported) }) + .flatMap({ $0 }) + .sorted() else { return [] } + return results + } + } + + public var defaultLanguage: String { get { return Storefront.language(from: AppleTVv3.DefaultCountry, countryLanguages: [AppleTVv3.DefaultLanguageCode]).first ?? "Unknown" } } + + public var name: String { return AppleTVv3.AppleTVAPI } + + public func search(tvShow: String, language: String) -> [String] { + return [] + } + + public func search(tvShow: String, language: String, season: Int?, episode: Int?) -> [MetadataResult] { + + if let storefront = Storefront.getStorefront(from: language) { + urlConfiguration(storefront: storefront.0, language: storefront.1) + } + + let results = search(term: tvShow, filter: .tvshows) + let show = results.first(where: { $0.title?.caseInsensitiveCompare(tvShow) == .orderedSame }) ?? results.first + + guard let show = show else { return [] } + + let contentResults = getEpisodes(showId: show.id, season: season, episode: episode) + + return contentResults.map { MetadataResult(item: show, content: $0 )} + } + + public func loadTVMetadata(_ metadata: MetadataResult, language: String) -> MetadataResult { + return details(metadata) + } + + public func search(movie: String, language: String) -> [MetadataResult] { + + if let storefront = Storefront.getStorefront(from: language) { + urlConfiguration(storefront: storefront.0, language: storefront.1) + } + + return search(term: movie, filter: .movies).map { MetadataResult(item: $0) } + } + + public func loadMovieMetadata(_ metadata: MetadataResult, language: String) -> MetadataResult { + return details(metadata) + } + + public enum MediaType { + case movie + case tvShow(season: Int?) + + var description: String { + get { + switch self { + case .movie: + return "Movie" + case .tvShow: + return "Show" + } + } + } + } + + func searchArtwork(term: String, store: iTunesStore.Store, type: MediaType = .movie) -> [Artwork] { + urlConfiguration(storefront: store.storeCode) + + let results = search(term: term, filter: .topresults ) + + guard let artworks = results.first?.images?.compactMap( { $0.value.addArtwork(type: .poster) } ) else { return [] } + + return artworks + } + + private func search(term: String, filter: searchFilter) -> [Item] { + + var components = AppleTVv3.urlComponents + components.path = AppleTVv3.searchPath + components.queryItems = current.configuration() + components.queryItems?.append(URLQueryItem(name: "searchTerm", value: term)) + + if filter == .topresults { + components.queryItems?.append(URLQueryItem(name: "topResultsOnly", value: "true")) + } + + guard let results = JSONRequest(components: components, type: DataWrapper.self) else { return [] } + guard let item = results.data.canvas?.shelves? + .filter({ $0.id == filter.filter }) + .compactMap({ $0.items }) + .flatMap({ $0 }) else { return [] } + return item + + } + + private func details(_ metadata: MetadataResult) -> MetadataResult { + + guard let id = metadata[.serviceSeriesID] else { return metadata } + + if metadata.mediaKind == .movie { + + var components = AppleTVv3.urlComponents + components.path = AppleTVv3.moviesPath + "/\(id)" + components.queryItems = current.configuration() + + guard let results = JSONRequest(components: components, type: DataWrapper.self) else { return metadata } + guard let content = results.data.content else { return metadata } + metadata.insert(contentOf: content) + + guard let cast = results.data.canvas?.shelves? + .filter({ $0.id == AppleTVv3.castShelfId }) + .first?.items else { return metadata } + metadata.insert(contentOf: cast) + + } + + if metadata.mediaKind == .tvShow { + + guard let sID = metadata[.serviceAdditionalSeriesID] else { return metadata } + + var components = AppleTVv3.urlComponents + components.path = AppleTVv3.seasonsPath + "/\(sID)" + AppleTVv3.qualifierMetadata + components.queryItems = current.configuration() + + guard let results = JSONRequest(components: components, type: ContentDetail.self) else { return metadata } + metadata.insert(contentOf: results.data) + + guard let shID = metadata[.serviceSeriesID] else { return metadata } + components.path = AppleTVv3.showsPath + "/\(shID)" + guard let results = JSONRequest(components: components, type: DataWrapper.self) else { return metadata } + + guard let cast = results.data.canvas?.shelves? + .filter({ $0.id == AppleTVv3.castShelfId }) + .first?.items else { return metadata } + metadata.insert(contentOf: cast) + + } + + return metadata + } + + private func getEpisodes(showId: String, season: Int? = nil, episode: Int? = nil) -> [Content] { + + var components = AppleTVv3.urlComponents + components.path = AppleTVv3.showsPath + "/\(showId)" + AppleTVv3.qualifierEpisodes + components.queryItems = current.configuration() + components.queryItems?.append(URLQueryItem(name: "nextToken", value: "0:1")) + components.queryItems?.append(URLQueryItem(name: "includeSeasonSummary", value: "true")) + + guard let results = JSONRequest(components: components, type: DataWrapper.self) else { return [] } + + components.queryItems = current.configuration() + + if season != nil { + if let summaries = results.data.seasonSummaries { + var startToken = 0, endToken = 1 + for s in summaries { + if s.seasonNumber == season { + if let e = episode { + startToken += e - 1 + } else { + endToken += s.episodeCount - 1 + } + } else if s.seasonNumber > season! { + } else { + startToken += s.episodeCount + } + } + components.queryItems?.append(URLQueryItem(name: "nextToken", value: "\(startToken):\(endToken)")) + } + + } else { + let token = results.data.totalEpisodeCount + components.queryItems?.append(URLQueryItem(name: "nextToken", value: "0:\(token)")) + } + + + guard let results = JSONRequest(components: components, type: DataWrapper.self) else { return [] } + + return results.data.episodes ?? [] + } + + // MARK: JSON structs + + private struct DataWrapper: Codable where T : Codable { + let data: T + } + + private struct ContentDetail: Codable { + let data: Content + } + + private struct ConfigurationCodable: Codable { + let applicationProps: ApplicationProps + struct ApplicationProps: Codable { let requiredParamsMap: RequiredParamsMap} + struct RequiredParamsMap: Codable { let Default: RequiredParams } + } + + private struct RequiredParams: Codable { + let caller: String + let locale: String + let utscf: String + let utsk: String + let pfm: String + let sf: String + let v: String + } + + private struct GeneralResult: Codable { + let canvas: Canvas? + let content: Content? + struct Canvas: Codable { let shelves: [Shelf]? } + } + + private struct Shelf: Codable { + let displayType: String? + let id: String + let markerType: String? + let title: String? + let url: URL? + let items: [Item]? + } + + private struct ShowEpisodes: Codable { + let episodes: [Content]? + let seasonSummaries: [SeasonSummary]? + let selectedEpisodeIndex: Int? + let totalEpisodeCount: Int + } + + private struct SeasonSummary: Codable { + let episodeCount: Int + let id: String + let seasonNumber: Int + let title: String + } + + fileprivate struct Item: Codable { + let genres: [Genre]? + let id: String + let images: [String:Image]? + let releaseDate: TimeInterval? + let title: String? + let type: String + let url: URL? + let airingType: String? + let endAirTime: TimeInterval? + let isGeoRestricted: Bool? + let leagueAbbreviation: String? + let leagueId: String? + let leagueName: String? + let leagueShortName: String? + let shortTitle: String? + let showVersions: Bool? + let sportId: String? + let sportName: String? + let startAirTime: TimeInterval? + let startTime: TimeInterval? + let flavorType: String? + let isExternalUrl: Bool? + let shortNote: String? + let tagLine: String? + let characterName: String? + let roleTitle: String? + } + + fileprivate struct Content: Codable { + let commonSenseMedia: CommonSenseMedia? + let copyright: String? + let countriesOfOrigin: [CountryCode]? + let description: String? + let duration: Int? + let genres: [Genre]? + let id: String + let images: [String:Image]? + let network: String? + let originalSpokenLanguages: [Language]? + let rating: Rating? + let releaseDate: TimeInterval? + let rolesSummary: Roles? + let studio: String? + let title: String + let type: String + let url: URL? + let episodeIndex: Int? + let episodeNumber: Int? + let fractionalEpisodeNumber: Float? + let isFirstEpisode: Bool? + let seasonId: String? + let seasonNumber: Int? + let seasonUrl: URL? + let showId: String? + let showTitle: String? + let showUrl: URL? + } + + fileprivate struct Genre: Codable { + let id: String + let name: String + let type: String + let url: URL + } + + fileprivate struct Roles: Codable { + let cast: [String]? + let directors: [String]? + } + + fileprivate struct CountryCode: Codable { + let countryCode: String + let displayName: String + } + + fileprivate struct Language: Codable { + let displayName: String + let locale: String + } + + fileprivate struct Rating: Codable { + let displayName: String + let name: String + let system: String + let systemType: String + let value: Int + } + + fileprivate struct CommonSenseMedia: Codable { + let contentInfo: [CommonSenseContentInfo] + let oneLiner: String + let recommendedAge: Int + } + + fileprivate struct CommonSenseContentInfo: Codable { + let label: String + let rating: Int + } + + fileprivate struct Image: Codable { + let height: Int + let width: Int + let supportsLayeredImage: Bool + let url: String + + var size: ArtworkSize { + get { + if 100*width/height == 46 { return .vertical } + if 100*width/height == 144 { return .fullscreen } + if 100*width/height == 177 { return .widescreen } + if width == height { return .square } + if width > height { return .rectangle } + return .standard + } + } + + func addArtwork(type: ArtworkType, title: String = "Apple TV") -> Artwork? { + guard var c = URLComponents(string: url) else { return nil } + c.path = String(c.path[..<(c.path.lastIndex(of: "/") ?? c.path.endIndex)]) + "/\(AppleTVv3.FullsizeArtwork)" + guard let fullsizeURL = c.url else { return nil } + c.path = String(c.path[..<(c.path.lastIndex(of: "/") ?? c.path.endIndex)]) + "/\(AppleTVv3.ThumbnailArtwork)" + guard let thumbnailURL = c.url else { return nil } + return Artwork(url: fullsizeURL, thumbURL: thumbnailURL, service: title , type: type, size: size) + } + + } +} + diff --git a/Classes/MetadataImporters/MetadataResult.swift b/Classes/MetadataImporters/MetadataResult.swift index e293d8b..cd24f66 100644 --- a/Classes/MetadataImporters/MetadataResult.swift +++ b/Classes/MetadataImporters/MetadataResult.swift @@ -19,12 +19,36 @@ public enum ArtworkSize : Int, CustomStringConvertible { return "square" case .rectangle: return "rectangle" + case .vertical: + return "vertical" + case .fullscreen: + return "fullscreen" + case .widescreen: + return "widescreen" + case .maxres: + return "maxres" + case .low: + return "low" + case .medium: + return "medium" + case .high: + return "high" + case .`default`: + return "default" } } case standard case square case rectangle + case vertical + case fullscreen + case widescreen + case maxres + case low + case medium + case high + case `default` } public enum ArtworkType : Int, CustomStringConvertible { @@ -38,6 +62,8 @@ public enum ArtworkType : Int, CustomStringConvertible { return "episode" case .backdrop: return "backdrop" + case .person: + return "person" case .none: return NSLocalizedString("None", comment: "Queue metadata search artwork type") @@ -57,15 +83,34 @@ public enum ArtworkType : Int, CustomStringConvertible { case season case episode case backdrop + case person case none } -public struct Artwork { +public struct Artwork: Equatable, Hashable { public let url: URL public let thumbURL: URL public let service: String public let type: ArtworkType public let size: ArtworkSize + + public static func == (lhs: Artwork, rhs: Artwork) -> Bool { + return lhs.url == rhs.url + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(url) + } + + public static func unique(artworks: [Artwork]) -> [Artwork] { + var uniques = [Artwork]() + for artwork in artworks { + if !uniques.contains(artwork) { + uniques.append(artwork) + } + } + return uniques + } } public enum MediaKind: Int { diff --git a/Storefronts.json b/Storefronts.json new file mode 100644 index 0000000..42d211d --- /dev/null +++ b/Storefronts.json @@ -0,0 +1,445 @@ +{ + "data" : { + "AE" : { + "localesSupported" : [ "en_GB", "ar_AE" ], + "storefrontId" : 143481 + }, + "AG" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143540 + }, + "AI" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143538 + }, + "AM" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143524 + }, + "AR" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143505 + }, + "AT" : { + "localesSupported" : [ "en_GB", "de_DE" ], + "storefrontId" : 143445 + }, + "AU" : { + "localesSupported" : [ "en_AU" ], + "storefrontId" : 143460 + }, + "AZ" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143568 + }, + "BE" : { + "localesSupported" : [ "nl_NL", "en_GB", "fr_FR" ], + "storefrontId" : 143446 + }, + "BG" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143526 + }, + "BH" : { + "localesSupported" : [ "en_GB", "ar_BH" ], + "storefrontId" : 143559 + }, + "BM" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143542 + }, + "BN" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143560 + }, + "BO" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143556 + }, + "BR" : { + "localesSupported" : [ "en_GB", "pt_BR" ], + "storefrontId" : 143503 + }, + "BS" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143539 + }, + "BW" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143525 + }, + "BY" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143565 + }, + "BZ" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143555 + }, + "CA" : { + "localesSupported" : [ "fr_CA", "en_CA" ], + "storefrontId" : 143455 + }, + "CH" : { + "localesSupported" : [ "de_DE", "fr_FR", "de_CH", "en_GB", "it_IT" ], + "storefrontId" : 143459 + }, + "CL" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143483 + }, + "CO" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143501 + }, + "CR" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143495 + }, + "CV" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143580 + }, + "CY" : { + "localesSupported" : [ "tr_TR", "en_GB", "el_GR" ], + "storefrontId" : 143557 + }, + "CZ" : { + "localesSupported" : [ "en_GB", "cs_CZ" ], + "storefrontId" : 143489 + }, + "DE" : { + "localesSupported" : [ "en_GB", "de_DE" ], + "storefrontId" : 143443 + }, + "DK" : { + "localesSupported" : [ "en_GB", "da_DK" ], + "storefrontId" : 143458 + }, + "DM" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143545 + }, + "DO" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143508 + }, + "EC" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143509 + }, + "EE" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143518 + }, + "EG" : { + "localesSupported" : [ "en_GB", "ar_EG" ], + "storefrontId" : 143516 + }, + "ES" : { + "localesSupported" : [ "ca_ES", "en_GB", "es_ES" ], + "storefrontId" : 143454 + }, + "FI" : { + "localesSupported" : [ "fi_FI", "en_GB" ], + "storefrontId" : 143447 + }, + "FJ" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143583 + }, + "FM" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143591 + }, + "FR" : { + "localesSupported" : [ "en_GB", "fr_FR" ], + "storefrontId" : 143442 + }, + "GB" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143444 + }, + "GD" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143546 + }, + "GH" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143573 + }, + "GM" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143584 + }, + "GR" : { + "localesSupported" : [ "el_GR", "en_GB" ], + "storefrontId" : 143448 + }, + "GT" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143504 + }, + "GW" : { + "localesSupported" : [ "en_GB", "fr_FR" ], + "storefrontId" : 143585 + }, + "HK" : { + "localesSupported" : [ "yue_Hant", "en_GB", "zh_Hant" ], + "storefrontId" : 143463 + }, + "HN" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143510 + }, + "HU" : { + "localesSupported" : [ "en_GB", "hu_HU" ], + "storefrontId" : 143482 + }, + "ID" : { + "localesSupported" : [ "en_GB", "id_ID" ], + "storefrontId" : 143476 + }, + "IE" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143449 + }, + "IL" : { + "localesSupported" : [ "en_GB", "iw_IL" ], + "storefrontId" : 143491 + }, + "IN" : { + "localesSupported" : [ "en_GB", "hi_IN" ], + "storefrontId" : 143467 + }, + "IT" : { + "localesSupported" : [ "it_IT", "en_GB" ], + "storefrontId" : 143450 + }, + "JO" : { + "localesSupported" : [ "en_GB", "ar_JO" ], + "storefrontId" : 143528 + }, + "JP" : { + "localesSupported" : [ "en_US", "ja_JP" ], + "storefrontId" : 143462 + }, + "KH" : { + "localesSupported" : [ "en_GB", "fr_FR" ], + "storefrontId" : 143579 + }, + "KN" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143548 + }, + "KR" : { + "localesSupported" : [ "en_GB", "ko_KR" ], + "storefrontId" : 143466 + }, + "KY" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143544 + }, + "LA" : { + "localesSupported" : [ "en_GB", "fr_FR" ], + "storefrontId" : 143587 + }, + "LB" : { + "localesSupported" : [ "en_GB", "ar_LB" ], + "storefrontId" : 143497 + }, + "LK" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143486 + }, + "LT" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143520 + }, + "LU" : { + "localesSupported" : [ "en_GB", "de_DE", "fr_FR" ], + "storefrontId" : 143451 + }, + "LV" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143519 + }, + "MD" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143523 + }, + "MN" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143592 + }, + "MO" : { + "localesSupported" : [ "yue_Hant", "en_GB", "zh_Hant" ], + "storefrontId" : 143515 + }, + "MT" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143521 + }, + "MU" : { + "localesSupported" : [ "en_GB", "fr_FR" ], + "storefrontId" : 143533 + }, + "MX" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143468 + }, + "MY" : { + "localesSupported" : [ "ms_MY", "en_GB" ], + "storefrontId" : 143473 + }, + "MZ" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143593 + }, + "NA" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143594 + }, + "NE" : { + "localesSupported" : [ "en_GB", "fr_FR" ], + "storefrontId" : 143534 + }, + "NI" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143512 + }, + "NL" : { + "localesSupported" : [ "en_GB", "nl_NL" ], + "storefrontId" : 143452 + }, + "NO" : { + "localesSupported" : [ "nb_NO", "en_GB" ], + "storefrontId" : 143457 + }, + "NZ" : { + "localesSupported" : [ "en_GB", "en_AU" ], + "storefrontId" : 143461 + }, + "OM" : { + "localesSupported" : [ "ar_OM", "en_GB" ], + "storefrontId" : 143562 + }, + "PA" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143485 + }, + "PE" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143507 + }, + "PH" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143474 + }, + "PL" : { + "localesSupported" : [ "en_GB", "pl_PL" ], + "storefrontId" : 143478 + }, + "PT" : { + "localesSupported" : [ "en_GB", "pt_PT" ], + "storefrontId" : 143453 + }, + "PY" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143513 + }, + "QA" : { + "localesSupported" : [ "ar_QA", "en_GB" ], + "storefrontId" : 143498 + }, + "RU" : { + "localesSupported" : [ "en_GB", "uk_UA", "ru_RU" ], + "storefrontId" : 143469 + }, + "SA" : { + "localesSupported" : [ "ar_SA", "en_GB" ], + "storefrontId" : 143479 + }, + "SE" : { + "localesSupported" : [ "en_GB", "sv_SE" ], + "storefrontId" : 143456 + }, + "SG" : { + "localesSupported" : [ "zh_Hans", "en_GB" ], + "storefrontId" : 143464 + }, + "SI" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143499 + }, + "SK" : { + "localesSupported" : [ "en_GB", "sk_SK" ], + "storefrontId" : 143496 + }, + "SV" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143506 + }, + "SZ" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143602 + }, + "TH" : { + "localesSupported" : [ "en_GB", "th_TH" ], + "storefrontId" : 143475 + }, + "TJ" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143603 + }, + "TM" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143604 + }, + "TR" : { + "localesSupported" : [ "en_GB", "tr_TR" ], + "storefrontId" : 143480 + }, + "TT" : { + "localesSupported" : [ "en_GB", "fr_FR" ], + "storefrontId" : 143551 + }, + "TW" : { + "localesSupported" : [ "en_GB", "zh_Hant" ], + "storefrontId" : 143470 + }, + "UA" : { + "localesSupported" : [ "en_GB", "uk_UA", "ru_RU" ], + "storefrontId" : 143492 + }, + "UG" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143537 + }, + "US" : { + "localesSupported" : [ "en_US", "es_MX" ], + "storefrontId" : 143441 + }, + "VE" : { + "localesSupported" : [ "en_GB", "es_MX" ], + "storefrontId" : 143502 + }, + "VG" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143543 + }, + "VN" : { + "localesSupported" : [ "vi_VI", "en_GB" ], + "storefrontId" : 143471 + }, + "ZA" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143472 + }, + "ZW" : { + "localesSupported" : [ "en_GB" ], + "storefrontId" : 143605 + } + } +} + diff --git a/Subler.xcodeproj/project.pbxproj b/Subler.xcodeproj/project.pbxproj index b1acf24..1a2d864 100644 --- a/Subler.xcodeproj/project.pbxproj +++ b/Subler.xcodeproj/project.pbxproj @@ -86,6 +86,7 @@ A99189D11F2F88F700623ED7 /* ChapterSearchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A99189D01F2F88F700623ED7 /* ChapterSearchController.swift */; }; A997B0AA1F348AB000974C9C /* MetadataSearchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A997B0A91F348AB000974C9C /* MetadataSearchController.swift */; }; A998DABF1BA54CFF004D7969 /* MediaTagsController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A998DABD1BA54CFF004D7969 /* MediaTagsController.xib */; }; + A99B7FD82D53764F0027BCB5 /* AppleTVv3.swift in Sources */ = {isa = PBXBuildFile; fileRef = A99B7FD72D53764F0027BCB5 /* AppleTVv3.swift */; }; A99D23212029CD32002E7F27 /* PrefsWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A99D23202029CD32002E7F27 /* PrefsWindow.swift */; }; A9A4A966202F51FA00482D12 /* SaveOptions.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9A4A968202F51FA00482D12 /* SaveOptions.xib */; }; A9A4A96B202F51FF00482D12 /* ProgressViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9A4A96D202F51FF00482D12 /* ProgressViewController.xib */; }; @@ -115,6 +116,8 @@ A9C3E44A205C07F4004DE24E /* OptionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C3E449205C07F4004DE24E /* OptionsViewController.swift */; }; A9C5FA7419FA2FEC0051F3FF /* SBActivityWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9C5FA7219FA2FEC0051F3FF /* SBActivityWindow.xib */; }; A9C73536206B8F9900794673 /* QueuePreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C73535206B8F9900794673 /* QueuePreferences.swift */; }; + A9CB19022D10415D0074DC9F /* Storefronts.json in Resources */ = {isa = PBXBuildFile; fileRef = A9CB19012D10415D0074DC9F /* Storefronts.json */; }; + A9CB19052D10417D0074DC9F /* Alpha2.json in Resources */ = {isa = PBXBuildFile; fileRef = A9CB19042D10417D0074DC9F /* Alpha2.json */; }; A9CBAB1E1F29C083001C26B3 /* MetadataImporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CBAB1D1F29C083001C26B3 /* MetadataImporter.swift */; }; A9D4B8671C05BD04007845C4 /* SBChapterSearch.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9D4B8651C05BD04007845C4 /* SBChapterSearch.xib */; }; A9D64527202CA92400BA172B /* SaveOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D64525202CA92400BA172B /* SaveOptions.swift */; }; @@ -351,6 +354,7 @@ A99189CC1F2F87EC00623ED7 /* ChapterImporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ChapterImporter.swift; path = Classes/MetadataImporters/ChapterImporter.swift; sourceTree = ""; }; A99189D01F2F88F700623ED7 /* ChapterSearchController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ChapterSearchController.swift; path = Classes/ChapterSearchController.swift; sourceTree = ""; }; A997B0A91F348AB000974C9C /* MetadataSearchController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MetadataSearchController.swift; path = Classes/MetadataSearchController.swift; sourceTree = ""; }; + A99B7FD72D53764F0027BCB5 /* AppleTVv3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppleTVv3.swift; path = Classes/MetadataImporters/AppleTVv3.swift; sourceTree = ""; }; A99D23202029CD32002E7F27 /* PrefsWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PrefsWindow.swift; path = Classes/PrefsWindow.swift; sourceTree = ""; }; A9A4A967202F51FA00482D12 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/SaveOptions.xib; sourceTree = ""; }; A9A4A96C202F51FF00482D12 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ProgressViewController.xib; sourceTree = ""; }; @@ -391,6 +395,8 @@ A9C31E632029A82200CEF474 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/AdvancedPrefsViewController.xib; sourceTree = ""; }; A9C3E449205C07F4004DE24E /* OptionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OptionsViewController.swift; path = Classes/OptionsViewController.swift; sourceTree = ""; }; A9C73535206B8F9900794673 /* QueuePreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = QueuePreferences.swift; path = Classes/QueuePreferences.swift; sourceTree = ""; }; + A9CB19012D10415D0074DC9F /* Storefronts.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = Storefronts.json; sourceTree = ""; }; + A9CB19042D10417D0074DC9F /* Alpha2.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = Alpha2.json; sourceTree = ""; }; A9CBAB1D1F29C083001C26B3 /* MetadataImporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MetadataImporter.swift; path = Classes/MetadataImporters/MetadataImporter.swift; sourceTree = ""; }; A9D64525202CA92400BA172B /* SaveOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SaveOptions.swift; path = Classes/SaveOptions.swift; sourceTree = ""; }; A9DA03E122A0211C0056AE7B /* OCRPrefsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OCRPrefsViewController.swift; path = Classes/OCRPrefsViewController.swift; sourceTree = ""; }; @@ -530,6 +536,8 @@ 089C165FFE840EACC02AAC07 /* InfoPlist.strings */, 8D15AC360486D014006FF6A4 /* Info.plist */, CDE8E451174CBBD4009410B5 /* iTunesStores.json */, + A9CB19012D10415D0074DC9F /* Storefronts.json */, + A9CB19042D10417D0074DC9F /* Alpha2.json */, A97FA42123E9877900EE5833 /* Ratings.json */, A94A6A581ED1C5CA00049F7D /* ParseFilename */, ); @@ -705,6 +713,7 @@ A97FA41D23E9837000EE5833 /* Ratings.swift */, A9E97F131F274F1100DBA586 /* iTunesStore.swift */, A90B094B235614D200F1B191 /* AppleTV.swift */, + A99B7FD72D53764F0027BCB5 /* AppleTVv3.swift */, A98D98451F0280CB00A77ABC /* TheMovieDB.swift */, A98D98471F02820F00A77ABC /* TheMovieDBService.swift */, A9B514181EFC12310055A035 /* TheTVDB.swift */, @@ -752,7 +761,7 @@ isa = PBXProject; attributes = { BuildIndependentTargetsInParallel = YES; - LastUpgradeCheck = 1610; + LastUpgradeCheck = 1620; TargetAttributes = { 8D15AC270486D014006FF6A4 = { LastSwiftMigration = 1020; @@ -821,6 +830,7 @@ buildActionMask = 2147483647; files = ( A9EEA5F818D654B9008B54B4 /* QueueOptions.xib in Resources */, + A9CB19022D10415D0074DC9F /* Storefronts.json in Resources */, A9AB486617F0AEFD000AA72E /* MovieView.xib in Resources */, A9C31E5D2029A79000CEF474 /* GeneralPrefsViewController.xib in Resources */, A98542DD20D1A7E500EB9803 /* ArtworkSelectorViewItem.xib in Resources */, @@ -850,6 +860,7 @@ A98542D720D197D300EB9803 /* ArtworkSelector.xib in Resources */, A9ECA0602029A13800D5F30C /* OffsetViewController.xib in Resources */, A9ACF03222A2BCF200AD5B12 /* OCRPrefsViewController.xib in Resources */, + A9CB19052D10417D0074DC9F /* Alpha2.json in Resources */, A97FA42223E9877900EE5833 /* Ratings.json in Resources */, A961476713F568210068F161 /* Queue.xib in Resources */, A9BA1AF31DBF7DD800FD0B38 /* Localizable.strings in Resources */, @@ -928,6 +939,7 @@ A9C31E572029A75F00CEF474 /* GeneralPrefsViewController.swift in Sources */, A9AE26C01F3B66470041A57D /* SquaredTVArt.swift in Sources */, A9B1056E2025D9B9009E91FC /* TracksViewController.swift in Sources */, + A99B7FD82D53764F0027BCB5 /* AppleTVv3.swift in Sources */, A9B514191EFC12310055A035 /* TheTVDB.swift in Sources */, A9C31E602029A80F00CEF474 /* AdvancedPrefsViewController.swift in Sources */, A979B3862025C8BF00468362 /* DocumentWindowController.swift in Sources */, @@ -1463,6 +1475,7 @@ C05733CC08A9546B00998B17 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; ASSETCATALOG_COMPILER_OPTIMIZATION = space; CLANG_ANALYZER_GCD_PERFORMANCE = YES; CLANG_ANALYZER_LOCALIZABILITY_EMPTY_CONTEXT = YES; @@ -1551,6 +1564,7 @@ C05733CD08A9546B00998B17 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; ASSETCATALOG_COMPILER_OPTIMIZATION = space; CLANG_ANALYZER_GCD_PERFORMANCE = YES; CLANG_ANALYZER_LOCALIZABILITY_EMPTY_CONTEXT = YES;