From 0972cfb5f2418902372b1fb3988f266af564389d Mon Sep 17 00:00:00 2001 From: higuaifan Date: Thu, 16 May 2024 23:23:36 +0800 Subject: [PATCH 1/3] fix: optimize ugc_season selection logic --- .../Component/Video/VideoDetailViewController.swift | 11 ++++++++++- .../Component/Video/VideoPlayerViewController.swift | 1 + BilibiliLive/Request/WebRequest.swift | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/BilibiliLive/Component/Video/VideoDetailViewController.swift b/BilibiliLive/Component/Video/VideoDetailViewController.swift index 41aafcd1..2f2edf56 100644 --- a/BilibiliLive/Component/Video/VideoDetailViewController.swift +++ b/BilibiliLive/Component/Video/VideoDetailViewController.swift @@ -320,8 +320,17 @@ class VideoDetailViewController: UIViewController { } if let season = data.View.ugc_season { - allUgcEpisodes = Array((season.sections.map { $0.episodes }.joined())) + if season.sections.count > 1 { + season.sections.first(where: { section in section.episodes.contains(where: { episode in episode.aid == data.View.aid }) }).map { section in + allUgcEpisodes = section.episodes + allUgcEpisodes.sort { $0.arc.ctime < $1.arc.ctime } + } + } else { + allUgcEpisodes = season.sections.first?.episodes ?? [] + allUgcEpisodes.sort { $0.arc.ctime < $1.arc.ctime } + } } + ugcCollectionView.reloadData() ugcLabel.text = "合集 \(data.View.ugc_season?.title ?? "") \(data.View.ugc_season?.sections.first?.title ?? "")" ugcView.isHidden = allUgcEpisodes.count == 0 diff --git a/BilibiliLive/Component/Video/VideoPlayerViewController.swift b/BilibiliLive/Component/Video/VideoPlayerViewController.swift index 55b414e0..18f1510a 100644 --- a/BilibiliLive/Component/Video/VideoPlayerViewController.swift +++ b/BilibiliLive/Component/Video/VideoPlayerViewController.swift @@ -18,6 +18,7 @@ struct PlayInfo { var cid: Int? = 0 var epid: Int? = 0 // 港澳台解锁需要 var isBangumi: Bool = false + var ctime: Int? = 0 var isCidVaild: Bool { return cid ?? 0 > 0 diff --git a/BilibiliLive/Request/WebRequest.swift b/BilibiliLive/Request/WebRequest.swift index 97916da0..431b67ec 100644 --- a/BilibiliLive/Request/WebRequest.swift +++ b/BilibiliLive/Request/WebRequest.swift @@ -595,6 +595,7 @@ struct VideoDetail: Codable, Hashable { let ugc_season: UgcSeason? let redirect_url: URL? let stat: Stat + var ctime: Int? struct Stat: Codable, Hashable { let favorite: Int let coin: Int @@ -623,6 +624,7 @@ struct VideoDetail: Codable, Hashable { struct UgcVideoInfo: Codable, Hashable, DisplayData { var ownerName: String { "" } var pic: URL? { arc.pic } + let id: Int let aid: Int let cid: Int let arc: Arc @@ -630,6 +632,7 @@ struct VideoDetail: Codable, Hashable { struct Arc: Codable, Hashable { let pic: URL + let ctime: Int } } } From 678f8c353dfd3941f7f8ca62faa6a8912b1d3043 Mon Sep 17 00:00:00 2001 From: higuaifan Date: Fri, 17 May 2024 01:38:44 +0800 Subject: [PATCH 2/3] fix: improve code structure --- BilibiliLive/Component/Video/VideoDetailViewController.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BilibiliLive/Component/Video/VideoDetailViewController.swift b/BilibiliLive/Component/Video/VideoDetailViewController.swift index 2f2edf56..e65b96c6 100644 --- a/BilibiliLive/Component/Video/VideoDetailViewController.swift +++ b/BilibiliLive/Component/Video/VideoDetailViewController.swift @@ -323,12 +323,11 @@ class VideoDetailViewController: UIViewController { if season.sections.count > 1 { season.sections.first(where: { section in section.episodes.contains(where: { episode in episode.aid == data.View.aid }) }).map { section in allUgcEpisodes = section.episodes - allUgcEpisodes.sort { $0.arc.ctime < $1.arc.ctime } } } else { allUgcEpisodes = season.sections.first?.episodes ?? [] - allUgcEpisodes.sort { $0.arc.ctime < $1.arc.ctime } } + allUgcEpisodes.sort { $0.arc.ctime < $1.arc.ctime } } ugcCollectionView.reloadData() From 3e5310e768da4341a9cd15a64218ec11d16e4a75 Mon Sep 17 00:00:00 2001 From: higuaifan Date: Mon, 20 May 2024 09:42:04 +0800 Subject: [PATCH 3/3] refactor: replace map function with if let structure --- BilibiliLive/Component/Video/VideoDetailViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BilibiliLive/Component/Video/VideoDetailViewController.swift b/BilibiliLive/Component/Video/VideoDetailViewController.swift index e65b96c6..f9ef9a3f 100644 --- a/BilibiliLive/Component/Video/VideoDetailViewController.swift +++ b/BilibiliLive/Component/Video/VideoDetailViewController.swift @@ -321,7 +321,7 @@ class VideoDetailViewController: UIViewController { if let season = data.View.ugc_season { if season.sections.count > 1 { - season.sections.first(where: { section in section.episodes.contains(where: { episode in episode.aid == data.View.aid }) }).map { section in + if let section = season.sections.first(where: { section in section.episodes.contains(where: { episode in episode.aid == data.View.aid }) }) { allUgcEpisodes = section.episodes } } else {