Skip to content

Commit

Permalink
Fixed duplicated ranking list
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsMEMZ committed Jan 1, 2025
1 parent d3c95a2 commit 2a2e937
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.8">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
10 changes: 4 additions & 6 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -9363,6 +9363,9 @@
}
}
}
},
"全站" : {

},
"关联反馈" : {
"extractionState" : "stale",
Expand Down Expand Up @@ -9851,9 +9854,6 @@
}
}
}
},
"国创" : {

},
"在iPhone上继续" : {
"localizations" : {
Expand Down Expand Up @@ -10288,6 +10288,7 @@
}
},
"手记建议" : {
"extractionState" : "stale",
"localizations" : {
"en" : {
"stringUnit" : {
Expand Down Expand Up @@ -10934,9 +10935,6 @@
}
}
}
},
"番剧" : {

},
"知识" : {

Expand Down
9 changes: 8 additions & 1 deletion MeowBili/InMain/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,18 @@ struct MainView: View {
festivalType = .fools
} else if Date.now.month == 1 && Date.now.day == 24 {
festivalType = .darockc
} else if Date.now.month == 1 && Date.now.day == 1 {
} else if (Date.now.month == 1 && Date.now.day == 1) || todayIsChineseNewYear() {
festivalType = .newyr
} else {
festivalType = .normal
}

func todayIsChineseNewYear() -> Bool {
let today = Date()
let chineseCalendar = Calendar(identifier: .chinese)
let components = chineseCalendar.dateComponents([.month, .day], from: today)
return components.month == 1 && components.day == 1
}
}
#endif
}
Expand Down
84 changes: 42 additions & 42 deletions MeowBili/InMain/RankingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,159 +24,151 @@ struct RankingsView: View {
var body: some View {
List {
Section {
NavigationLink(destination: { RankingCategoryListView(tid: 1) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 0) }, label: {
Label(title: {
Text("动画")
}, icon: {
Image(systemName: "play.square.fill")
.foregroundStyle(.purple)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 13) }, label: {
Label(title: {
Text("番剧")
Text("全站")
}, icon: {
Image(systemName: "tv.fill")
.foregroundStyle(.orange)
Image(systemName: "sparkles.tv.fill")
.foregroundStyle(.accent)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 167) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 1) }, label: {
Label(title: {
Text("国创")
Text("动画")
}, icon: {
Image(systemName: "flag.fill")
.foregroundStyle(.red)
Image(systemName: "play.square.fill")
.foregroundStyle(.purple)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 3) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 3) }, label: {
Label(title: {
Text("音乐")
}, icon: {
Image(systemName: "headphones")
.foregroundStyle(.blue)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 129) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 129) }, label: {
Label(title: {
Text("舞蹈")
}, icon: {
Image(systemName: "figure.barre")
.foregroundStyle(.red)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 4) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 4) }, label: {
Label(title: {
Text("游戏")
}, icon: {
Image(systemName: "gamecontroller.fill")
.foregroundStyle(.green)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 36) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 36) }, label: {
Label(title: {
Text("知识")
}, icon: {
Image(systemName: "lightbulb.fill")
.foregroundStyle(.orange)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 188) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 188) }, label: {
Label(title: {
Text("科技")
}, icon: {
Image(systemName: "camera.fill")
.foregroundStyle(.orange)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 234) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 234) }, label: {
Label(title: {
Text("运动")
}, icon: {
Image(systemName: "figure.run")
.foregroundStyle(.green)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 223) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 223) }, label: {
Label(title: {
Text("汽车")
}, icon: {
Image(systemName: "car.fill")
.foregroundStyle(.blue)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 160) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 160) }, label: {
Label(title: {
Text("生活")
}, icon: {
Image(systemName: "fish.fill")
.foregroundStyle(.yellow)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 211) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 211) }, label: {
Label(title: {
Text("美食")
}, icon: {
Image(systemName: "carrot.fill")
.foregroundStyle(.orange)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 217) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 217) }, label: {
Label(title: {
Text("动物圈")
}, icon: {
Image(systemName: "pawprint.fill")
.foregroundStyle(.pink)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 119) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 119) }, label: {
Label(title: {
Text("鬼畜")
}, icon: {
Image(systemName: "figure.roll")
.foregroundStyle(.blue)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 155) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 155) }, label: {
Label(title: {
Text("时尚")
}, icon: {
Image(systemName: "figure.wave")
.foregroundStyle(.pink)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 5) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 5) }, label: {
Label(title: {
Text("娱乐")
}, icon: {
Image(systemName: "flame.fill")
.foregroundStyle(.orange)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 181) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 181) }, label: {
Label(title: {
Text("影视")
}, icon: {
Image(systemName: "movieclapper.fill")
.foregroundStyle(.blue)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 177) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 177) }, label: {
Label(title: {
Text("纪录片")
}, icon: {
Image(systemName: "camera.shutter.button.fill")
.foregroundStyle(.blue)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 23) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 23) }, label: {
Label(title: {
Text("电影")
}, icon: {
Image(systemName: "sunglasses.fill")
.foregroundStyle(.green)
})
})
NavigationLink(destination: { RankingCategoryListView(tid: 11) }, label: {
NavigationLink(destination: { RankingCategoryListView(rid: 11) }, label: {
Label(title: {
Text("电视剧")
}, icon: {
Expand All @@ -194,7 +186,7 @@ struct RankingsView: View {
}

private struct RankingCategoryListView: View {
var tid: Int
var rid: Int
@AppStorage("DedeUserID") var dedeUserID = ""
@AppStorage("DedeUserID__ckMd5") var dedeUserID__ckMd5 = ""
@AppStorage("SESSDATA") var sessdata = ""
Expand All @@ -214,15 +206,23 @@ private struct RankingCategoryListView: View {
}
.onAppear {
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"
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9",
"cookie": "SESSDATA=\(sessdata); buvid_fp=e651c1a382430ea93631e09474e0b395; buvid3=\(UuidInfoc.gen()); buvid4=buvid4-failed-1",
"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",
"Referer": "https://www.bilibili.com/v/popular/rank"
]
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/web-interface/ranking/v2?tid=\(tid)&type=all", headers: headers) { respJson, isSuccess in
if isSuccess {
if !CheckBApiError(from: respJson) { return }
let data = respJson["data"]["list"]
for videoInfo in data {
videos.append(["Pic": videoInfo.1["pic"].string ?? "E", "Title": videoInfo.1["title"].string ?? "[加载失败]", "BV": videoInfo.1["bvid"].string ?? "E", "UP": videoInfo.1["owner"]["name"].string ?? "[加载失败]", "View": String(videoInfo.1["stat"]["view"].int ?? -1), "Danmaku": String(videoInfo.1["stat"]["danmaku"].int ?? -1)])
biliWbiSign(paramEncoded: "rid=\(rid)&type=all".base64Encoded()) { signed in
if let signed {
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/web-interface/ranking/v2?\(signed)", headers: headers) { respJson, isSuccess in
if isSuccess {
if !CheckBApiError(from: respJson) { return }
let data = respJson["data"]["list"]
for videoInfo in data {
videos.append(["Pic": videoInfo.1["pic"].string ?? "E", "Title": videoInfo.1["title"].string ?? "[加载失败]", "BV": videoInfo.1["bvid"].string ?? "E", "UP": videoInfo.1["owner"]["name"].string ?? "[加载失败]", "View": String(videoInfo.1["stat"]["view"].int ?? -1), "Danmaku": String(videoInfo.1["stat"]["danmaku"].int ?? -1)])
}
}
}
}
}
Expand Down

0 comments on commit 2a2e937

Please sign in to comment.