Move ratings code to app level.
This commit is contained in:
9 files changed
+371
-25
No files matched your search
@@ -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 } }
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user