From 2a2e9376bd9a609cca13764390ac5ed44f411ea2 Mon Sep 17 00:00:00 2001 From: WindowsMEMZ Date: Wed, 1 Jan 2025 22:30:25 +0800 Subject: [PATCH] Fixed duplicated ranking list --- .../Alternative Destribution.xcscheme | 2 +- .../xcschemes/MeowWidgetExtension.xcscheme | 1 + Localizable.xcstrings | 10 +-- MeowBili/InMain/MainView.swift | 9 +- MeowBili/InMain/RankingsView.swift | 84 +++++++++---------- 5 files changed, 56 insertions(+), 50 deletions(-) diff --git a/DarockBili.xcodeproj/xcshareddata/xcschemes/Alternative Destribution.xcscheme b/DarockBili.xcodeproj/xcshareddata/xcschemes/Alternative Destribution.xcscheme index 8245c0519..8e551bb00 100644 --- a/DarockBili.xcodeproj/xcshareddata/xcschemes/Alternative Destribution.xcscheme +++ b/DarockBili.xcodeproj/xcshareddata/xcschemes/Alternative Destribution.xcscheme @@ -1,7 +1,7 @@ + version = "1.7"> diff --git a/Localizable.xcstrings b/Localizable.xcstrings index c3859abdf..4e3c94255 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -9363,6 +9363,9 @@ } } } + }, + "全站" : { + }, "关联反馈" : { "extractionState" : "stale", @@ -9851,9 +9854,6 @@ } } } - }, - "国创" : { - }, "在iPhone上继续" : { "localizations" : { @@ -10288,6 +10288,7 @@ } }, "手记建议" : { + "extractionState" : "stale", "localizations" : { "en" : { "stringUnit" : { @@ -10934,9 +10935,6 @@ } } } - }, - "番剧" : { - }, "知识" : { diff --git a/MeowBili/InMain/MainView.swift b/MeowBili/InMain/MainView.swift index ad262fd66..b8a2ed79f 100644 --- a/MeowBili/InMain/MainView.swift +++ b/MeowBili/InMain/MainView.swift @@ -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 } diff --git a/MeowBili/InMain/RankingsView.swift b/MeowBili/InMain/RankingsView.swift index 78accde28..136bc0b89 100644 --- a/MeowBili/InMain/RankingsView.swift +++ b/MeowBili/InMain/RankingsView.swift @@ -24,31 +24,23 @@ 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: { @@ -56,7 +48,7 @@ struct RankingsView: View { .foregroundStyle(.blue) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 129) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 129) }, label: { Label(title: { Text("舞蹈") }, icon: { @@ -64,7 +56,7 @@ struct RankingsView: View { .foregroundStyle(.red) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 4) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 4) }, label: { Label(title: { Text("游戏") }, icon: { @@ -72,7 +64,7 @@ struct RankingsView: View { .foregroundStyle(.green) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 36) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 36) }, label: { Label(title: { Text("知识") }, icon: { @@ -80,7 +72,7 @@ struct RankingsView: View { .foregroundStyle(.orange) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 188) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 188) }, label: { Label(title: { Text("科技") }, icon: { @@ -88,7 +80,7 @@ struct RankingsView: View { .foregroundStyle(.orange) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 234) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 234) }, label: { Label(title: { Text("运动") }, icon: { @@ -96,7 +88,7 @@ struct RankingsView: View { .foregroundStyle(.green) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 223) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 223) }, label: { Label(title: { Text("汽车") }, icon: { @@ -104,7 +96,7 @@ struct RankingsView: View { .foregroundStyle(.blue) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 160) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 160) }, label: { Label(title: { Text("生活") }, icon: { @@ -112,7 +104,7 @@ struct RankingsView: View { .foregroundStyle(.yellow) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 211) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 211) }, label: { Label(title: { Text("美食") }, icon: { @@ -120,7 +112,7 @@ struct RankingsView: View { .foregroundStyle(.orange) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 217) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 217) }, label: { Label(title: { Text("动物圈") }, icon: { @@ -128,7 +120,7 @@ struct RankingsView: View { .foregroundStyle(.pink) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 119) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 119) }, label: { Label(title: { Text("鬼畜") }, icon: { @@ -136,7 +128,7 @@ struct RankingsView: View { .foregroundStyle(.blue) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 155) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 155) }, label: { Label(title: { Text("时尚") }, icon: { @@ -144,7 +136,7 @@ struct RankingsView: View { .foregroundStyle(.pink) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 5) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 5) }, label: { Label(title: { Text("娱乐") }, icon: { @@ -152,7 +144,7 @@ struct RankingsView: View { .foregroundStyle(.orange) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 181) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 181) }, label: { Label(title: { Text("影视") }, icon: { @@ -160,7 +152,7 @@ struct RankingsView: View { .foregroundStyle(.blue) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 177) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 177) }, label: { Label(title: { Text("纪录片") }, icon: { @@ -168,7 +160,7 @@ struct RankingsView: View { .foregroundStyle(.blue) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 23) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 23) }, label: { Label(title: { Text("电影") }, icon: { @@ -176,7 +168,7 @@ struct RankingsView: View { .foregroundStyle(.green) }) }) - NavigationLink(destination: { RankingCategoryListView(tid: 11) }, label: { + NavigationLink(destination: { RankingCategoryListView(rid: 11) }, label: { Label(title: { Text("电视剧") }, icon: { @@ -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 = "" @@ -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)]) + } + } } } }