From ec5e0fac7f1d6babeeca992886768e32559dfe5d Mon Sep 17 00:00:00 2001 From: Daniel Chick Date: Mon, 23 Oct 2023 22:43:56 -0500 Subject: [PATCH 1/6] If there are no image tags don't build a url --- .../JellyfinAPI/BaseItemDto+Images.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift index 11d144a37..0f99703b9 100644 --- a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift +++ b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift @@ -19,7 +19,7 @@ extension BaseItemDto { _ type: ImageType, maxWidth: Int? = nil, maxHeight: Int? = nil - ) -> URL { + ) -> URL? { _imageURL(type, maxWidth: maxWidth, maxHeight: maxHeight, itemID: id ?? "") } @@ -27,7 +27,7 @@ extension BaseItemDto { _ type: ImageType, maxWidth: CGFloat? = nil, maxHeight: CGFloat? = nil - ) -> URL { + ) -> URL? { _imageURL(type, maxWidth: Int(maxWidth), maxHeight: Int(maxHeight), itemID: id ?? "") } @@ -52,11 +52,11 @@ extension BaseItemDto { // MARK: Series Images - func seriesImageURL(_ type: ImageType, maxWidth: Int? = nil, maxHeight: Int? = nil) -> URL { + func seriesImageURL(_ type: ImageType, maxWidth: Int? = nil, maxHeight: Int? = nil) -> URL? { _imageURL(type, maxWidth: maxWidth, maxHeight: maxHeight, itemID: seriesID ?? "") } - func seriesImageURL(_ type: ImageType, maxWidth: CGFloat? = nil, maxHeight: CGFloat? = nil) -> URL { + func seriesImageURL(_ type: ImageType, maxWidth: CGFloat? = nil, maxHeight: CGFloat? = nil) -> URL? { _imageURL(type, maxWidth: Int(maxWidth), maxHeight: Int(maxHeight), itemID: seriesID ?? "") } @@ -80,11 +80,13 @@ extension BaseItemDto { maxWidth: Int?, maxHeight: Int?, itemID: String - ) -> URL { + ) -> URL? { + guard let imageTags = imageTags else { return nil } + // TODO: See if the scaling is actually right so that it isn't so big let scaleWidth = maxWidth == nil ? nil : UIScreen.main.scale(maxWidth!) let scaleHeight = maxHeight == nil ? nil : UIScreen.main.scale(maxHeight!) - let tag = imageTags?[type.rawValue] + let tag = imageTags[type.rawValue] let client = Container.userSession.callAsFunction().client let parameters = Paths.GetItemImageParameters( From f10f78d12b9225a3dfe606fd194f95ebbc1cff59 Mon Sep 17 00:00:00 2001 From: Daniel Chick Date: Tue, 24 Oct 2023 22:57:24 -0500 Subject: [PATCH 2/6] return nil if there is no tag of the given imageType --- Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift index 0f99703b9..83e69337b 100644 --- a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift +++ b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift @@ -86,7 +86,8 @@ extension BaseItemDto { // TODO: See if the scaling is actually right so that it isn't so big let scaleWidth = maxWidth == nil ? nil : UIScreen.main.scale(maxWidth!) let scaleHeight = maxHeight == nil ? nil : UIScreen.main.scale(maxHeight!) - let tag = imageTags[type.rawValue] + + guard let tag = imageTags[type.rawValue] else { return nil } let client = Container.userSession.callAsFunction().client let parameters = Paths.GetItemImageParameters( From 40affb41910ad31f00b9083d0d452cfa663f13ef Mon Sep 17 00:00:00 2001 From: Daniel Chick Date: Tue, 24 Oct 2023 23:15:48 -0500 Subject: [PATCH 3/6] Swiftformat --- Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift index 83e69337b..d98512584 100644 --- a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift +++ b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift @@ -82,7 +82,7 @@ extension BaseItemDto { itemID: String ) -> URL? { guard let imageTags = imageTags else { return nil } - + // TODO: See if the scaling is actually right so that it isn't so big let scaleWidth = maxWidth == nil ? nil : UIScreen.main.scale(maxWidth!) let scaleHeight = maxHeight == nil ? nil : UIScreen.main.scale(maxHeight!) From 7e9be64b0ee94a8e8370018aad8ba83fa61f7625 Mon Sep 17 00:00:00 2001 From: Daniel Chick Date: Sat, 28 Oct 2023 19:48:57 -0500 Subject: [PATCH 4/6] add function that switches on image type to get appropriate image tags --- .../Extensions/JellyfinAPI/BaseItemDto+Images.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift index d98512584..0f45a8dde 100644 --- a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift +++ b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift @@ -105,6 +105,17 @@ extension BaseItemDto { return client.fullURL(with: request) } + private func getImageTag(for type: ImageType) -> String? { + switch type { + case .backdrop: + return backdropImageTags?.first + case .screenshot: + return screenshotImageTags?.first + default: + return imageTags?[type.rawValue] + } + } + fileprivate func _imageSource(_ type: ImageType, maxWidth: Int?, maxHeight: Int?) -> ImageSource { let url = _imageURL(type, maxWidth: maxWidth, maxHeight: maxHeight, itemID: id ?? "") let blurHash = blurHash(type) From 3ceb5d6c3a8b8d7724e986ef724b66b59a443e9a Mon Sep 17 00:00:00 2001 From: Daniel Chick Date: Sat, 28 Oct 2023 19:49:38 -0500 Subject: [PATCH 5/6] Remove guard statements andinstea return nil if there is no image tag and image type is not backdrop --- Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift index 0f45a8dde..354568e9c 100644 --- a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift +++ b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift @@ -81,13 +81,15 @@ extension BaseItemDto { maxHeight: Int?, itemID: String ) -> URL? { - guard let imageTags = imageTags else { return nil } // TODO: See if the scaling is actually right so that it isn't so big let scaleWidth = maxWidth == nil ? nil : UIScreen.main.scale(maxWidth!) let scaleHeight = maxHeight == nil ? nil : UIScreen.main.scale(maxHeight!) + let tag = getImageTag(for: type) - guard let tag = imageTags[type.rawValue] else { return nil } + if tag == nil && type != .backdrop { + return nil + } let client = Container.userSession.callAsFunction().client let parameters = Paths.GetItemImageParameters( From 60648cd9352b99149960710612edc074047a71d4 Mon Sep 17 00:00:00 2001 From: Daniel Chick Date: Mon, 30 Oct 2023 13:02:17 -0500 Subject: [PATCH 6/6] Remove backdrop check --- Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift index 354568e9c..ba4d67856 100644 --- a/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift +++ b/Shared/Extensions/JellyfinAPI/BaseItemDto+Images.swift @@ -85,11 +85,8 @@ extension BaseItemDto { // TODO: See if the scaling is actually right so that it isn't so big let scaleWidth = maxWidth == nil ? nil : UIScreen.main.scale(maxWidth!) let scaleHeight = maxHeight == nil ? nil : UIScreen.main.scale(maxHeight!) - let tag = getImageTag(for: type) - if tag == nil && type != .backdrop { - return nil - } + guard let tag = getImageTag(for: type) else { return nil } let client = Container.userSession.callAsFunction().client let parameters = Paths.GetItemImageParameters(