Skip to content

Commit

Permalink
Fix Search Issue (#28)
Browse files Browse the repository at this point in the history
* Update SearchView.swift

* Fast merge main to fix/search (#29)

* Update DarockBili_Watch_App_UI_Tests.swift

* Update ui-test.yml

* Update ui-test.yml

* Update DarockBili_Watch_App_UI_Tests.swift

* Update status-check.yml

* Update DarockBili_Watch_App_UI_Tests.swift

* Update SearchView.swift

* Update DarockBiliApp.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update DarockBili_Watch_App_UI_Tests.swift

* Update SearchView.swift

* Update SearchView.swift

* Update SearchView.swift
  • Loading branch information
WindowsMEMZ authored Dec 15, 2023
1 parent da58437 commit 9dfe0cd
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 31 deletions.
13 changes: 13 additions & 0 deletions DarockBili Watch App UI Tests/DarockBili_Watch_App_UI_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion DarockBili Watch App/DarockBiliApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import SDWebImageSVGCoder
import SDWebImageWebPCoder

//!!!: Debug Setting, Set false Before Release
var debug = false
var debug = true

var pShowTipText = ""
var pShowTipSymbol = ""
Expand Down
81 changes: 51 additions & 30 deletions DarockBili Watch App/InMain/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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("历史记录")) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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: "<em class=\"keyword\">", with: "").replacingOccurrences(of: "</em>", 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: "<em class=\"keyword\">", with: "").replacingOccurrences(of: "</em>", with: ""), "View": String(video.1["play"].int!), "Danmaku": String(video.1["danmaku"].int!), "UP": video.1["author"].string!, "BV": video.1["bvid"].string!])
}
}
}
}
Expand Down

0 comments on commit 9dfe0cd

Please sign in to comment.