diff --git a/Classes/GeneralPrefsViewController.swift b/Classes/GeneralPrefsViewController.swift index 6743498..74aa69a 100644 --- a/Classes/GeneralPrefsViewController.swift +++ b/Classes/GeneralPrefsViewController.swift @@ -32,9 +32,9 @@ class GeneralPrefsViewController: NSViewController { } @IBAction func updateRatingsCountry(_ sender: Any) { - MP42Ratings.defaultManager.updateCountry() + // Unused } - @objc dynamic var ratingsCountries: [String] { return MP42Ratings.defaultManager.ratingsCountries } + @objc dynamic var ratingsCountries: [String] { return Ratings.shared.countries.map { $0.displayName } } } diff --git a/Classes/MetadataImporters/TheMovieDB.swift b/Classes/MetadataImporters/TheMovieDB.swift index 03e9ec0..3093dac 100644 --- a/Classes/MetadataImporters/TheMovieDB.swift +++ b/Classes/MetadataImporters/TheMovieDB.swift @@ -178,9 +178,7 @@ public struct TheMovieDB: MetadataService { if let releases = result.releases { for release in releases.countries { if release.iso_3166_1 == "US" { - metadata[.rating] = MP42Ratings.defaultManager.ratingStringForiTunesCountry("USA", - media: "movie", - ratingString: release.certification) + metadata[.rating] = Ratings.shared.rating(countryCode: "USA", media: "movie", name: release.certification)?.iTunesCode } } } @@ -322,9 +320,7 @@ public struct TheMovieDB: MetadataService { if let ratings = info.content_ratings?.results { let USRating = ratings.filter { $0.iso_3166_1 == "US" }.compactMap { $0.rating } if let rating = USRating.first { - metadata[.rating] = MP42Ratings.defaultManager.ratingStringForiTunesCountry("USA", - media: "TV", - ratingString: rating) + metadata[.rating] = Ratings.shared.rating(countryCode: "USA", media: "TV", name: rating)?.iTunesCode } } diff --git a/Classes/MetadataImporters/TheTVDB.swift b/Classes/MetadataImporters/TheTVDB.swift index 89eec03..a1db6a2 100644 --- a/Classes/MetadataImporters/TheTVDB.swift +++ b/Classes/MetadataImporters/TheTVDB.swift @@ -138,9 +138,7 @@ public struct TheTVDB : MetadataService { // Rating if let rating = info.rating, rating.count > 0 { - result[.rating] = MP42Ratings.defaultManager.ratingStringForiTunesCountry("USA", - media: "TV", - ratingString: rating) + result[.rating] = Ratings.shared.rating(countryCode: "USA", media: "TV", name: rating)?.iTunesCode } // Actors diff --git a/Classes/MetadataImporters/iTunesStore.swift b/Classes/MetadataImporters/iTunesStore.swift index 5aa3ce7..eede467 100644 --- a/Classes/MetadataImporters/iTunesStore.swift +++ b/Classes/MetadataImporters/iTunesStore.swift @@ -608,9 +608,7 @@ public struct iTunesStore: MetadataService { } if let contentAdvisoryRating = result.contentAdvisoryRating { - metadata[.rating] = MP42Ratings.defaultManager.ratingStringForiTunesCountry(store.country, - media: metadata.mediaKind == .movie ? "movie" : "TV", - ratingString: contentAdvisoryRating) + metadata[.rating] = Ratings.shared.rating(countryCode: store.country, media: metadata.mediaKind == .movie ? "movie" : "TV", name: contentAdvisoryRating)?.iTunesCode } metadata[.iTunesCountry] = store.storeCode @@ -656,9 +654,7 @@ public struct iTunesStore: MetadataService { metadata[.genre] = result.primaryGenreName if let contentAdvisoryRating = result.contentAdvisoryRating { - metadata[.rating] = MP42Ratings.defaultManager.ratingStringForiTunesCountry(store.country, - media: metadata.mediaKind == .movie ? "movie" : "TV", - ratingString: contentAdvisoryRating) + metadata[.rating] = Ratings.shared.rating(countryCode: store.country, media: metadata.mediaKind == .movie ? "movie" : "TV", name: contentAdvisoryRating)?.iTunesCode } metadata[.iTunesCountry] = store.storeCode diff --git a/Classes/PropertyView/MovieViewController.swift b/Classes/PropertyView/MovieViewController.swift index 50d764d..37bed61 100644 --- a/Classes/PropertyView/MovieViewController.swift +++ b/Classes/PropertyView/MovieViewController.swift @@ -23,6 +23,7 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie private var tags: [MP42MetadataItem] private let ratings: [String] + private let codes: [String] private lazy var dummyCell: NSTableCellView = { return self.metadataTableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "TextCellForSizing"), owner: self) as! NSTableCellView @@ -70,10 +71,19 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie self.metadata = metadata self.tags = [] self.artworks = [] - self.ratings = MP42Ratings.defaultManager.ratings + + let selectedCountry = UserDefaults.standard.string(forKey: "SBRatingsCountry") + let countries = selectedCountry == "All countries" ? + Ratings.shared.countries : + Ratings.shared.countries.filter { $0.displayName == selectedCountry || $0.displayName == "USA" } + self.ratings = countries.flatMap { country in country.ratings + .map { "\(country.displayName) \($0.media): \($0.displayName)" } } + self.codes = countries.flatMap { $0.ratings.map { $0.iTunesCode } } + self.columnWidth = 0 self.previousColumnWidth = 0 self.rowHeights = Dictionary() + super.init(nibName: nil, bundle: nil) } @@ -431,9 +441,7 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie contents.forEach { popUpButton.menu?.addItem(withTitle: $0, action: nil, keyEquivalent: "") } - // WTF - let index = MP42Ratings.defaultManager.ratingIndexForiTunesCode(value ?? "") - if index != -1 { + if let index = self.codes.firstIndex(of: value ?? "") { popUpButton.selectItem(at: Int(index)) } else { let title = value?.isEmpty ?? true ? NSLocalizedString("Unknown", comment: "") : value ?? NSLocalizedString("Unknown", comment: "") @@ -682,9 +690,8 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie switch item.dataType { case .string: if item.identifier == MP42MetadataKeyRating { - let ratings = MP42Ratings.defaultManager.iTunesCodes - if index < ratings.count { - value = ratings[index] + if index < self.codes.count { + value = self.codes[index] } else { value = item.value as Any } diff --git a/MP42Foundation b/MP42Foundation index 9a2c585..98b7bb0 160000 --- a/MP42Foundation +++ b/MP42Foundation @@ -1 +1 @@ -Subproject commit 9a2c5858ce1f6e3424dd9547932f2df2734a8595 +Subproject commit 98b7bb0b6c9a518567eabed201ee4dcc6fc711ce diff --git a/Ratings.json b/Ratings.json new file mode 100644 index 0000000..49a4eb7 --- /dev/null +++ b/Ratings.json @@ -0,0 +1,291 @@ +[ +{ + "country" : "USA", + "ratings" : [ + { "media" : "movie", "prefix" : "mpaa", "itunes-code" : "NR", "itunes-value" : "000", "description" : "NR" }, + { "media" : "movie", "prefix" : "mpaa", "itunes-code" : "G", "itunes-value" : "100", "description" : "G" }, + { "media" : "movie", "prefix" : "mpaa", "itunes-code" : "PG", "itunes-value" : "200", "description" : "PG" }, + { "media" : "movie", "prefix" : "mpaa", "itunes-code" : "PG-13", "itunes-value" : "300", "description" : "PG-13" }, + { "media" : "movie", "prefix" : "mpaa", "itunes-code" : "R", "itunes-value" : "400", "description" : "R" }, + { "media" : "movie", "prefix" : "mpaa", "itunes-code" : "NC-17", "itunes-value" : "500", "description" : "NC-17" }, + { "media" : "movie", "prefix" : "mpaa", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Unrated" }, + { "media" : "TV", "prefix" : "us-tv", "itunes-code" : "TV-Y", "itunes-value" : "100", "description" : "TV-Y" }, + { "media" : "TV", "prefix" : "us-tv", "itunes-code" : "TV-Y7", "itunes-value" : "200", "description" : "TV-Y7" }, + { "media" : "TV", "prefix" : "us-tv", "itunes-code" : "TV-G", "itunes-value" : "300", "description" : "TV-G" }, + { "media" : "TV", "prefix" : "us-tv", "itunes-code" : "TV-PG", "itunes-value" : "400", "description" : "TV-PG" }, + { "media" : "TV", "prefix" : "us-tv", "itunes-code" : "TV-14", "itunes-value" : "500", "description" : "TV-14" }, + { "media" : "TV", "prefix" : "us-tv", "itunes-code" : "TV-MA", "itunes-value" : "600", "description" : "TV-MA" }, + { "media" : "TV", "prefix" : "us-tv", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Unrated" } + ] +}, +{ + "country" : "Australia", + "ratings" : [ + { "media" : "movie", "prefix" : "au-movie", "itunes-code" : "G", "itunes-value" : "100", "description" : "G" }, + { "media" : "movie", "prefix" : "au-movie", "itunes-code" : "PG", "itunes-value" : "200", "description" : "PG" }, + { "media" : "movie", "prefix" : "au-movie", "itunes-code" : "M", "itunes-value" : "350", "description" : "M" }, + { "media" : "movie", "prefix" : "au-movie", "itunes-code" : "MA15+", "itunes-value" : "375", "description" : "MA15+" }, + { "media" : "movie", "prefix" : "au-movie", "itunes-code" : "R18+", "itunes-value" : "400", "description" : "R18+" }, + { "media" : "movie", "prefix" : "au-movie", "itunes-code" : "Not Rated","itunes-value" : "???", "description" : "Not Rated" }, + { "media" : "TV", "prefix" : "au-tv", "itunes-code" : "P", "itunes-value" : "100", "description" : "P" }, + { "media" : "TV", "prefix" : "au-tv", "itunes-code" : "C", "itunes-value" : "200", "description" : "C" }, + { "media" : "TV", "prefix" : "au-tv", "itunes-code" : "G", "itunes-value" : "300", "description" : "G" }, + { "media" : "TV", "prefix" : "au-tv", "itunes-code" : "PG", "itunes-value" : "400", "description" : "PG" }, + { "media" : "TV", "prefix" : "au-tv", "itunes-code" : "M", "itunes-value" : "500", "description" : "M" }, + { "media" : "TV", "prefix" : "au-tv", "itunes-code" : "MA15+", "itunes-value" : "550", "description" : "MA15+" }, + { "media" : "TV", "prefix" : "au-tv", "itunes-code" : "AV15+", "itunes-value" : "575", "description" : "AV15+" }, + { "media" : "TV", "prefix" : "au-tv", "itunes-code" : "R18+", "itunes-value" : "160", "description" : "R18+" } + ] +}, +{ + "country" : "Brasil", + "ratings" : [ + { "media" : "movie", "prefix" : "br-movie", "itunes-code" : "L", "itunes-value" : "000", "description" : "L" }, + { "media" : "movie", "prefix" : "br-movie", "itunes-code" : "12", "itunes-value" : "100", "description" : "12" }, + { "media" : "movie", "prefix" : "br-movie", "itunes-code" : "14", "itunes-value" : "300", "description" : "14" }, + { "media" : "movie", "prefix" : "br-movie", "itunes-code" : "16", "itunes-value" : "350", "description" : "16" }, + { "media" : "movie", "prefix" : "br-movie", "itunes-code" : "18", "itunes-value" : "400", "description" : "18" } + ] +}, +{ + "country" : "Canada", + "ratings" : [ + { "media" : "movie", "prefix" : "ca-movie", "itunes-code" : "G", "itunes-value" : "100", "description" : "G" }, + { "media" : "movie", "prefix" : "ca-movie", "itunes-code" : "PG", "itunes-value" : "200", "description" : "PG" }, + { "media" : "movie", "prefix" : "ca-movie", "itunes-code" : "14A", "itunes-value" : "300", "description" : "14A" }, + { "media" : "movie", "prefix" : "ca-movie", "itunes-code" : "18A", "itunes-value" : "350", "description" : "18A" }, + { "media" : "movie", "prefix" : "ca-movie", "itunes-code" : "R", "itunes-value" : "400", "description" : "R" }, + { "media" : "movie", "prefix" : "ca-movie", "itunes-code" : "A", "itunes-value" : "500", "description" : "A" }, + { "media" : "movie", "prefix" : "ca-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Unrated" }, + { "media" : "movie", "prefix" : "ca-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Not Rated" }, + { "media" : "TV", "prefix" : "ca-tv", "itunes-code" : "E", "itunes-value" : "000", "description" : "E" }, + { "media" : "TV", "prefix" : "ca-tv", "itunes-code" : "C", "itunes-value" : "050", "description" : "C" }, + { "media" : "TV", "prefix" : "ca-tv", "itunes-code" : "C8", "itunes-value" : "075", "description" : "C8" }, + { "media" : "TV", "prefix" : "ca-tv", "itunes-code" : "G", "itunes-value" : "100", "description" : "G" }, + { "media" : "TV", "prefix" : "ca-tv", "itunes-code" : "PG", "itunes-value" : "200", "description" : "PG" }, + { "media" : "TV", "prefix" : "ca-tv", "itunes-code" : "14+", "itunes-value" : "300", "description" : "14+" }, + { "media" : "TV", "prefix" : "ca-tv", "itunes-code" : "18+", "itunes-value" : "350", "description" : "18+" }, + { "media" : "TV", "prefix" : "ca-tv", "itunes-code" : "21+", "itunes-value" : "500", "description" : "21+" } + ] +}, +{ + "country" : "Deutschland", + "ratings" : [ + { "media" : "movie", "prefix" : "de-movie", "itunes-code" : "Ab 0 Jahren", "itunes-value" : "075", "description" : "Ab 0 Jahren" }, + { "media" : "movie", "prefix" : "de-movie", "itunes-code" : "Ab 6 Jahren", "itunes-value" : "100", "description" : "Ab 6 Jahren" }, + { "media" : "movie", "prefix" : "de-movie", "itunes-code" : "Ab 12 Jahren", "itunes-value" : "200", "description" : "Ab 12 Jahren" }, + { "media" : "movie", "prefix" : "de-movie", "itunes-code" : "Ab 16 Jahren", "itunes-value" : "500", "description" : "Ab 16 Jahren" }, + { "media" : "movie", "prefix" : "de-movie", "itunes-code" : "Ab 18 Jahren", "itunes-value" : "600", "description" : "Ab 18 Jahren" }, + { "media" : "TV", "prefix" : "de-tv", "itunes-code" : "Ab 0 Jahren", "itunes-value" : "075", "description" : "Ab 0 Jahren" }, + { "media" : "TV", "prefix" : "de-tv", "itunes-code" : "Ab 6 Jahren", "itunes-value" : "100", "description" : "Ab 6 Jahren" }, + { "media" : "TV", "prefix" : "de-tv", "itunes-code" : "Ab 12 Jahren", "itunes-value" : "200", "description" : "Ab 12 Jahren" }, + { "media" : "TV", "prefix" : "de-tv", "itunes-code" : "Ab 16 Jahren", "itunes-value" : "500", "description" : "Ab 16 Jahren" }, + { "media" : "TV", "prefix" : "de-tv", "itunes-code" : "Ab 18 Jahren", "itunes-value" : "600", "description" : "Ab 18 Jahren" } + ] +}, +{ + "country" : "France", + "ratings" : [ + { "media" : "movie & TV", "prefix" : "fr-movie", "itunes-code" : "Tout public", "itunes-value" : "000", "description" : "Tout public" }, + { "media" : "movie & TV", "prefix" : "fr-movie", "itunes-code" : "-10", "itunes-value" : "100", "description" : "-10" }, + { "media" : "movie & TV", "prefix" : "fr-movie", "itunes-code" : "-12", "itunes-value" : "300", "description" : "-12" }, + { "media" : "movie & TV", "prefix" : "fr-movie", "itunes-code" : "-16", "itunes-value" : "375", "description" : "-16" }, + { "media" : "movie & TV", "prefix" : "fr-movie", "itunes-code" : "-18", "itunes-value" : "400", "description" : "-18" }, + { "media" : "movie & TV", "prefix" : "fr-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Unrated" } + ] +}, +{ + "country" : "Italia", + "ratings" : [ + { "media" : "movie", "prefix" : "it-movie", "itunes-code" : "T", "itunes-value" : "100", "description" : "T" }, + { "media" : "movie", "prefix" : "it-movie", "itunes-code" : "VPA", "itunes-value" : "125", "description" : "VPA" }, + { "media" : "movie", "prefix" : "it-movie", "itunes-code" : "VM10", "itunes-value" : "150", "description" : "VM10" }, + { "media" : "movie", "prefix" : "it-movie", "itunes-code" : "VM12", "itunes-value" : "200", "description" : "VM12" }, + { "media" : "movie", "prefix" : "it-movie", "itunes-code" : "VM14", "itunes-value" : "325", "description" : "VM14" }, + { "media" : "movie", "prefix" : "it-movie", "itunes-code" : "VM18", "itunes-value" : "400", "description" : "VM18" } + ] +}, +{ + "country" : "Ireland", + "ratings" : [ + { "media" : "movie", "prefix" : "ie-movie", "itunes-code" : "Not Rated", "itunes-value" : "000", "description" : "Not Rated" }, + { "media" : "movie", "prefix" : "ie-movie", "itunes-code" : "G", "itunes-value" : "100", "description" : "G" }, + { "media" : "movie", "prefix" : "ie-movie", "itunes-code" : "PG", "itunes-value" : "200", "description" : "PG" }, + { "media" : "movie", "prefix" : "ie-movie", "itunes-code" : "12", "itunes-value" : "300", "description" : "12" }, + { "media" : "movie", "prefix" : "ie-movie", "itunes-code" : "15", "itunes-value" : "350", "description" : "15" }, + { "media" : "movie", "prefix" : "ie-movie", "itunes-code" : "16", "itunes-value" : "375", "description" : "16" }, + { "media" : "movie", "prefix" : "ie-movie", "itunes-code" : "18", "itunes-value" : "400", "description" : "18" }, + { "media" : "movie", "prefix" : "ie-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Unrated" }, + { "media" : "TV", "prefix" : "ie-tv", "itunes-code" : "G", "itunes-value" : "100", "description" : "G" }, + { "media" : "TV", "prefix" : "ie-tv", "itunes-code" : "PG", "itunes-value" : "350", "description" : "PG" }, + { "media" : "TV", "prefix" : "ie-tv", "itunes-code" : "12", "itunes-value" : "400", "description" : "12" }, + { "media" : "TV", "prefix" : "ie-tv", "itunes-code" : "15", "itunes-value" : "500", "description" : "15" }, + { "media" : "TV", "prefix" : "ie-tv", "itunes-code" : "18", "itunes-value" : "600", "description" : "18" } + ] +}, +{ + "country" : "日本", + "ratings" : [ + { "media" : "movie", "prefix" : "jp-movie", "itunes-code" : "G", "itunes-value" : "100", "description" : "G" }, + { "media" : "movie", "prefix" : "jp-movie", "itunes-code" : "PG12", "itunes-value" : "200", "description" : "PG12" }, + { "media" : "movie", "prefix" : "jp-movie", "itunes-code" : "R15+", "itunes-value" : "300", "description" : "R15+" }, + { "media" : "movie", "prefix" : "jp-movie", "itunes-code" : "R18+", "itunes-value" : "400", "description" : "R18+" }, + { "media" : "movie", "prefix" : "jp-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "未審査" } + ] +}, +{ + "country" : "Mexico", + "ratings" : [ + { "media" : "movie", "prefix" : "mx-movie", "itunes-code" : "AA", "itunes-value" : "000", "description" : "AA" }, + { "media" : "movie", "prefix" : "mx-movie", "itunes-code" : "A", "itunes-value" : "100", "description" : "A" }, + { "media" : "movie", "prefix" : "mx-movie", "itunes-code" : "B", "itunes-value" : "300", "description" : "B" }, + { "media" : "movie", "prefix" : "mx-movie", "itunes-code" : "B-15", "itunes-value" : "500", "description" : "B-15" }, + { "media" : "movie", "prefix" : "mx-movie", "itunes-code" : "C", "itunes-value" : "600", "description" : "C" } + ] +}, +{ + "country" : "Nederland", + "ratings" : [ + { "media" : "movie & TV", "prefix" : "nl-movie", "itunes-code" : "AL/G", "itunes-value" : "000", "description" : "AL/G" }, + { "media" : "movie & TV", "prefix" : "nl-movie", "itunes-code" : "6", "itunes-value" : "100", "description" : "6" }, + { "media" : "movie & TV", "prefix" : "nl-movie", "itunes-code" : "9", "itunes-value" : "200", "description" : "9" }, + { "media" : "movie & TV", "prefix" : "nl-movie", "itunes-code" : "12", "itunes-value" : "300", "description" : "12" }, + { "media" : "movie & TV", "prefix" : "nl-movie", "itunes-code" : "16", "itunes-value" : "500", "description" : "16" }, + { "media" : "movie & TV", "prefix" : "nl-movie", "itunes-code" : "18", "itunes-value" : "600", "description" : "18" } + ] +}, +{ + "country" : "New Zealand", + "ratings" : [ + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "G", "itunes-value" : "100", "description" : "G" }, + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "PG", "itunes-value" : "200", "description" : "PG" }, + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "M", "itunes-value" : "300", "description" : "M" }, + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "R13", "itunes-value" : "325", "description" : "R13" }, + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "RP13", "itunes-value" : "325", "description" : "RP13" }, + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "R15", "itunes-value" : "350", "description" : "R15" }, + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "R16", "itunes-value" : "375", "description" : "R16" }, + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "RP16", "itunes-value" : "375", "description" : "RP16" }, + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "R18", "itunes-value" : "400", "description" : "R18" }, + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "R", "itunes-value" : "500", "description" : "R" }, + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "U", "itunes-value" : "900", "description" : "U" }, + { "media" : "movie & TV", "prefix" : "nz-movie", "itunes-code" : "Not Rated","itunes-value" : "???", "description" : "Not Rated" } + ] +}, +{ + "country" : "Sverige", + "ratings" : [ + { "media" : "movie & TV", "prefix" : "se-movie", "itunes-code" : "A", "itunes-value" : "000", "description" : "Barntillåten" }, + { "media" : "movie & TV", "prefix" : "se-movie", "itunes-code" : "7", "itunes-value" : "125", "description" : "Från 7 år" }, + { "media" : "movie & TV", "prefix" : "se-movie", "itunes-code" : "11", "itunes-value" : "225", "description" : "Från 11 år" }, + { "media" : "movie & TV", "prefix" : "se-movie", "itunes-code" : "15", "itunes-value" : "400", "description" : "Från 15 år" }, + { "media" : "movie & TV", "prefix" : "se-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Ocensurerad" }, + { "media" : "movie & TV", "prefix" : "se-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Inte klassificerad" } + ] +}, +{ + "country" : "Schweiz", + "ratings" : [ + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "0", "itunes-value" : "050", "description" : "0" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "6", "itunes-value" : "075", "description" : "6" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "7", "itunes-value" : "125", "description" : "7" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "10", "itunes-value" : "150", "description" : "10" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "12", "itunes-value" : "200", "description" : "12" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "14", "itunes-value" : "325", "description" : "14" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "16", "itunes-value" : "375", "description" : "16" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "18", "itunes-value" : "400", "description" : "18" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "keine alterseinstufung" } + ] +}, +{ + "country" : "Suisse", + "ratings" : [ + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "0", "itunes-value" : "050", "description" : "0" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "6", "itunes-value" : "075", "description" : "6" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "7", "itunes-value" : "125", "description" : "7" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "10", "itunes-value" : "150", "description" : "10" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "12", "itunes-value" : "200", "description" : "12" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "14", "itunes-value" : "325", "description" : "14" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "16", "itunes-value" : "375", "description" : "16" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "18", "itunes-value" : "400", "description" : "18" }, + { "media" : "movie", "prefix" : "ch-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "keine alterseinstufung" } + ] +}, +{ + "country" : "UK", + "ratings" : [ + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "NR", "itunes-value" : "000", "description" : "Not Rated" }, + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "U", "itunes-value" : "100", "description" : "U" }, + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "Uc", "itunes-value" : "150", "description" : "Uc" }, + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "PG", "itunes-value" : "200", "description" : "PG" }, + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "12", "itunes-value" : "300", "description" : "12" }, + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "12A", "itunes-value" : "325", "description" : "12A" }, + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "15", "itunes-value" : "350", "description" : "15" }, + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "18", "itunes-value" : "400", "description" : "18" }, + { "media" : "TV", "prefix" : "uk-tv", "itunes-code" : "Caution", "itunes-value" : "500", "description" : "Caution" }, + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "R18", "itunes-value" : "600", "description" : "R18" }, + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "E", "itunes-value" : "0", "description" : "Exempt" }, + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Unrated" }, + { "media" : "movie & TV", "prefix" : "uk-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "TBC" } + ] +}, +{ + "country" : "Россия", + "ratings" : [ + { "media" : "movie & TV", "prefix" : "ru-movie", "itunes-code" : "0+", "itunes-value" : "000", "description" : "0+" }, + { "media" : "movie & TV", "prefix" : "ru-movie", "itunes-code" : "6+", "itunes-value" : "150", "description" : "6+" }, + { "media" : "movie & TV", "prefix" : "ru-movie", "itunes-code" : "12+", "itunes-value" : "200", "description" : "12+" }, + { "media" : "movie & TV", "prefix" : "ru-movie", "itunes-code" : "16+", "itunes-value" : "375", "description" : "16+" }, + { "media" : "movie & TV", "prefix" : "ru-movie", "itunes-code" : "18+", "itunes-value" : "400", "description" : "18+" }, + { "media" : "movie & TV", "prefix" : "ru-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Unrated" } + ] +}, +{ + "country" : "Pilipinas", + "ratings" : [ + { "media" : "movie & TV", "prefix" : "ph-movie", "itunes-code" : "G", "itunes-value" : "100", "description" : "G" }, + { "media" : "movie & TV", "prefix" : "ph-movie", "itunes-code" : "PG", "itunes-value" : "300", "description" : "PG" }, + { "media" : "movie & TV", "prefix" : "ph-movie", "itunes-code" : "R-13", "itunes-value" : "325", "description" : "R-13" }, + { "media" : "movie & TV", "prefix" : "ph-movie", "itunes-code" : "R-16", "itunes-value" : "375", "description" : "R-16" }, + { "media" : "movie & TV", "prefix" : "ph-movie", "itunes-code" : "R-18", "itunes-value" : "400", "description" : "R-18" }, + { "media" : "movie & TV", "prefix" : "ph-movie", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Unrated" } + ] +}, +{ + "country" : "Hong Kong", + "ratings" : [ + { "media" : "movie & TV", "prefix" : "hk-movie", "itunes-code" : "第i類", "itunes-value" : "100", "description" : "第i類" }, + { "media" : "movie & TV", "prefix" : "hk-movie", "itunes-code" : "第ii類", "itunes-value" : "400", "description" : "第ii類" }, + { "media" : "movie & TV", "prefix" : "hk-movie", "itunes-code" : "未作評級", "itunes-value" : "???", "description" : "未作評級" } + ] +}, +{ + "country" : "Česká republika", + "ratings" : [ + { "media" : "movie & TV", "prefix" : "cz-movies", "itunes-code" : "U", "itunes-value" : "100", "description" : "U" }, + { "media" : "movie & TV", "prefix" : "cz-movies", "itunes-code" : "12+", "itunes-value" : "200", "description" : "12+" }, + { "media" : "movie & TV", "prefix" : "cz-movies", "itunes-code" : "15+", "itunes-value" : "350", "description" : "15+" }, + { "media" : "movie & TV", "prefix" : "cz-movies", "itunes-code" : "18+", "itunes-value" : "400", "description" : "18+" }, + { "media" : "movie & TV", "prefix" : "cz-movies", "itunes-code" : "neklasifikováno", "itunes-value" : "???", "description" : "Neklasifikováno" } + ] +}, +{ + "country" : "India", + "ratings" : [ + { "media" : "movie", "prefix" : "in-movies", "itunes-code" : "U", "itunes-value" : "000", "description" : "U" }, + { "media" : "movie", "prefix" : "in-movies", "itunes-code" : "UA", "itunes-value" : "200", "description" : "UA" }, + { "media" : "movie", "prefix" : "in-movies", "itunes-code" : "A", "itunes-value" : "500", "description" : "A" }, + { "media" : "movie", "prefix" : "in-movies", "itunes-code" : "S", "itunes-value" : "600", "description" : "S" }, + { "media" : "TV", "prefix" : "in-tv", "itunes-code" : "U", "itunes-value" : "100", "description" : "U" }, + { "media" : "TV", "prefix" : "in-tv", "itunes-code" : "UA", "itunes-value" : "200", "description" : "UA" }, + { "media" : "TV", "prefix" : "in-tv", "itunes-code" : "A", "itunes-value" : "600", "description" : "A" }, + { "media" : "TV", "prefix" : "in-tv", "itunes-code" : "S", "itunes-value" : "800", "description" : "S" }, + { "media" : "movie & TV", "prefix" : "in-movies", "itunes-code" : "रेट नहीं की गई", "itunes-value" : "???", "description" : "रेट नहीं की गई" } + ] +}, +{ + "country" : "Unknown", + "ratings" : [ + { "media" : "movie & TV", "prefix" : "mpaa", "itunes-code" : "Unrated", "itunes-value" : "???", "description" : "Unknown" } + ] +} +] diff --git a/Ratings.swift b/Ratings.swift new file mode 100644 index 0000000..d7d6962 --- /dev/null +++ b/Ratings.swift @@ -0,0 +1,50 @@ +// +// Ratings.swift +// Subler +// +// Created by Damiano Galassi on 04/02/2020. +// + +import Foundation + +final class Ratings { + static let shared = Ratings() + + let countries: [Country] + + private init() { + guard let url = Bundle.main.url(forResource: "Ratings", withExtension: "json"), + let data = try? Data(contentsOf: url), + let countries = try? JSONDecoder().decode([Country].self, from: data) else { fatalError() } + + self.countries = countries + } + + func rating(countryCode: String, media: String, name: String) -> Rating? { + guard let country = countries.first(where: { $0.displayName == countryCode }) else { return nil } + return country.ratings.first(where: {$0.media.contains(media) && $0.displayName == name}) + } +} + +struct Country: Codable { + let displayName: String + let ratings: [Rating] + + enum CodingKeys: String, CodingKey { + case displayName = "country", ratings + } +} + +struct Rating: Codable { + let media: String + let prefix: String + let code: String + let value: String + let displayName: String + + enum CodingKeys: String, CodingKey { + case media, prefix, code = "itunes-code", value = "itunes-value", displayName = "description" + } + + var iTunesCode: String { "\(prefix)|\(code)|\(value)|" } +} diff --git a/Subler.xcodeproj/project.pbxproj b/Subler.xcodeproj/project.pbxproj index f6d9a83..fb9113a 100644 --- a/Subler.xcodeproj/project.pbxproj +++ b/Subler.xcodeproj/project.pbxproj @@ -66,6 +66,8 @@ A979B3862025C8BF00468362 /* DocumentWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A979B3842025C8BF00468362 /* DocumentWindowController.swift */; }; A97C3AA5204F18C90007AD38 /* TokenCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97C3AA4204F18C90007AD38 /* TokenCellView.swift */; }; A97D99DA22A0240C001FA3A7 /* OCRManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97D99D922A0240C001FA3A7 /* OCRManager.swift */; }; + A97FA41E23E9837000EE5833 /* Ratings.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97FA41D23E9837000EE5833 /* Ratings.swift */; }; + A97FA42223E9877900EE5833 /* Ratings.json in Resources */ = {isa = PBXBuildFile; fileRef = A97FA42123E9877900EE5833 /* Ratings.json */; }; A97FBE3C21FC7F1C00F1FD35 /* QueueController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97FBE3B21FC7F1C00F1FD35 /* QueueController.swift */; }; A983E80B22365B5400221BAE /* MovieViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A983E80A22365B5400221BAE /* MovieViewController.swift */; }; A984DB740F52DD4B001A20B2 /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = A984DB730F52DD4B001A20B2 /* dsa_pub.pem */; }; @@ -280,6 +282,8 @@ A979B3842025C8BF00468362 /* DocumentWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DocumentWindowController.swift; path = Classes/DocumentWindowController.swift; sourceTree = ""; }; A97C3AA4204F18C90007AD38 /* TokenCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TokenCellView.swift; path = Classes/TokenCellView.swift; sourceTree = ""; }; A97D99D922A0240C001FA3A7 /* OCRManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OCRManager.swift; path = Classes/OCRManager.swift; sourceTree = ""; }; + A97FA41D23E9837000EE5833 /* Ratings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Ratings.swift; sourceTree = ""; }; + A97FA42123E9877900EE5833 /* Ratings.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Ratings.json; sourceTree = ""; }; A97FBE3B21FC7F1C00F1FD35 /* QueueController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = QueueController.swift; path = Classes/QueueController.swift; sourceTree = ""; }; A983E80A22365B5400221BAE /* MovieViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MovieViewController.swift; path = Classes/PropertyView/MovieViewController.swift; sourceTree = ""; }; A984DB730F52DD4B001A20B2 /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsa_pub.pem; sourceTree = ""; }; @@ -460,6 +464,7 @@ 8D15AC360486D014006FF6A4 /* Info.plist */, A9B46AA312B79BB10040517A /* Subler.icns */, CDE8E451174CBBD4009410B5 /* iTunesStores.json */, + A97FA42123E9877900EE5833 /* Ratings.json */, A94A6A581ED1C5CA00049F7D /* ParseFilename */, ); name = Resources; @@ -640,6 +645,7 @@ A9AE70E01F2F7B3D001CF27C /* MetadataHelper.swift */, A90BC5E21F3A139700F9F3F3 /* MetadataResult.swift */, A900CE3D1F3ACF9700CCA08E /* MetadataResultMap.swift */, + A97FA41D23E9837000EE5833 /* Ratings.swift */, A9E97F131F274F1100DBA586 /* iTunesStore.swift */, A90B094B235614D200F1B191 /* AppleTV.swift */, A98D98451F0280CB00A77ABC /* TheMovieDB.swift */, @@ -786,6 +792,7 @@ A98542D720D197D300EB9803 /* ArtworkSelector.xib in Resources */, A9ECA0602029A13800D5F30C /* OffsetViewController.xib in Resources */, A9ACF03222A2BCF200AD5B12 /* OCRPrefsViewController.xib in Resources */, + A97FA42223E9877900EE5833 /* Ratings.json in Resources */, A961476713F568210068F161 /* Queue.xib in Resources */, A9BA1AF31DBF7DD800FD0B38 /* Localizable.strings in Resources */, A9ECA0572029A10B00D5F30C /* DocumentWindowController.xib in Resources */, @@ -854,6 +861,7 @@ A997B0AA1F348AB000974C9C /* MetadataSearchController.swift in Sources */, A974F9D022F9B48900DBB30E /* MetadataSearchViewController.swift in Sources */, A956CE6B1F99EAAD00093992 /* Logger.swift in Sources */, + A97FA41E23E9837000EE5833 /* Ratings.swift in Sources */, A956CE691F99E93D00093992 /* ButtonToolbarItem.swift in Sources */, A98D44102036F661005CB092 /* AppDelegate.swift in Sources */, A9C31E572029A75F00CEF474 /* GeneralPrefsViewController.swift in Sources */,