diff --git a/DarockBili Watch App UI Tests/DarockBili_Watch_App_UI_Tests.swift b/DarockBili Watch App UI Tests/DarockBili_Watch_App_UI_Tests.swift index 92aabff9a..0ee6b5ecc 100644 --- a/DarockBili Watch App UI Tests/DarockBili_Watch_App_UI_Tests.swift +++ b/DarockBili Watch App UI Tests/DarockBili_Watch_App_UI_Tests.swift @@ -51,6 +51,19 @@ final class DarockBili_Watch_App_UI_Tests: XCTestCase { app.navigationBars.buttons.element(boundBy: 0).tap() sleep(1) // Backed to suggestions view + app.navigationBars.buttons["SearchButton"].firstMatch.tap() + sleep(1) + if app.buttons["SearchDebugButton"].exists { + app.buttons["SearchDebugButton"].tap() + sleep(5) + takeScreenshot(of: app, named: "DebugSearch") + print(app.debugDescription) + app.buttons["关闭"].firstMatch.tap() + sleep(1) + } + app.buttons["关闭"].firstMatch.tap() + sleep(1) + // Backed to suggestions view app.otherElements["MainTabView"].swipeLeft() sleep(1) takeScreenshot(of: app, named: "PersonalCenter") diff --git a/DarockBili Watch App/DarockBiliApp.swift b/DarockBili Watch App/DarockBiliApp.swift index af5fdc1ef..0a39971e4 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 = false +var debug = true var pShowTipText = "" var pShowTipSymbol = "" diff --git a/DarockBili Watch App/InMain/SearchView.swift b/DarockBili Watch App/InMain/SearchView.swift index b4305e70d..9ac87a1e0 100644 --- a/DarockBili Watch App/InMain/SearchView.swift +++ b/DarockBili Watch App/InMain/SearchView.swift @@ -39,6 +39,15 @@ struct SearchMainView: View { searchText = "" } .accessibilityIdentifier("SearchInput") + if debug { + Button(action: { + searchText = "Darock" + isSearchPresented = true + }, label: { + Text("Debug Search") + }) + .accessibilityIdentifier("SearchDebugButton") + } } if searchHistory.count != 0 { Section(header: Text("历史记录")) { @@ -68,6 +77,7 @@ struct SearchView: View { @State var users = [[String: Any]]() @State var isUserDetailPresented = [Bool]() @State var isLoaded = false + @State var debugResponse = "" var body: some View { ScrollView { VStack { @@ -112,42 +122,53 @@ struct SearchView: View { ForEach(0...videos.count - 1, id: \.self) { i in VideoCard(videos[i]) } + } else if debugResponse != "" { + Text("似乎在搜索时遇到了一些问题,以下是详细信息") + Text(debugResponse) } } } .onAppear { if !isLoaded { - AF.request("bilibili.com").response { response in - let headers: HTTPHeaders = [ - "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", - "accept-encoding": "gzip, deflate, br", - "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.30 Safari/537.36 Edg/84.0.522.11", - "sec-fetch-dest": "document", - "sec-fetch-mode": "navigate", - "sec-fetch-site": "none", - "sec-fetch-user": "?1", - "upgrade-insecure-requests": "1", - "referer": "https://www.bilibili.com/", - "cookie": "SESSDATA=\(sessdata); bili_jct=\(biliJct); DedeUserID=\(dedeUserID); DedeUserID__ckMd5=\(dedeUserID__ckMd5)" - ] - DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/web-interface/search/all/v2?keyword=\(keyword)", headers: headers) { respJson, isSuccess in - if isSuccess { - debugPrint(respJson) - let userDatas = respJson["data"]["result"][8]["data"] - for user in userDatas { - isUserDetailPresented.append(false) - users.append(["Name": user.1["uname"].string ?? "[加载失败]", "Pic": "https:" + (user.1["upic"].string ?? "E"), "ID": String(user.1["mid"].int ?? -1), "Fans": String(user.1["fans"].int ?? -1), "VideoCount": String(user.1["videos"].int ?? -1), "Videos": { () -> [[String: String]] in - var tVideos = [[String: String]]() - for video in user.1["res"] { - tVideos.append(["Pic": "https:" + (video.1["pic"].string ?? "E"), "Title": video.1["title"].string ?? "[加载失败]", "BV": video.1["bvid"].string ?? "E", "UP": user.1["uname"].string ?? "[加载失败]", "View": video.1["play"].string ?? "-1", "Danmaku": String(video.1["coin"].int ?? -1)]) + debugResponse = "" + DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/frontend/finger/spi") { respJson, isSuccess in + if isSuccess { + let headers: HTTPHeaders = [ + "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", + "accept-encoding": "gzip, deflate, br", + "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.30 Safari/537.36 Edg/84.0.522.11", + "sec-fetch-dest": "document", + "sec-fetch-mode": "navigate", + "sec-fetch-site": "none", + "sec-fetch-user": "?1", + "upgrade-insecure-requests": "1", + "referer": "https://www.bilibili.com/", + "cookie": "SESSDATA=\(sessdata); bili_jct=\(biliJct); DedeUserID=\(dedeUserID); DedeUserID__ckMd5=\(dedeUserID__ckMd5); buvid3=\(respJson["data"]["b_3"].string ?? ""); buvid4=\(respJson["data"]["b_4"].string ?? "")" + ] + biliWbiSign(paramEncoded: "keyword=\(keyword)".base64Encoded()) { signed in + if let signed { + DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/web-interface/wbi/search/all/v2?\(signed)", headers: headers) { respJson, isSuccess in + if isSuccess { + debugPrint(respJson) + let userDatas = respJson["data"]["result"][8]["data"] + for user in userDatas { + isUserDetailPresented.append(false) + users.append(["Name": user.1["uname"].string ?? "[加载失败]", "Pic": "https:" + (user.1["upic"].string ?? "E"), "ID": String(user.1["mid"].int ?? -1), "Fans": String(user.1["fans"].int ?? -1), "VideoCount": String(user.1["videos"].int ?? -1), "Videos": { () -> [[String: String]] in + var tVideos = [[String: String]]() + for video in user.1["res"] { + tVideos.append(["Pic": "https:" + (video.1["pic"].string ?? "E"), "Title": video.1["title"].string ?? "[加载失败]", "BV": video.1["bvid"].string ?? "E", "UP": user.1["uname"].string ?? "[加载失败]", "View": video.1["play"].string ?? "-1", "Danmaku": String(video.1["coin"].int ?? -1)]) + } + return tVideos + }()]) + } + let videoDatas = respJson["data"]["result"][11]["data"] + for video in videoDatas { + videos.append(["Pic": "https:" + video.1["pic"].string!, "Title": video.1["title"].string!.replacingOccurrences(of: "", with: "").replacingOccurrences(of: "", with: ""), "View": String(video.1["play"].int!), "Danmaku": String(video.1["danmaku"].int!), "UP": video.1["author"].string!, "BV": video.1["bvid"].string!]) + } + debugResponse = respJson.debugDescription } - return tVideos - }()]) - } - let videoDatas = respJson["data"]["result"][11]["data"] - for video in videoDatas { - videos.append(["Pic": "https:" + video.1["pic"].string!, "Title": video.1["title"].string!.replacingOccurrences(of: "", with: "").replacingOccurrences(of: "", with: ""), "View": String(video.1["play"].int!), "Danmaku": String(video.1["danmaku"].int!), "UP": video.1["author"].string!, "BV": video.1["bvid"].string!]) + } } } }