diff --git a/Model/ThumbnailsModel.swift b/Model/ThumbnailsModel.swift index c8649f76..8421db49 100644 --- a/Model/ThumbnailsModel.swift +++ b/Model/ThumbnailsModel.swift @@ -15,11 +15,16 @@ final class ThumbnailsModel: ObservableObject { return unloadable.contains(url) } - func loadableURL(_ url: URL!) -> URL? { - guard !url.isNil else { - return nil + func best(_ video: Video) -> URL? { + let qualities = [Thumbnail.Quality.maxresdefault, .medium, .default] + + for quality in qualities { + let url = video.thumbnailURL(quality: quality) + if !isUnloadable(url) { + return url + } } - return isUnloadable(url) ? nil : url + return nil } } diff --git a/Shared/Videos/HorizontalCells.swift b/Shared/Videos/HorizontalCells.swift index 194184e2..bb867c3e 100644 --- a/Shared/Videos/HorizontalCells.swift +++ b/Shared/Videos/HorizontalCells.swift @@ -15,7 +15,7 @@ struct HorizontalCells: View { .padding(.trailing, 20) .padding(.bottom, 40) #else - .frame(width: 285) + .frame(width: 295) #endif } } diff --git a/Shared/Videos/VideoCell.swift b/Shared/Videos/VideoCell.swift index 60b39011..75ae0e06 100644 --- a/Shared/Videos/VideoCell.swift +++ b/Shared/Videos/VideoCell.swift @@ -65,7 +65,7 @@ struct VideoCell: View { HStack(alignment: .top, spacing: 2) { Section { #if os(tvOS) - thumbnailImage(quality: .medium) + thumbnailImage #else thumbnail #endif @@ -224,7 +224,7 @@ struct VideoCell: View { var thumbnail: some View { ZStack(alignment: .leading) { - thumbnailImage(quality: mediumQualityThumbnail ? .medium : .maxresdefault) + thumbnailImage VStack { HStack(alignment: .top) { @@ -257,9 +257,9 @@ struct VideoCell: View { } } - func thumbnailImage(quality: Thumbnail.Quality) -> some View { + var thumbnailImage: some View { Group { - if let url = thumbnails.loadableURL(video.thumbnailURL(quality: quality)) { + if let url = thumbnails.best(video) { WebImage(url: url) .resizable() .placeholder { @@ -267,13 +267,7 @@ struct VideoCell: View { } .retryOnAppear(false) .onFailure { _ in - if let url = video.thumbnailURL(quality: quality) { thumbnails.insertUnloadable(url) - } - - if !thumbnails.isUnloadable(video.thumbnailURL(quality: .medium)) { - mediumQualityThumbnail = true - } } .indicator(.activity)