Remember the preferred artwork type in the ArtworkSelectorController

This commit is contained in:
Damiano Galassi committed 2017-08-06 20:24:20 +02:00
1 parent daa41aad63
commit b10c99ba58
10 files changed
+104 -61

No files matched your search

@@ -65,7 +65,7 @@ extension Array where Element == RemoteImage {
extension SBRemoteImage {
func toStruct() -> RemoteImage {
return RemoteImage(url: self.url, thumbURL: self.thumbURL, providerName: self.providerName)
return RemoteImage(url: self.url, thumbURL: self.thumbURL, service: self.service, type: self.type)
}
}
@@ -78,10 +78,11 @@ extension Array where Element == SBRemoteImage {
public struct RemoteImage {
let url: URL
let thumbURL: URL
let providerName: String
let service: String
let type: String
public func toClass() -> SBRemoteImage {
return SBRemoteImage(url: url, thumbURL: thumbURL, providerName: providerName)
return SBRemoteImage(url: url, thumbURL: thumbURL, service: service, type: type)
}
}
@@ -91,12 +91,12 @@ public enum MetadataSearch {
}
}
public enum MetadataSearchType: String {
public enum Kind: String {
case movie = "Movie"
case tvShow = "TV"
}
public var type: MetadataSearchType {
public var type: Kind {
get {
switch self {
case .movieSeach:
@@ -144,12 +144,12 @@ extension MetadataSearch {
}
}
public static func defaultLanguage(service: MetadataService, type: MetadataSearchType) -> String {
public static func defaultLanguage(service: MetadataService, type: Kind) -> String {
let language = UserDefaults.standard.string(forKey: "SBMetadataPreference|\(type.rawValue)|\(service.name)|Language") ?? service.defaultLanguage
return service.languageType.displayName(language: language)
}
public static func setDefaultLanguage(_ language: String, service: MetadataService, type: MetadataSearchType) {
public static func setDefaultLanguage(_ language: String, service: MetadataService, type: Kind) {
let extendedLanguage = service.languageType.extendedTag(displayName: language)
UserDefaults.standard.set(extendedLanguage, forKey: "SBMetadataPreference|\(type.rawValue)|\(service.name)|Language")
}
+3 -2
View File
@@ -49,11 +49,12 @@ extern NSString *const SBMetadataResultNetwork;
@interface SBRemoteImage : NSObject
+ (instancetype)remoteImageWithURL:(NSURL *)fullSizeURL thumbURL:(NSURL *)thumbURL providerName:(NSString *)providerName;
+ (instancetype)remoteImageWithURL:(NSURL *)fullSizeURL thumbURL:(NSURL *)thumbURL service:(NSString *)service type:(NSString *)kind;
@property (nonatomic, readonly) NSURL *URL;
@property (nonatomic, readonly) NSURL *thumbURL;
@property (nonatomic, readonly) NSString *providerName;
@property (nonatomic, readonly) NSString *service;
@property (nonatomic, readonly) NSString *type;
@end
+5 -4
View File
@@ -45,21 +45,22 @@ NSString *const SBMetadataResultNetwork = @"{Network}";
@implementation SBRemoteImage
- (instancetype)initWithURL:(NSURL *)fullSizeURL thumbURL:(NSURL *)thumbURL providerName:(NSString *)providerName
- (instancetype)initWithURL:(NSURL *)fullSizeURL thumbURL:(NSURL *)thumbURL service:(NSString *)service type:(NSString *)type
{
self = [super init];
if (self)
{
_URL = fullSizeURL;
_thumbURL = thumbURL;
_providerName = providerName;
_service = service;
_type = type;
}
return self;
}
+ (instancetype)remoteImageWithURL:(NSURL *)fullSizeURL thumbURL:(NSURL *)thumbURL providerName:(NSString *)providerName
+ (instancetype)remoteImageWithURL:(NSURL *)fullSizeURL thumbURL:(NSURL *)thumbURL service:(NSString *)service type:(NSString *)type
{
return [[self alloc] initWithURL:fullSizeURL thumbURL:thumbURL providerName:providerName];
return [[self alloc] initWithURL:fullSizeURL thumbURL:thumbURL service:service type:type];
}
@end
+10 -10
View File
@@ -86,10 +86,10 @@ public struct TheMovieDB: MetadataService {
// MARK: - Movie metadata loading
private func loadArtwork(filePath: String, baseURL: String, thumbSize: String, providerName: String) -> RemoteImage? {
private func loadArtwork(filePath: String, baseURL: String, thumbSize: String, kind: String) -> RemoteImage? {
guard let url = URL(string: baseURL + "original" + filePath),
let thumbURL = URL(string: baseURL + thumbSize + filePath) else { return nil }
return RemoteImage(url: url, thumbURL: thumbURL, providerName: providerName)
return RemoteImage(url: url, thumbURL: thumbURL, service: self.name, type: kind)
}
private func loadMovieArtworks(result: TMDBMovie) -> [RemoteImage] {
@@ -108,16 +108,16 @@ public struct TheMovieDB: MetadataService {
let backdropThumbnailSize = config.backdrop_sizes.first {
if let images = result.images?.posters {
artworks.append(contentsOf: images.flatMap { loadArtwork(filePath: $0.file_path, baseURL: imageBaseURL, thumbSize: posterThumbnailSize, providerName: "TheMovieDB|poster") } )
artworks.append(contentsOf: images.flatMap { loadArtwork(filePath: $0.file_path, baseURL: imageBaseURL, thumbSize: posterThumbnailSize, kind: "poster") } )
}
if result.images?.posters?.count == 0, let posterPath = result.poster_path,
let artwork = loadArtwork(filePath: posterPath, baseURL: imageBaseURL, thumbSize: posterThumbnailSize, providerName: "TheMovieDB|poster") {
let artwork = loadArtwork(filePath: posterPath, baseURL: imageBaseURL, thumbSize: posterThumbnailSize, kind: "poster") {
artworks.append(artwork)
}
if let backdropPath = result.backdrop_path,
let artwork = loadArtwork(filePath: backdropPath, baseURL: imageBaseURL, thumbSize: backdropThumbnailSize, providerName: "TheMovieDB|poster") {
let artwork = loadArtwork(filePath: backdropPath, baseURL: imageBaseURL, thumbSize: backdropThumbnailSize, kind: "poster") {
artworks.append(artwork)
}
}
@@ -209,7 +209,7 @@ public struct TheMovieDB: MetadataService {
for image in images {
if let url = URL(string: imageBaseURL + "original" + image.file_path),
let thumbURL = URL(string: imageBaseURL + posterThumbnailSize + image.file_path) {
let remoteImage = RemoteImage(url: url, thumbURL: thumbURL, providerName: "TheMovieDB|poster")
let remoteImage = RemoteImage(url: url, thumbURL: thumbURL, service: self.name, type: "poster")
artworks.append(remoteImage)
}
}
@@ -219,14 +219,14 @@ public struct TheMovieDB: MetadataService {
let posterPath = result.poster_path,
let url = URL(string: imageBaseURL + "original" + posterPath),
let thumbURL = URL(string: imageBaseURL + posterThumbnailSize + posterPath) {
let remoteImage = RemoteImage(url: url, thumbURL: thumbURL, providerName: "TheMovieDB|poster")
let remoteImage = RemoteImage(url: url, thumbURL: thumbURL, service: self.name, type: "poster")
artworks.append(remoteImage)
}
if let backdropPath = result.backdrop_path,
let url = URL(string: imageBaseURL + "original" + backdropPath),
let thumbURL = URL(string: imageBaseURL + backdropThumbnailSize + backdropPath) {
let remoteImage = RemoteImage(url: url, thumbURL: thumbURL, providerName: "TheMovieDB|poster")
let remoteImage = RemoteImage(url: url, thumbURL: thumbURL, service: self.name, type: "poster")
artworks.append(remoteImage)
}
}
@@ -332,8 +332,8 @@ public struct TheMovieDB: MetadataService {
let imageBaseURL = config.secure_base_url,
let posterThumbnailSize = config.poster_sizes.first {
artworks.append(contentsOf: seasonImages.flatMap { loadArtwork(filePath: $0.file_path, baseURL: imageBaseURL, thumbSize: posterThumbnailSize, providerName: "TheMovieDB|season") } )
artworks.append(contentsOf: episodeImages.flatMap { loadArtwork(filePath: $0.file_path, baseURL: imageBaseURL, thumbSize: posterThumbnailSize, providerName: "TheMovieDB|episode") } )
artworks.append(contentsOf: seasonImages.flatMap { loadArtwork(filePath: $0.file_path, baseURL: imageBaseURL, thumbSize: posterThumbnailSize, kind: "season") } )
artworks.append(contentsOf: episodeImages.flatMap { loadArtwork(filePath: $0.file_path, baseURL: imageBaseURL, thumbSize: posterThumbnailSize, kind: "episode") } )
}
}
+2 -2
View File
@@ -294,7 +294,7 @@ public struct TheTVDB : MetadataService, MetadataNameService {
}
if selected {
artworks.append(RemoteImage(url: fileURL, thumbURL: thumbURL, providerName: "TheTVDB|" + type.rawValue))
artworks.append(RemoteImage(url: fileURL, thumbURL: thumbURL, service: self.name, type: type.rawValue))
}
}
return artworks
@@ -320,7 +320,7 @@ public struct TheTVDB : MetadataService, MetadataNameService {
}
if let filename = info.filename, let url = URL(string: TheTVDB.bannerPath + filename) {
artworks.append(RemoteImage(url: url, thumbURL: url, providerName: "TheTVDB|episode"))
artworks.append(RemoteImage(url: url, thumbURL: url, service: self.name, type: "episode"))
}
}
+1 -1
View File
@@ -186,7 +186,7 @@ public struct iTunesStore: MetadataService {
if let artworkURL = URL(string: text),
let artworkFullSizeURL = URL(string: text.replacingOccurrences(of: "100x100bb", with: replacement)) {
return RemoteImage(url:artworkFullSizeURL, thumbURL:artworkURL, providerName:"iTunes")
return RemoteImage(url:artworkFullSizeURL, thumbURL: artworkURL, service: self.name, type: "")
}
return nil