From b70697e1beddf9813ef429ccc0850276e3243e67 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 16 Apr 2022 19:50:02 +0200 Subject: [PATCH] Improve subscriptions count Piped API now includes it in the streams response, no need for separate query --- Model/Applications/PipedAPI.swift | 3 ++- Model/Player/PlayerModel.swift | 38 +--------------------------- Model/Player/PlayerQueue.swift | 1 - Shared/Defaults.swift | 1 - Shared/Player/VideoDetails.swift | 13 ++++------ Shared/Settings/PlayerSettings.swift | 6 ----- 6 files changed, 8 insertions(+), 54 deletions(-) diff --git a/Model/Applications/PipedAPI.swift b/Model/Applications/PipedAPI.swift index df9e61f1..d53454b5 100644 --- a/Model/Applications/PipedAPI.swift +++ b/Model/Applications/PipedAPI.swift @@ -319,6 +319,7 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { let author = details["uploaderName"]?.stringValue ?? details["uploader"]!.stringValue let authorThumbnailURL = details["avatarUrl"]?.url ?? details["uploaderAvatar"]?.url ?? details["avatar"]?.url + let subscriptionsCount = details["uploaderSubscriberCount"]?.int let uploaded = details["uploaded"]?.doubleValue var published = uploaded.isNil ? nil : (uploaded! / 1000).formattedAsRelativeTime() @@ -336,7 +337,7 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { published: published!, views: details["views"]!.intValue, description: extractDescription(from: content), - channel: Channel(id: channelId, name: author, thumbnailURL: authorThumbnailURL), + channel: Channel(id: channelId, name: author, thumbnailURL: authorThumbnailURL, subscriptionsCount: subscriptionsCount), thumbnails: thumbnails, live: live, likes: details["likes"]?.int, diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 74f54b07..852bf77b 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -45,8 +45,6 @@ final class PlayerModel: ObservableObject { @Published var lastSkipped: Segment? { didSet { rebuildTVMenu() } } @Published var restoredSegments = [Segment]() - @Published var channelWithDetails: Channel? - #if os(iOS) @Published var motionManager: CMMotionManager! @Published var lockedOrientation: UIInterfaceOrientation? @@ -210,11 +208,7 @@ final class PlayerModel: ObservableObject { self?.sponsorBlock.loadSegments( videoID: video.videoID, categories: Defaults[.sponsorBlockCategories] - ) { [weak self] in - if Defaults[.showChannelSubscribers] { - self?.loadCurrentItemChannelDetails() - } - } + ) } } @@ -706,36 +700,6 @@ final class PlayerModel: ObservableObject { currentArtwork = MPMediaItemArtwork(boundsSize: image!.size) { _ in image! } } - func loadCurrentItemChannelDetails() { - guard let video = currentVideo, - !video.channel.detailsLoaded - else { - return - } - - if restoreLoadedChannel() { - return - } - - accounts.api.channel(video.channel.id).load().onSuccess { [weak self] response in - if let channel: Channel = response.typedContent() { - self?.channelWithDetails = channel - withAnimation { - self?.currentItem?.video.channel = channel - } - } - } - } - - @discardableResult func restoreLoadedChannel() -> Bool { - if !currentVideo.isNil, channelWithDetails?.id == currentVideo!.channel.id { - currentItem.video.channel = channelWithDetails! - return true - } - - return false - } - func rateLabel(_ rate: Float) -> String { let formatter = NumberFormatter() formatter.minimumFractionDigits = 0 diff --git a/Model/Player/PlayerQueue.swift b/Model/Player/PlayerQueue.swift index 314d80d8..75111cc3 100644 --- a/Model/Player/PlayerQueue.swift +++ b/Model/Player/PlayerQueue.swift @@ -74,7 +74,6 @@ extension PlayerModel { } preservedTime = currentItem.playbackTime - restoreLoadedChannel() DispatchQueue.main.async { [weak self] in guard let video = self?.currentVideo else { diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index 1f52fdf5..5bec9ecc 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -48,7 +48,6 @@ extension Defaults.Keys { static let playerInstanceID = Key("playerInstance") static let showKeywords = Key("showKeywords", default: false) static let showHistoryInPlayer = Key("showHistoryInPlayer", default: false) - static let showChannelSubscribers = Key("showChannelSubscribers", default: true) static let commentsInstanceID = Key("commentsInstance", default: kavinPipedInstanceID) #if !os(tvOS) static let commentsPlacement = Key("commentsPlacement", default: .separate) diff --git a/Shared/Player/VideoDetails.swift b/Shared/Player/VideoDetails.swift index 832e6443..5bc83e3c 100644 --- a/Shared/Player/VideoDetails.swift +++ b/Shared/Player/VideoDetails.swift @@ -30,7 +30,6 @@ struct VideoDetails: View { @EnvironmentObject private var recents @EnvironmentObject private var subscriptions - @Default(.showChannelSubscribers) private var showChannelSubscribers @Default(.showKeywords) private var showKeywords init( @@ -208,15 +207,13 @@ struct VideoDetails: View { .font(.system(size: 14)) .bold() - if showChannelSubscribers { - Group { - if let subscribers = video!.channel.subscriptionsString { - Text("\(subscribers) subscribers") - } + Group { + if let subscribers = video!.channel.subscriptionsString { + Text("\(subscribers) subscribers") } - .foregroundColor(.secondary) - .font(.caption2) } + .foregroundColor(.secondary) + .font(.caption2) } } } diff --git a/Shared/Settings/PlayerSettings.swift b/Shared/Settings/PlayerSettings.swift index 3030392c..54faaf90 100644 --- a/Shared/Settings/PlayerSettings.swift +++ b/Shared/Settings/PlayerSettings.swift @@ -14,7 +14,6 @@ struct PlayerSettings: View { @Default(.playerSidebar) private var playerSidebar @Default(.showHistoryInPlayer) private var showHistory @Default(.showKeywords) private var showKeywords - @Default(.showChannelSubscribers) private var channelSubscribers @Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer #if os(iOS) @Default(.honorSystemOrientationLock) private var honorSystemOrientationLock @@ -83,7 +82,6 @@ struct PlayerSettings: View { keywordsToggle showHistoryToggle - channelSubscribersToggle } Section(header: SettingsHeader(text: "Picture in Picture")) { @@ -196,10 +194,6 @@ struct PlayerSettings: View { Toggle("Show history", isOn: $showHistory) } - private var channelSubscribersToggle: some View { - Toggle("Show subscribers count", isOn: $channelSubscribers) - } - private var pauseOnHidingPlayerToggle: some View { Toggle("Pause when player is closed", isOn: $pauseOnHidingPlayer) }