From 0a4599847a7ec1c84f69ced6ac11ce9bc8e9ca03 Mon Sep 17 00:00:00 2001 From: WindowsMEMZ Date: Sun, 20 Oct 2024 12:26:13 +0800 Subject: [PATCH] feat: Splited some backends --- DarockBili.xcodeproj/project.pbxproj | 11 +++ MeowBili/Backend/BiliAPI.swift | 84 +++++++++++++++++++ MeowBili/Backend/ResponseModels.swift | 40 +++++---- MeowBili/InMain/ContentView.swift | 20 +---- MeowBili/InMain/MainView.swift | 30 ++----- MeowBili/Live/LiveDetailView.swift | 20 ++--- .../PersonalCenter/PersonAccountView.swift | 26 ++---- MeowBili/PersonalCenter/SelfQrCardView.swift | 22 +---- MeowBili/PersonalCenter/UserDetailView.swift | 58 +++++-------- MeowBili/Video/VideoPlayerView.swift | 2 +- 10 files changed, 168 insertions(+), 145 deletions(-) diff --git a/DarockBili.xcodeproj/project.pbxproj b/DarockBili.xcodeproj/project.pbxproj index 4033dc4ea..45f427f97 100644 --- a/DarockBili.xcodeproj/project.pbxproj +++ b/DarockBili.xcodeproj/project.pbxproj @@ -198,6 +198,10 @@ 8CC5B7432B8749BC00BAD89E /* MeowBiliUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CC5B7422B8749BC00BAD89E /* MeowBiliUITests.swift */; }; 8CD3D0402C8C715300E9C37C /* MarqueeText in Frameworks */ = {isa = PBXBuildFile; productRef = 8CD3D03F2C8C715300E9C37C /* MarqueeText */; }; 8CD3D0422C8C715B00E9C37C /* MarqueeText in Frameworks */ = {isa = PBXBuildFile; productRef = 8CD3D0412C8C715B00E9C37C /* MarqueeText */; }; + 8CF148952CC40A4C00C13711 /* BiliAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CF148922CC403BF00C13711 /* BiliAPI.swift */; }; + 8CF148962CC40A4C00C13711 /* BiliAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CF148922CC403BF00C13711 /* BiliAPI.swift */; }; + 8CF148972CC40AAB00C13711 /* ResponseModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CF148942CC4040E00C13711 /* ResponseModels.swift */; }; + 8CF148982CC40AAB00C13711 /* ResponseModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CF148942CC4040E00C13711 /* ResponseModels.swift */; }; B2B8137F2CC3D0ED00C69D17 /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2B8137E2CC3D0ED00C69D17 /* WidgetKit.framework */; }; B2B813812CC3D0ED00C69D17 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2B813802CC3D0ED00C69D17 /* SwiftUI.framework */; }; B2B813842CC3D0ED00C69D17 /* MeowWidgetBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B813832CC3D0ED00C69D17 /* MeowWidgetBundle.swift */; }; @@ -1255,6 +1259,7 @@ 8CA7CCB62B77B3BF008E587F /* UserDetailView.swift in Sources */, 8CA7CCCE2B77B4DF008E587F /* DynamicSendView.swift in Sources */, 8CA7CCCC2B77B4CA008E587F /* DynamicDetailView.swift in Sources */, + 8CF148952CC40A4C00C13711 /* BiliAPI.swift in Sources */, 8CA7CCC52B77B47A008E587F /* AudioPlayerView.swift in Sources */, 8CA7CCC82B77B49D008E587F /* ImageViewerView.swift in Sources */, 8CA7CC972B77B115008E587F /* SkinExplorerView.swift in Sources */, @@ -1263,6 +1268,7 @@ 8CC3D5652B7CCF3C005636DC /* SelfQrCardView.swift in Sources */, 8CA7CCB82B77B3D6008E587F /* HistoryView.swift in Sources */, 8CA7CCDC2B77B571008E587F /* LiveMessagesView.swift in Sources */, + 8CF148972CC40AAB00C13711 /* ResponseModels.swift in Sources */, 8CC3D55A2B7CB95D005636DC /* NowPlayingExtension.m in Sources */, 8CA7CC6A2B77AE62008E587F /* Bangumi.swift in Sources */, 8CA7CBC52B77AC4A008E587F /* ContentView.swift in Sources */, @@ -1322,6 +1328,7 @@ 8CBFF0C52B85E55F00350E0F /* SkinExplorerView.swift in Sources */, 8CBFF0BC2B85E55F00350E0F /* HistoryView.swift in Sources */, 8CBFF0B72B85E55F00350E0F /* ContentView.swift in Sources */, + 8CF148962CC40A4C00C13711 /* BiliAPI.swift in Sources */, 8CBFF0DB2B85E55F00350E0F /* SignalErrorView.swift in Sources */, 8CBFF0D82B85E55F00350E0F /* VideoDetailView.swift in Sources */, 8CBFF0D72B85E55F00350E0F /* MainView.swift in Sources */, @@ -1330,6 +1337,7 @@ 8CBFF0E82B85E55F00350E0F /* LivePlayerView.swift in Sources */, 8CBFF0BD2B85E55F00350E0F /* DynamicSendView.swift in Sources */, 8CBFF0DD2B85E55F00350E0F /* DownloadObj.swift in Sources */, + 8CF148982CC40AAB00C13711 /* ResponseModels.swift in Sources */, 8CBFF0D02B85E55F00350E0F /* AVExtension.m in Sources */, 8CBFF0C12B85E55F00350E0F /* CodeExt.swift in Sources */, 8CBFF0E62B85E55F00350E0F /* PersonAccountView.swift in Sources */, @@ -1684,6 +1692,7 @@ FRAMEWORK_SEARCH_PATHS = ""; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "MeowBili-Watch-App-Info.plist"; + INFOPLIST_KEY_CFBundleDisplayName = "喵哩喵哩"; INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; INFOPLIST_KEY_WKCompanionAppBundleIdentifier = com.darock.alt785.DarockBili; INFOPLIST_KEY_WKRunsIndependentlyOfCompanionApp = YES; @@ -1902,6 +1911,7 @@ FRAMEWORK_SEARCH_PATHS = ""; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "MeowBili-Watch-App-Info.plist"; + INFOPLIST_KEY_CFBundleDisplayName = "喵哩喵哩"; INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; INFOPLIST_KEY_WKCompanionAppBundleIdentifier = com.darock.DarockBili; INFOPLIST_KEY_WKRunsIndependentlyOfCompanionApp = YES; @@ -1939,6 +1949,7 @@ FRAMEWORK_SEARCH_PATHS = ""; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "MeowBili-Watch-App-Info.plist"; + INFOPLIST_KEY_CFBundleDisplayName = "喵哩喵哩"; INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; INFOPLIST_KEY_WKCompanionAppBundleIdentifier = com.darock.DarockBili; INFOPLIST_KEY_WKRunsIndependentlyOfCompanionApp = YES; diff --git a/MeowBili/Backend/BiliAPI.swift b/MeowBili/Backend/BiliAPI.swift index 08e52e9ac..6edbe5d4c 100644 --- a/MeowBili/Backend/BiliAPI.swift +++ b/MeowBili/Backend/BiliAPI.swift @@ -16,9 +16,93 @@ // //===----------------------------------------------------------------------===// +import SwiftUI import DarockKit +import Alamofire +import SwiftyJSON class BiliAPI { static let shared = BiliAPI() + @AppStorage("DedeUserID") private var dedeUserID = "" + @AppStorage("DedeUserID__ckMd5") private var dedeUserID__ckMd5 = "" + @AppStorage("SESSDATA") private var sessdata = "" + @AppStorage("bili_jct") private var biliJct = "" + @AppStorage("CachedBiliTicket") private var cachedBiliTicket = "" + + /// 获取指定用户详情 + /// - Parameter uid: 用户 UID + /// - Returns: 用户详情数据 + func userInfo(of uid: String? = nil) async -> UserInfo? { + let uid = uid ?? dedeUserID + let headers: HTTPHeaders = [ + "cookie": "SESSDATA=\(sessdata)", + "referer": "https://message.bilibili.com/", // rdar://gh/SocialSisterYi/bilibili-API-collect/issues/631#issuecomment-2099276628 + "User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + ] + return await withCheckedContinuation { continuation in + biliWbiSign(paramEncoded: "mid=\(uid)".base64Encoded()) { signed in + if let signed { + DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/space/wbi/acc/info?\(signed)", headers: headers) { respJson, isSuccess in + if isSuccess { + if !CheckBApiError(from: respJson) { + continuation.resume(returning: nil) + return + } + continuation.resume(returning: UserInfo(json: respJson)) + } else { + continuation.resume(returning: nil) + } + } + } else { + continuation.resume(returning: nil) + } + } + } + } + + func userRelation(of uid: String) async -> UserRelation? { + let headers: HTTPHeaders = [ + "cookie": "SESSDATA=\(sessdata); buvid3=\(globalBuvid3); bili_ticket=\(cachedBiliTicket)", + "referer": "https://message.bilibili.com/", // rdar://gh/SocialSisterYi/bilibili-API-collect/issues/631#issuecomment-2099276628 + "User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + ] + if case .success(let json) = await DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation/stat?vmid=\(uid)", headers: headers) { + if !CheckBApiError(from: json) { return nil } + return UserRelation(json: json["data"]) + } else { + return nil + } + } + + func isFollowed(user uid: String) async -> Bool { + let headers: HTTPHeaders = [ + "cookie": "SESSDATA=\(sessdata); buvid3=\(globalBuvid3); bili_ticket=\(cachedBiliTicket)", + "referer": "https://message.bilibili.com/", // rdar://gh/SocialSisterYi/bilibili-API-collect/issues/631#issuecomment-2099276628 + "User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + ] + if case let .success(json) = await DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation?fid=\(uid)", headers: headers) { + if !CheckBApiError(from: json) { return false } + if json["data"]["attribute"].int ?? 0 == 2 || json["data"]["attribute"].int ?? 0 == 6 { + return true + } + } + return false + } + + func currentUserExperience() async -> (current: Int, next: Int, min: Int)? { + let headers: HTTPHeaders = [ + "cookie": "SESSDATA=\(sessdata); buvid3=\(globalBuvid3); bili_ticket=\(cachedBiliTicket)", + "referer": "https://message.bilibili.com/", // rdar://gh/SocialSisterYi/bilibili-API-collect/issues/631#issuecomment-2099276628 + "User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + ] + if case let .success(json) = await DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/web-interface/nav", headers: headers) { + if !CheckBApiError(from: json) { return nil } + let currentExp = json["data"]["level_info"]["current_exp"].int ?? 0 + let nextExp = json["data"]["level_info"]["next_exp"].int ?? 0 + let minExp = json["data"]["level_info"]["current_min"].int ?? 0 + return (currentExp, nextExp, minExp) + } + return nil + } } diff --git a/MeowBili/Backend/ResponseModels.swift b/MeowBili/Backend/ResponseModels.swift index dca3f8b9d..7d22fde8f 100644 --- a/MeowBili/Backend/ResponseModels.swift +++ b/MeowBili/Backend/ResponseModels.swift @@ -23,29 +23,29 @@ struct UserInfo: Identifiable { let id: Int64 let sex: String let level: Int - let coins: Double? + let coins: Double let face: String let vip: VIPDetail? let birthday: String - let official: OfficialDetail? + let official: OfficialDetail let name: String let sign: String init(json: JSON) { - self.id = json["mid"].int64Value - self.sex = json["sex"].string/ - self.level = json["level"].int ?? 0 - self.coins = json["coins"].double ?? 0 - self.face = json["face"].string/ - if json["vip"].dictionary != nil { - self.vip = .init(json: json["vip"]) + self.id = json["data"]["mid"].int64Value + self.sex = json["data"]["sex"].string/ + self.level = json["data"]["level"].int ?? 0 + self.coins = json["data"]["coins"].double ?? -1 + self.face = json["data"]["face"].string/ + if json["data"]["vip"].dictionary != nil { + self.vip = .init(json: json["data"]["vip"]) + } else { + self.vip = nil } - self.birthday = json["birthday"].string ?? "01-01" - if json["official"].dictionary != nil { - self.official = .init(json: json["official"]) - } - self.name = json["name"].string/ - self.sign = json["sign"].string/ + self.birthday = json["data"]["birthday"].string ?? "01-01" + self.official = .init(json: json["data"]["official"]) + self.name = json["data"]["name"].string/ + self.sign = json["data"]["sign"].string/ } struct VIPDetail { @@ -77,3 +77,13 @@ struct UserInfo: Identifiable { } } } + +struct UserRelation { + let following: Int + let follower: Int + + init(json: JSON) { + self.following = json["following"].int ?? -1 + self.follower = json["follower"].int ?? -1 + } +} diff --git a/MeowBili/InMain/ContentView.swift b/MeowBili/InMain/ContentView.swift index 86eced988..b3fc49f48 100644 --- a/MeowBili/InMain/ContentView.swift +++ b/MeowBili/InMain/ContentView.swift @@ -122,23 +122,9 @@ struct ContentView: View { .onAppear { updateBiliTicket(csrf: biliJct) if dedeUserID != "" { - getBuvid(url: "https://api.bilibili.com/x/space/wbi/acc/info".urlEncoded()) { buvid3, buvid4, _uuid, _ in - let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata); innersign=0; buvid3=\(buvid3); b_nut=1704873471; i-wanna-go-back=-1; b_ut=7; b_lsid=9910433CB_18CF260AB89; _uuid=\(_uuid); enable_web_push=DISABLE; header_theme_version=undefined; home_feed_column=4; browser_resolution=3440-1440; buvid4=\(buvid4);", - "referer": "https://message.bilibili.com/", // rdar://gh/SocialSisterYi/bilibili-API-collect/issues/631#issuecomment-2099276628 - "User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" - ] - biliWbiSign(paramEncoded: "mid=\(dedeUserID)".base64Encoded()) { signed in - if let signed { - debugPrint(signed) - autoRetryRequestApi("https://api.bilibili.com/x/space/wbi/acc/info?\(signed)", headers: headers) { respJson, isSuccess in - if isSuccess { - debugPrint(respJson) - if !CheckBApiError(from: respJson) { return } - userFaceUrl = respJson["data"]["face"].string ?? "E" - } - } - } + Task { + if let info = await BiliAPI.shared.userInfo() { + userFaceUrl = info.face } } } diff --git a/MeowBili/InMain/MainView.swift b/MeowBili/InMain/MainView.swift index acc5fb31a..ad262fd66 100644 --- a/MeowBili/InMain/MainView.swift +++ b/MeowBili/InMain/MainView.swift @@ -112,27 +112,15 @@ struct MainView: View { .sheet(isPresented: $isNewUserPresenting, content: { LoginView() }) .onAppear { if username == "" { - let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)", - "referer": "https://message.bilibili.com/", // rdar://gh/SocialSisterYi/bilibili-API-collect/issues/631#issuecomment-2099276628 - "User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" - ] - biliWbiSign(paramEncoded: "mid=\(dedeUserID)".base64Encoded()) { signed in - if let signed { - DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/space/wbi/acc/info?\(signed)", headers: headers) { respJson, isSuccess in - if isSuccess { - debugPrint(respJson) - if !CheckBApiError(from: respJson) { return } - username = respJson["data"]["name"].string ?? "" - userSign = respJson["data"]["sign"].string ?? "" - userFaceUrl = respJson["data"]["face"].string ?? "E" - if let bd = respJson["data"]["birthday"].string, let mo = bd.split(separator: "-")[from: 0], let d = bd.split(separator: "-")[from: 1] { - if let imo = Int(mo), let id = Int(d), imo == Date.now.month && id == Date.now.day { - festivalType = .birthday - } - } - } else if isShowNetworkFixing { - isNetworkFixPresented = true + Task { + if let info = await BiliAPI.shared.userInfo() { + username = info.name + userSign = info.sign + userFaceUrl = info.face + let bd = info.birthday + if let mo = bd.split(separator: "-")[from: 0], let d = bd.split(separator: "-")[from: 1] { + if let imo = Int(mo), let id = Int(d), imo == Date.now.month && id == Date.now.day { + festivalType = .birthday } } } diff --git a/MeowBili/Live/LiveDetailView.swift b/MeowBili/Live/LiveDetailView.swift index bc7b5b024..aabce8053 100644 --- a/MeowBili/Live/LiveDetailView.swift +++ b/MeowBili/Live/LiveDetailView.swift @@ -217,20 +217,12 @@ struct LiveDetailView: View { tagName = respJson["data"]["tags"].string ?? "[加载失败]" if let upUid = respJson["data"]["uid"].int64 { streamerId = upUid - biliWbiSign(paramEncoded: "mid=\(upUid)".base64Encoded()) { signed in - if let signed { - debugPrint(signed) - autoRetryRequestApi("https://api.bilibili.com/x/space/wbi/acc/info?\(signed)", headers: headers) { respJson, isSuccess in - if isSuccess { - if !CheckBApiError(from: respJson) { return } - streamerFaceUrl = respJson["data"]["face"].string ?? "E" - streamerName = respJson["data"]["name"].string ?? "[加载失败]" - DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation/stat?vmid=\(upUid)", headers: headers) { respJson, isSuccess in - if isSuccess { - streamerFansCount = respJson["data"]["follower"].int ?? -1 - } - } - } + Task { + if let info = await BiliAPI.shared.userInfo(of: String(upUid)) { + streamerFaceUrl = info.face + streamerName = info.name + if let relation = await BiliAPI.shared.userRelation(of: String(upUid)) { + streamerFansCount = relation.follower } } } diff --git a/MeowBili/PersonalCenter/PersonAccountView.swift b/MeowBili/PersonalCenter/PersonAccountView.swift index ce5fa0cc1..5ef12ed76 100644 --- a/MeowBili/PersonalCenter/PersonAccountView.swift +++ b/MeowBili/PersonalCenter/PersonAccountView.swift @@ -216,27 +216,11 @@ struct PersonAccountView: View { } func getAccountInfo() { if username == "" { - getBuvid(url: "https://api.bilibili.com/x/space/wbi/acc/info".urlEncoded()) { buvid3, buvid4, _uuid, _ in - let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata); innersign=0; buvid3=\(buvid3); b_nut=1704873471; i-wanna-go-back=-1; b_ut=7; b_lsid=9910433CB_18CF260AB89; _uuid=\(_uuid); enable_web_push=DISABLE; header_theme_version=undefined; home_feed_column=4; browser_resolution=3440-1440; buvid4=\(buvid4);", - "referer": "https://message.bilibili.com/", // rdar://gh/SocialSisterYi/bilibili-API-collect/issues/631#issuecomment-2099276628 - "User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" - ] - biliWbiSign(paramEncoded: "mid=\(dedeUserID)".base64Encoded()) { signed in - if let signed { - debugPrint(signed) - autoRetryRequestApi("https://api.bilibili.com/x/space/wbi/acc/info?\(signed)", headers: headers) { respJson, isSuccess in - if isSuccess { - debugPrint(respJson) - if !CheckBApiError(from: respJson) { return } - username = respJson["data"]["name"].string ?? "" - userSign = respJson["data"]["sign"].string ?? "" - userFaceUrl = respJson["data"]["face"].string ?? "E" - } else if isShowNetworkFixing { - isNetworkFixPresented = true - } - } - } + Task { + if let info = await BiliAPI.shared.userInfo() { + username = info.name + userSign = info.sign + userFaceUrl = info.face } } } diff --git a/MeowBili/PersonalCenter/SelfQrCardView.swift b/MeowBili/PersonalCenter/SelfQrCardView.swift index 3f6cb7a21..c0f9ab264 100644 --- a/MeowBili/PersonalCenter/SelfQrCardView.swift +++ b/MeowBili/PersonalCenter/SelfQrCardView.swift @@ -81,24 +81,10 @@ struct SelfQrCardView: View { } .onAppear { qrcodeImg = EFQRCode.generate(for: "https://space.bilibili.com/\(dedeUserID)", foregroundColor: Color(hex: 0x2b4785).cgColor!) - - getBuvid(url: "https://api.bilibili.com/x/space/wbi/acc/info".urlEncoded()) { buvid3, buvid4, _uuid, _ in - let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata); innersign=0; buvid3=\(buvid3); b_nut=1704873471; i-wanna-go-back=-1; b_ut=7; b_lsid=9910433CB_18CF260AB89; _uuid=\(_uuid); enable_web_push=DISABLE; header_theme_version=undefined; home_feed_column=4; browser_resolution=3440-1440; buvid4=\(buvid4);", - "User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" - ] - biliWbiSign(paramEncoded: "mid=\(dedeUserID)".base64Encoded()) { signed in - if let signed { - debugPrint(signed) - autoRetryRequestApi("https://api.bilibili.com/x/space/wbi/acc/info?\(signed)", headers: headers) { respJson, isSuccess in - if isSuccess { - debugPrint(respJson) - if !CheckBApiError(from: respJson) { return } - username = respJson["data"]["name"].string ?? "" - userFaceUrl = respJson["data"]["face"].string ?? "E" - } - } - } + Task { + if let info = await BiliAPI.shared.userInfo() { + username = info.name + userFaceUrl = info.face } } } diff --git a/MeowBili/PersonalCenter/UserDetailView.swift b/MeowBili/PersonalCenter/UserDetailView.swift index 9b4c14a47..a972b6df2 100644 --- a/MeowBili/PersonalCenter/UserDetailView.swift +++ b/MeowBili/PersonalCenter/UserDetailView.swift @@ -328,49 +328,31 @@ struct UserDetailView: View { #endif } .onAppear { - let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata); buvid3=\(globalBuvid3); bili_ticket=\(cachedBiliTicket)", - "referer": "https://message.bilibili.com/", // rdar://gh/SocialSisterYi/bilibili-API-collect/issues/631#issuecomment-2099276628 - "User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" - ] - biliWbiSign(paramEncoded: "mid=\(uid)".base64Encoded()) { signed in - if let signed { - autoRetryRequestApi("https://api.bilibili.com/x/space/wbi/acc/info?\(signed)", headers: headers) { respJson, isSuccess in - if isSuccess { - if !CheckBApiError(from: respJson) { return } - userFaceUrl = respJson["data"]["face"].string ?? "E" - username = respJson["data"]["name"].string ?? "[加载失败]" - userLevel = respJson["data"]["level"].int ?? 0 - officialType = respJson["data"]["official"]["type"].int ?? -1 - officialTitle = respJson["data"]["official"]["title"].string ?? "" - userSign = respJson["data"]["sign"].string ?? "[加载失败]" - coinCount = respJson["data"]["coins"].int ?? -1 - vipLabel = respJson["data"]["vip"]["label"]["text"].string ?? "" - DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation/stat?vmid=\(uid)", headers: headers) { respJson, isSuccess in - if isSuccess { - followCount = respJson["data"]["following"].int ?? -1 - fansCount = respJson["data"]["follower"].int ?? -1 - } - } - } + Task { + if let info = await BiliAPI.shared.userInfo(of: uid) { + userFaceUrl = info.face + username = info.name + userLevel = info.level + officialType = info.official.type + officialTitle = info.official.title + userSign = info.sign + coinCount = Int(info.coins) + vipLabel = info.vip?.label.text ?? "" + if let relation = await BiliAPI.shared.userRelation(of: uid) { + followCount = relation.following + fansCount = relation.follower } } } - DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation?fid=\(uid)", headers: headers) { respJson, isSuccess in - if isSuccess { - if !CheckBApiError(from: respJson) { return } - if respJson["data"]["attribute"].int ?? 0 == 2 || respJson["data"]["attribute"].int ?? 0 == 6 { - isFollowed = true - } - } + Task { + isFollowed = await BiliAPI.shared.isFollowed(user: uid) } if uid == dedeUserID { - DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/web-interface/nav", headers: headers) { respJson, isSuccess in - if isSuccess { - if !CheckBApiError(from: respJson) { return } - currentExp = respJson["data"]["level_info"]["current_exp"].int ?? 0 - nextExp = respJson["data"]["level_info"]["next_exp"].int ?? 0 - minExp = respJson["data"]["level_info"]["current_min"].int ?? 0 + Task { + if let exp = await BiliAPI.shared.currentUserExperience() { + currentExp = exp.current + nextExp = exp.next + minExp = exp.min } } } diff --git a/MeowBili/Video/VideoPlayerView.swift b/MeowBili/Video/VideoPlayerView.swift index 029237ab7..6970ca984 100644 --- a/MeowBili/Video/VideoPlayerView.swift +++ b/MeowBili/Video/VideoPlayerView.swift @@ -157,7 +157,6 @@ struct VideoPlayerView: View { playerScaledOffset = .zero } }) - .rotationEffect(.degrees(isFullScreen ? 90 : 0)) .frame( width: isFullScreen ? WKInterfaceDevice.current().screenBounds.height : nil, height: isFullScreen ? WKInterfaceDevice.current().screenBounds.width : nil @@ -199,6 +198,7 @@ struct VideoPlayerView: View { } } } + .rotationEffect(.degrees(isFullScreen ? 90 : 0)) .tag(1) List { Section {