Add a media type enum.
This commit is contained in:
7 files changed
+24
-31
No files matched your search
@@ -427,7 +427,7 @@ class DocumentWindowController: NSWindowController, TracksViewControllerDelegate
|
||||
|
||||
func didSelect(metadata: MetadataResult) {
|
||||
let defaults = UserDefaults.standard
|
||||
let map = metadata.mediaKind == 9 ? defaults.map(forKey: "SBMetadataMovieResultMap") : defaults.map(forKey: "SBMetadataTvShowResultMap")
|
||||
let map = metadata.mediaKind == .movie ? defaults.map(forKey: "SBMetadataMovieResultMap") : defaults.map(forKey: "SBMetadataTvShowResultMap")
|
||||
let keepEmptyKeys = defaults.bool(forKey: "SBMetadataKeepEmptyAnnotations")
|
||||
|
||||
if let map = map {
|
||||
|
||||
@@ -47,13 +47,13 @@ extension MP42File {
|
||||
let season = metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyTVSeason).first?.numberValue?.intValue,
|
||||
let number = metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyTVEpisodeNumber).first?.numberValue?.intValue,
|
||||
let mediaKind = metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyMediaKind).first?.numberValue?.intValue,
|
||||
mediaKind == 10 {
|
||||
mediaKind == MetadataResult.MediaKindType.tvShow.rawValue {
|
||||
return MetadataSearchTerms.tvShow(seriesName: tvShow, season: season, episode: number)
|
||||
}
|
||||
else if let title = metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyName).first?.stringValue,
|
||||
let _ = metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyReleaseDate).first?.stringValue,
|
||||
let mediaKind = metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyMediaKind).first?.numberValue?.intValue,
|
||||
mediaKind == 9 {
|
||||
mediaKind == MetadataResult.MediaKindType.movie.rawValue {
|
||||
return MetadataSearchTerms.movie(title: title)
|
||||
}
|
||||
else if let url = firstSourceURL() ?? fallbackURL {
|
||||
@@ -72,9 +72,9 @@ extension MP42File {
|
||||
}
|
||||
|
||||
private func outputNameFormat(mediaKind: Int) -> [String]? {
|
||||
if mediaKind == 10 {
|
||||
if mediaKind == MetadataResult.MediaKindType.tvShow.rawValue {
|
||||
return UserDefaults.standard.stringArray(forKey: "SBTVShowFormat")
|
||||
} else if mediaKind == 9 {
|
||||
} else if mediaKind == MetadataResult.MediaKindType.movie.rawValue {
|
||||
return UserDefaults.standard.stringArray(forKey: "SBMovieFormat")
|
||||
}
|
||||
return nil
|
||||
@@ -84,8 +84,8 @@ extension MP42File {
|
||||
|
||||
func preferredFileName() -> String? {
|
||||
if let mediaKind = metadata.metadataItemsFiltered(byIdentifier: MP42MetadataKeyMediaKind).first?.numberValue?.intValue,
|
||||
(mediaKind == 10 && UserDefaults.standard.bool(forKey: "SBSetTVShowFormat")) ||
|
||||
(mediaKind == 9 && UserDefaults.standard.bool(forKey: "SBSetMovieFormat")),
|
||||
(mediaKind == MetadataResult.MediaKindType.tvShow.rawValue && UserDefaults.standard.bool(forKey: "SBSetTVShowFormat")) ||
|
||||
(mediaKind == MetadataResult.MediaKindType.movie.rawValue && UserDefaults.standard.bool(forKey: "SBSetMovieFormat")),
|
||||
let name = formattedFileName() {
|
||||
return name
|
||||
} else {
|
||||
|
||||
@@ -18,14 +18,6 @@ import Foundation
|
||||
return MetadataSearch.tvProviders
|
||||
}
|
||||
|
||||
@objc public static func languages(provider: String) -> [String] {
|
||||
return MetadataSearch.service(name: provider).languages
|
||||
}
|
||||
|
||||
@objc public static func languageType(provider: String) -> LanguageType {
|
||||
return MetadataSearch.service(name: provider).languageType
|
||||
}
|
||||
|
||||
@objc public static func defaultLanguage(provider: String) -> String {
|
||||
return MetadataSearch.service(name: provider).defaultLanguage
|
||||
}
|
||||
@@ -40,10 +32,6 @@ import Foundation
|
||||
service = MetadataSearch.service(name: provider)
|
||||
}
|
||||
|
||||
init(service: MetadataService) {
|
||||
self.service = service
|
||||
}
|
||||
|
||||
@objc public var languageType: LanguageType {
|
||||
return service.languageType
|
||||
}
|
||||
|
||||
@@ -192,7 +192,12 @@ public class MetadataResult : NSObject {
|
||||
|
||||
private var dictionary: [Key:Any]
|
||||
|
||||
public var mediaKind: Int
|
||||
public enum MediaKindType: Int {
|
||||
case tvShow = 10
|
||||
case movie = 9
|
||||
}
|
||||
|
||||
public var mediaKind: MediaKindType
|
||||
public var contentRating: Int
|
||||
public var remoteArtworks: [Artwork]
|
||||
public var artworks: [MP42Image]
|
||||
@@ -201,7 +206,7 @@ public class MetadataResult : NSObject {
|
||||
self.dictionary = Dictionary()
|
||||
self.remoteArtworks = Array()
|
||||
self.artworks = Array()
|
||||
self.mediaKind = 0
|
||||
self.mediaKind = .movie
|
||||
self.contentRating = 0
|
||||
}
|
||||
|
||||
@@ -215,7 +220,7 @@ public class MetadataResult : NSObject {
|
||||
}
|
||||
|
||||
lazy var orderedKeys: [Key] = {
|
||||
let sortedKeys = self.mediaKind == 9 ? Key.movieKeys : Key.tvShowKeys
|
||||
let sortedKeys = self.mediaKind == .movie ? Key.movieKeys : Key.tvShowKeys
|
||||
return Array(dictionary.keys).sorted(by: { (key1: Key, key2: Key) -> Bool in
|
||||
if let index1 = sortedKeys.index(of: key1), let index2 = sortedKeys.index(of: key2) {
|
||||
return index1 < index2
|
||||
@@ -262,7 +267,7 @@ public class MetadataResult : NSObject {
|
||||
})
|
||||
|
||||
let mediaKind = MP42MetadataItem(identifier: MP42MetadataKeyMediaKind,
|
||||
value: NSNumber(value: self.mediaKind),
|
||||
value: NSNumber(value: self.mediaKind.rawValue),
|
||||
dataType: .integer,
|
||||
extendedLanguageTag: nil)
|
||||
metadata.addItem(mediaKind)
|
||||
|
||||
@@ -36,7 +36,7 @@ public struct TheMovieDB: MetadataService {
|
||||
private func metadata(forMoviePartialResult result: TMDBMovieSearchResult, language: String?) -> MetadataResult {
|
||||
let metadata = MetadataResult()
|
||||
|
||||
metadata.mediaKind = 9; // movie
|
||||
metadata.mediaKind = .movie
|
||||
|
||||
metadata[.serviceSeriesID] = result.id
|
||||
metadata[.name] = result.title
|
||||
@@ -127,7 +127,7 @@ public struct TheMovieDB: MetadataService {
|
||||
private func metadata(forResult result: TMDBMovie, language: String?) -> MetadataResult {
|
||||
let metadata = MetadataResult()
|
||||
|
||||
metadata.mediaKind = 9; // movie
|
||||
metadata.mediaKind = .movie
|
||||
|
||||
metadata[.name] = result.title
|
||||
metadata[.releaseDate] = result.release_date
|
||||
@@ -245,7 +245,7 @@ public struct TheMovieDB: MetadataService {
|
||||
private func metadata(forTVResult result: TMDBEpisode, info: TMDBSeries) -> MetadataResult {
|
||||
let metadata = MetadataResult()
|
||||
|
||||
metadata.mediaKind = 10; // tv
|
||||
metadata.mediaKind = .tvShow
|
||||
|
||||
// TV Show Info
|
||||
metadata[.serviceSeriesID] = info.id
|
||||
|
||||
@@ -110,7 +110,7 @@ public struct TheTVDB : MetadataService, MetadataNameService {
|
||||
private func merge(episode: TVDBEpisode, info: TVDBSeriesInfo, actors: [TVDBActor]) -> MetadataResult {
|
||||
let result = MetadataResult()
|
||||
|
||||
result.mediaKind = 10
|
||||
result.mediaKind = .tvShow
|
||||
|
||||
// TV Show Info
|
||||
result[.serviceSeriesID] = info.id
|
||||
|
||||
@@ -359,7 +359,7 @@ public struct iTunesStore: MetadataService {
|
||||
private func metadata(forTVResult result: Track, store: Store) -> MetadataResult {
|
||||
let metadata = MetadataResult()
|
||||
|
||||
metadata.mediaKind = 10 // TV show
|
||||
metadata.mediaKind = .tvShow
|
||||
|
||||
metadata[.name] = result.trackName
|
||||
metadata[.releaseDate] = result.releaseDate
|
||||
@@ -400,7 +400,7 @@ public struct iTunesStore: MetadataService {
|
||||
|
||||
if let contentAdvisoryRating = result.contentAdvisoryRating {
|
||||
metadata[.rating] = MP42Ratings.defaultManager.ratingStringForiTunesCountry(store.country,
|
||||
media: metadata.mediaKind == 9 ? "movie" : "TV",
|
||||
media: metadata.mediaKind == .movie ? "movie" : "TV",
|
||||
ratingString: contentAdvisoryRating)
|
||||
}
|
||||
|
||||
@@ -437,7 +437,7 @@ public struct iTunesStore: MetadataService {
|
||||
private func metadata(forMoviePartialResult result: Track, store: Store) -> MetadataResult {
|
||||
let metadata = MetadataResult()
|
||||
|
||||
metadata.mediaKind = 9 // movie
|
||||
metadata.mediaKind = .movie
|
||||
|
||||
metadata[.name] = result.trackName
|
||||
metadata[.releaseDate] = result.releaseDate
|
||||
@@ -448,7 +448,7 @@ public struct iTunesStore: MetadataService {
|
||||
|
||||
if let contentAdvisoryRating = result.contentAdvisoryRating {
|
||||
metadata[.rating] = MP42Ratings.defaultManager.ratingStringForiTunesCountry(store.country,
|
||||
media: metadata.mediaKind == 9 ? "movie" : "TV",
|
||||
media: metadata.mediaKind == .movie ? "movie" : "TV",
|
||||
ratingString: contentAdvisoryRating)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user