diff --git a/.github/workflows/ui-test.yml b/.github/workflows/ui-test.yml index 57373a4db..31ed0f948 100644 --- a/.github/workflows/ui-test.yml +++ b/.github/workflows/ui-test.yml @@ -73,12 +73,14 @@ jobs: echo "FIN_STATUS=success" >> $GITHUB_ENV - name: Process Test Result + if: always() run: | mv ~/Library/Developer/Xcode/DerivedData/DarockBili-*/Logs/Test/Test-*.xcresult ./Caches/Test-1.xcresult mkdir Caches/ExportFiles xcparse -s ./Caches/Test-1.xcresult ./Caches/ExportFiles - name: Upload Test Attachments + if: always() uses: actions/upload-artifact@v3 with: name: Test Attachments diff --git a/DarockBili Watch App/DarockBiliApp.swift b/DarockBili Watch App/DarockBiliApp.swift index da58b5024..7d09d0041 100644 --- a/DarockBili Watch App/DarockBiliApp.swift +++ b/DarockBili Watch App/DarockBiliApp.swift @@ -25,7 +25,7 @@ import SDWebImageSVGCoder import SDWebImageWebPCoder //!!!: Debug Setting, Set false Before Release -var debug = true +var debug = false var debugControlStdout = "stdo\n" diff --git a/DarockBili Watch App/Extension/CodeExt.swift b/DarockBili Watch App/Extension/CodeExt.swift index c9be619e3..34ad643ad 100644 --- a/DarockBili Watch App/Extension/CodeExt.swift +++ b/DarockBili Watch App/Extension/CodeExt.swift @@ -157,7 +157,10 @@ func biliWbiSign(paramEncoded: String, completion: @escaping (String?) -> Void) } func getWbiKeys(completion: @escaping (Result<(imgKey: String, subKey: String), Error>) -> Void) { - AF.request("https://api.bilibili.com/x/web-interface/nav").responseJSON { response in + let headers: HTTPHeaders = [ + "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" + ] + AF.request("https://api.bilibili.com/x/web-interface/nav", headers: headers).responseJSON { response in switch response.result { case .success(let value): let json = JSON(value) diff --git a/DarockBili Watch App/InMain/MainView.swift b/DarockBili Watch App/InMain/MainView.swift index 6bd7ba4e0..783addf89 100644 --- a/DarockBili Watch App/InMain/MainView.swift +++ b/DarockBili Watch App/InMain/MainView.swift @@ -158,7 +158,8 @@ struct MainView: View { isLoadingNew = true isFailedToLoad = false let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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: "ps=\(isInLowBatteryMode ? 10 : 30)".base64Encoded()) { signed in if let signed { diff --git a/DarockBili Watch App/Others/LoginView.swift b/DarockBili Watch App/Others/LoginView.swift index 4a8bf348c..72d015086 100644 --- a/DarockBili Watch App/Others/LoginView.swift +++ b/DarockBili Watch App/Others/LoginView.swift @@ -73,7 +73,10 @@ struct LoginView: View { } .tag(0) .onAppear { - DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/web/qrcode/generate") { respJson, isSuccess in + let headers: HTTPHeaders = [ + "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" + ] + DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/web/qrcode/generate", headers: headers) { respJson, isSuccess in if isSuccess { let qrUrl = respJson["data"]["url"].string!.replacingOccurrences(of: "\\u0026", with: "&") debugPrint(qrUrl) @@ -83,7 +86,7 @@ struct LoginView: View { qrKey = respJson["data"]["qrcode_key"].string! Timer.scheduledTimer(withTimeInterval: 2.0, repeats: true) { timer in qrTimer = timer - DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=\(qrKey)") { respJson, isSuccess in + DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=\(qrKey)", headers: headers) { respJson, isSuccess in if respJson["data"]["code"].int == 86090 { isScanned = true } else if respJson["data"]["code"].int == 0 { @@ -195,7 +198,10 @@ struct LoginView: View { } .tag(1) .onAppear { - DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/captcha?source=main_web") { respJson, isSuccess in + let headers: HTTPHeaders = [ + "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" + ] + DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/captcha?source=main_web", headers: headers) { respJson, isSuccess in if isSuccess { challenge = respJson["data"]["geetest"]["challenge"].string! gt = respJson["data"]["geetest"]["gt"].string! diff --git a/DarockBili Watch App/PersonalCenter/FavoriteView.swift b/DarockBili Watch App/PersonalCenter/FavoriteView.swift index d3cb7e947..d22ae8c90 100644 --- a/DarockBili Watch App/PersonalCenter/FavoriteView.swift +++ b/DarockBili Watch App/PersonalCenter/FavoriteView.swift @@ -42,7 +42,8 @@ struct FavoriteView: View { .onAppear { if !isLoaded { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata);" + "cookie": "SESSDATA=\(sessdata);", + "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" ] DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v3/fav/folder/created/list-all?up_mid=\(dedeUserID)", headers: headers) { respJson, isSuccess in if isSuccess { @@ -109,7 +110,8 @@ struct FavoriteDetailView: View { func RefreshDetailData() { details.removeAll() let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata);" + "cookie": "SESSDATA=\(sessdata);", + "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" ] DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v3/fav/resource/list?media_id=\(folderDatas["ID"]!)&ps=20&pn=\(nowPage)", headers: headers) { respJson, isSuccess in if isSuccess { diff --git a/DarockBili Watch App/PersonalCenter/FollowListView.swift b/DarockBili Watch App/PersonalCenter/FollowListView.swift index 66236e0f5..55fee13b8 100644 --- a/DarockBili Watch App/PersonalCenter/FollowListView.swift +++ b/DarockBili Watch App/PersonalCenter/FollowListView.swift @@ -17,6 +17,7 @@ import SwiftUI import DarockKit +import Alamofire import SwiftyJSON import SDWebImageSwiftUI @@ -114,7 +115,11 @@ struct FollowListView: View { } } func RefreshNew() { - DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation/followings?vmid=\(viewUserId)&order_type=&ps=20&pn=\(nowPage)") { respJson, isSuccess in + let headers: HTTPHeaders = [ + "cookie": "SESSDATA=\(sessdata);", + "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" + ] + DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation/followings?vmid=\(viewUserId)&order_type=&ps=20&pn=\(nowPage)", headers: headers) { respJson, isSuccess in if isSuccess { let datas = respJson["data"]["list"] for data in datas { diff --git a/DarockBili Watch App/PersonalCenter/HistoryView.swift b/DarockBili Watch App/PersonalCenter/HistoryView.swift index 21f00710b..17248f7f5 100644 --- a/DarockBili Watch App/PersonalCenter/HistoryView.swift +++ b/DarockBili Watch App/PersonalCenter/HistoryView.swift @@ -68,7 +68,8 @@ struct HistoryView: View { .onAppear { if !isLoaded { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata);" + "cookie": "SESSDATA=\(sessdata);", + "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" ] DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v2/history", headers: headers) { respJson, isSuccess in if isSuccess { diff --git a/DarockBili Watch App/PersonalCenter/PersonAccountView.swift b/DarockBili Watch App/PersonalCenter/PersonAccountView.swift index e0bb4517a..f24409ce3 100644 --- a/DarockBili Watch App/PersonalCenter/PersonAccountView.swift +++ b/DarockBili Watch App/PersonalCenter/PersonAccountView.swift @@ -224,7 +224,8 @@ struct PersonAccountView: View { .navigationBarTitleDisplayMode(.large) .onAppear { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata);" + "cookie": "SESSDATA=\(sessdata);", + "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" ] DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/member/web/account", headers: headers) { respJson, isSuccess in if isSuccess { diff --git a/DarockBili Watch App/PersonalCenter/UserDetailView.swift b/DarockBili Watch App/PersonalCenter/UserDetailView.swift index 6906d2d29..1dfecca35 100644 --- a/DarockBili Watch App/PersonalCenter/UserDetailView.swift +++ b/DarockBili Watch App/PersonalCenter/UserDetailView.swift @@ -144,7 +144,8 @@ struct UserDetailView: View { } .onAppear { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata);" + "cookie": "SESSDATA=\(sessdata);", + "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 { @@ -164,7 +165,7 @@ struct UserDetailView: View { officialTitle = respJson["data"]["official"]["title"].string ?? "" userSign = respJson["data"]["sign"].string ?? "[加载失败]" coinCount = respJson["data"]["coins"].int ?? -1 - DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation/stat?vmid=\(uid)") { respJson, isSuccess in + 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 @@ -174,7 +175,7 @@ struct UserDetailView: View { } } } - DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation?fid=\(uid)") { respJson, isSuccess in + DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation?fid=\(uid)", headers: headers) { respJson, isSuccess in if isSuccess { if respJson["data"]["attribute"].int ?? 0 == 2 || respJson["data"]["attribute"].int ?? 0 == 6 { isFollowed = true @@ -251,7 +252,8 @@ struct UserDetailView: View { } Button(action: { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata);" + "cookie": "SESSDATA=\(sessdata);", + "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" ] AF.request("https://api.bilibili.com/x/relation/modify", method: .post, parameters: ModifyUserRelation(fid: Int(uid)!, act: isFollowed ? 2 : 1, csrf: biliJct), headers: headers).response { response in debugPrint(response) diff --git a/DarockBili Watch App/PersonalCenter/WatchLaterView.swift b/DarockBili Watch App/PersonalCenter/WatchLaterView.swift index e967c20ed..b0747b11c 100644 --- a/DarockBili Watch App/PersonalCenter/WatchLaterView.swift +++ b/DarockBili Watch App/PersonalCenter/WatchLaterView.swift @@ -36,7 +36,8 @@ struct WatchLaterView: View { } .onAppear { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata);" + "cookie": "SESSDATA=\(sessdata);", + "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" ] DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v2/history/toview", headers: headers) { respJson, isSuccess in if isSuccess { diff --git a/DarockBili Watch App/UserDynamic/UserDynamicMainView.swift b/DarockBili Watch App/UserDynamic/UserDynamicMainView.swift index a15704f4f..bcb2d8ab3 100644 --- a/DarockBili Watch App/UserDynamic/UserDynamicMainView.swift +++ b/DarockBili Watch App/UserDynamic/UserDynamicMainView.swift @@ -181,7 +181,8 @@ struct UserDynamicMainView: View { func ContinueLoadDynamic() { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata);" + "cookie": "SESSDATA=\(sessdata);", + "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" ] DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?type=all\({ () -> String in if lastDynamicID != "" { return "&offset=\(lastDynamicID)"; } else { return ""; }; }())&page=\(nextLoadPage)", headers: headers) { respJson, isSuccess in if isSuccess { diff --git a/DarockBili Watch App/Video/VideoCommentsView.swift b/DarockBili Watch App/Video/VideoCommentsView.swift index 8d39c5d55..1c1bc3b9c 100644 --- a/DarockBili Watch App/Video/VideoCommentsView.swift +++ b/DarockBili Watch App/Video/VideoCommentsView.swift @@ -159,7 +159,8 @@ struct VideoCommentsView: View { .opacity(comments[i]["UserAction"]! == "1" ? 1 : 0.6) .onTapGesture { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] AF.request("https://api.bilibili.com/x/v2/reply/action", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(comments[i]["Rpid"]!)!, action: comments[i]["UserAction"]! == "1" ? 0 : 1, csrf: biliJct), headers: headers).response { response in debugPrint(response) @@ -174,7 +175,8 @@ struct VideoCommentsView: View { .opacity(comments[i]["UserAction"]! == "2" ? 1 : 0.6) .onTapGesture { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] AF.request("https://api.bilibili.com/x/v2/reply/hate", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(comments[i]["Rpid"]!)!, action: comments[i]["UserAction"]! == "2" ? 0 : 1, csrf: biliJct), headers: headers).response { response in debugPrint(response) @@ -222,7 +224,8 @@ struct VideoCommentsView: View { avid = bv2av(bvid: oid) debugPrint(avid) let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata);" + "cookie": "SESSDATA=\(sessdata);", + "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" ] DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/v2/reply?type=1&oid=\(avid)&sort=1&ps=20&pn=\(nowPage)", headers: headers) { respJson, isSuccess in if isSuccess { @@ -352,7 +355,8 @@ struct VideoCommentsView: View { .opacity(replies[i]["UserAction"]! == "1" ? 1 : 0.6) .onTapGesture { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] AF.request("https://api.bilibili.com/x/v2/reply/action", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(replies[i]["Rpid"]!)!, action: replies[i]["UserAction"]! == "1" ? 0 : 1, csrf: biliJct), headers: headers).response { response in debugPrint(response) @@ -367,7 +371,8 @@ struct VideoCommentsView: View { .opacity(replies[i]["UserAction"]! == "2" ? 1 : 0.6) .onTapGesture { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] AF.request("https://api.bilibili.com/x/v2/reply/hate", method: .post, parameters: BiliCommentLike(oid: avid, rpid: Int(replies[i]["Rpid"]!)!, action: replies[i]["UserAction"]! == "2" ? 0 : 1, csrf: biliJct), headers: headers).response { response in debugPrint(response) @@ -420,7 +425,8 @@ struct VideoCommentsView: View { .onSubmit { if sendCommentCache != "" { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] AF.request("https://api.bilibili.com/x/v2/reply/add", method: .post, parameters: BiliSubmitComment(oid: avid, message: sendCommentCache, csrf: biliJct), headers: headers).response { response in sendCommentCache = "" diff --git a/DarockBili Watch App/Video/VideoDetailView.swift b/DarockBili Watch App/Video/VideoDetailView.swift index 218551ac3..55723388d 100644 --- a/DarockBili Watch App/Video/VideoDetailView.swift +++ b/DarockBili Watch App/Video/VideoDetailView.swift @@ -89,7 +89,8 @@ struct VideoDetailView: View { .sheet(isPresented: $isDownloadPresented, content: {VideoDownloadView(bvid: videoDetails["BV"]!, videoDetails: videoDetails)}) Button(action: { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] AF.request("https://api.bilibili.com/x/v2/history/toview/add", method: .post, parameters: ["bvid": videoDetails["BV"]!, "csrf": biliJct], headers: headers).response { response in do { @@ -119,7 +120,8 @@ struct VideoDetailView: View { if videoGetterSource == "official" { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] AF.request("https://api.bilibili.com/x/web-interface/view?bvid=\(videoDetails["BV"]!)").response { response in let cid = Int((String(data: response.data!, encoding: .utf8)?.components(separatedBy: "\"pages\":[{\"cid\":")[1].components(separatedBy: ",")[0])!)! @@ -275,7 +277,8 @@ struct VideoDetailView: View { .accentColor(.white) .onAppear { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/web-interface/archive/has/like?bvid=\(videoDetails["BV"]!)", headers: headers) { respJson, isSuccess in if isSuccess { @@ -341,7 +344,7 @@ struct VideoDetailView: View { } } if let cid = respJson["data"]["pages"][0]["cid"].int { - DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/player/online/total?bvid=\(videoDetails["BV"]!)&cid=\(cid)") { respJson, isSuccess in + DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/player/online/total?bvid=\(videoDetails["BV"]!)&cid=\(cid)", headers: headers) { respJson, isSuccess in if isSuccess { nowPlayingCount = respJson["data"]["total"].string ?? "[加载失败]" } @@ -471,9 +474,10 @@ struct VideoDetailView: View { if videoGetterSource == "official" { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] - AF.request("https://api.bilibili.com/x/web-interface/view?bvid=\(videoDetails["BV"]!)").response { response in + AF.request("https://api.bilibili.com/x/web-interface/view?bvid=\(videoDetails["BV"]!)", headers: headers).response { response in let cid = Int((String(data: response.data!, encoding: .utf8)?.components(separatedBy: "\"pages\":[{\"cid\":")[1].components(separatedBy: ",")[0])!)! VideoDetailView.willPlayVideoCID = String(cid) AF.request("https://api.bilibili.com/x/player/playurl?platform=html5&bvid=\(videoDetails["BV"]!)&cid=\(cid)", headers: headers).response { response in @@ -505,9 +509,10 @@ struct VideoDetailView: View { if videoGetterSource == "official" { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] - AF.request("https://api.bilibili.com/x/web-interface/view?bvid=\(videoDetails["BV"]!)").response { response in + AF.request("https://api.bilibili.com/x/web-interface/view?bvid=\(videoDetails["BV"]!)", headers: headers).response { response in let cid = Int((String(data: response.data!, encoding: .utf8)?.components(separatedBy: "\"pages\":[{\"cid\":")[1].components(separatedBy: ",")[0])!)! VideoDetailView.willPlayVideoCID = String(cid) AF.request("https://api.bilibili.com/x/player/playurl?platform=html5&bvid=\(videoDetails["BV"]!)&cid=\(cid)", headers: headers).response { response in @@ -545,7 +550,8 @@ struct VideoDetailView: View { .sheet(isPresented: $isDownloadPresented, content: {VideoDownloadView(bvid: videoDetails["BV"]!, videoDetails: videoDetails)}) Button(action: { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] AF.request("https://api.bilibili.com/x/v2/history/toview/add", method: .post, parameters: ["bvid": videoDetails["BV"]!, "csrf": biliJct], headers: headers).response { response in do { @@ -640,7 +646,8 @@ struct VideoDetailView: View { HStack { Button(action: { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] AF.request("https://api.bilibili.com/x/web-interface/archive/like", method: .post, parameters: BiliVideoLike(bvid: videoDetails["BV"]!, like: isLiked ? 2 : 1, csrf: biliJct), headers: headers).response { response in debugPrint(response) @@ -682,7 +689,8 @@ struct VideoDetailView: View { Button(action: { let headers: HTTPHeaders = [ "cookie": "SESSDATA=\(sessdata)", - "referer": "bilibili.com/video/\(videoDetails["BV"]!)" + "referer": "bilibili.com/video/\(videoDetails["BV"]!)", + "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" ] let avid = bv2av(bvid: videoDetails["BV"]!) AF.request("https://api.bilibili.com/medialist/gateway/coll/resource/deal", method: .post, parameters: BiliVideoFavourite(rid: avid, csrf: biliJct), headers: headers).response { response in @@ -818,7 +826,8 @@ struct VideoDetailView: View { if videoGetterSource == "official" { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] let cid = videoPages[i]["CID"]! VideoDetailView.willPlayVideoCID = cid @@ -884,7 +893,8 @@ struct VideoThrowCoinView: View { } Button(action: { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] AF.request("https://api.bilibili.com/x/web-interface/coin/add", method: .post, parameters: BiliVideoCoin(bvid: bvid, multiply: choseCoin, csrf: biliJct), headers: headers).response { response in debugPrint(response) diff --git a/DarockBili Watch App/Video/VideoDownloadView.swift b/DarockBili Watch App/Video/VideoDownloadView.swift index f921b0ce3..f705bdfa9 100644 --- a/DarockBili Watch App/Video/VideoDownloadView.swift +++ b/DarockBili Watch App/Video/VideoDownloadView.swift @@ -59,7 +59,8 @@ struct VideoDownloadView: View { } .onAppear { let headers: HTTPHeaders = [ - "cookie": "SESSDATA=\(sessdata)" + "cookie": "SESSDATA=\(sessdata)", + "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" ] AF.request("https://api.bilibili.com/x/web-interface/view?bvid=\(bvid)").response { response in let cid = Int((String(data: response.data!, encoding: .utf8)?.components(separatedBy: "\"pages\":[{\"cid\":")[1].components(separatedBy: ",")[0])!)!