Skip to content

Commit

Permalink
Merge pull request #372 from Darock-Studio/fix/drksgs
Browse files Browse the repository at this point in the history
fix: Darock Suggestion Settings
  • Loading branch information
Mark Chan authored Jun 28, 2024
2 parents 4566495 + 52c98f5 commit ee401d2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 78 deletions.
24 changes: 12 additions & 12 deletions DarockBili.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_TEAM = B57D8PP775;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SafariExtension/Info.plist;
Expand Down Expand Up @@ -1245,7 +1245,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_TEAM = B57D8PP775;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SafariExtension/Info.plist;
Expand Down Expand Up @@ -1342,7 +1342,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MeowBili/MeowBiliAlternative.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\"";
DEVELOPMENT_TEAM = B38QUJMY47;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1387,7 +1387,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIconWatch;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview\\ Content\"";
DEVELOPMENT_TEAM = B38QUJMY47;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1423,7 +1423,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_TEAM = B57D8PP775;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
Expand All @@ -1447,7 +1447,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_TEAM = B38QUJMY47;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SafariExtension/Info.plist;
Expand Down Expand Up @@ -1515,7 +1515,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MeowBili/MeowBili.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1562,7 +1562,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MeowBili/MeowBili.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1607,7 +1607,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIconWatch;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview\\ Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1643,7 +1643,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIconWatch;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_ASSET_PATHS = "\"MeowBili/Preview\\ Content\"";
DEVELOPMENT_TEAM = B57D8PP775;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1679,7 +1679,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_TEAM = B57D8PP775;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
Expand All @@ -1702,7 +1702,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1261;
CURRENT_PROJECT_VERSION = 1262;
DEVELOPMENT_TEAM = B57D8PP775;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = "zh-Hans"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
allowLocationSimulation = "YES"
notificationPayloadFile = "PushNotificationPayload.apns">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
Expand Down
4 changes: 2 additions & 2 deletions MeowBili/Others/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,12 @@ struct SuggestionViewSettingsView: View {
}

struct NetworkSettingsView: View {
@AppStorage("IsTipDarockSuggestions") var isTipDarockSuggestions = true
@AppStorage("IsShowVideoSuggestionsFromDarock") var isShowVideoSuggestionsFromDarock = true
@AppStorage("IsShowNetworkFixing") var isShowNetworkFixing = true
var body: some View {
List {
Section {
Toggle("显示来自 Darock 的推荐", isOn: $isTipDarockSuggestions)
Toggle("显示来自 Darock 的推荐", isOn: $isShowVideoSuggestionsFromDarock)
}
Section {
NavigationLink(destination: { NetworkFixView() }, label: {
Expand Down
127 changes: 64 additions & 63 deletions MeowBili/Video/VideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -365,80 +365,81 @@ struct VideoPlayerView: View {
@inline(__always)
func UpdateDanmaku() {
AF.request("https://api.bilibili.com/x/v1/dm/list.so?oid=\(videoCID)").response { response in
let danmakus = String(data: response.data!, encoding: .utf8)!
if danmakus.contains("<d p=\"") {
let danmakuOnly = danmakus.split(separator: "</source>")[1].split(separator: "</i>")[0]
let danmakuSpd = danmakuOnly.split(separator: "</d>")
for singleDanmaku in danmakuSpd {
let p = singleDanmaku.split(separator: "<d p=\"")[0].split(separator: "\"")[0]
let spdP = p.split(separator: ",")
var stredSpdP = [String]()
for p in spdP {
stredSpdP.append(String(p))
}
if singleDanmaku.split(separator: "\">").count < 2 {
return
}
let danmakuText = String(singleDanmaku.split(separator: "\">")[1].split(separator: "</d>")[0])
if stredSpdP[5] == "0" {
showDanmakus.append(["Appear": stredSpdP[0], "Type": stredSpdP[1], "Size": stredSpdP[2], "Color": stredSpdP[3], "Text": danmakuText])
}
}
showDanmakus.sort { dict1, dict2 in
if let time1 = dict1["Appear"], let time2 = dict2["Appear"] {
return Double(time1)! < Double(time2)!
}
return false
}
var removedCount = 0
for i in 1..<showDanmakus.count {
if showDanmakus.count - removedCount - i <= 0 {
break
if let danmakus = String(data: response.data!, encoding: .utf8) {
if danmakus.contains("<d p=\"") {
let danmakuOnly = danmakus.split(separator: "</source>")[1].split(separator: "</i>")[0]
let danmakuSpd = danmakuOnly.split(separator: "</d>")
for singleDanmaku in danmakuSpd {
let p = singleDanmaku.split(separator: "<d p=\"")[0].split(separator: "\"")[0]
let spdP = p.split(separator: ",")
var stredSpdP = [String]()
for p in spdP {
stredSpdP.append(String(p))
}
if singleDanmaku.split(separator: "\">").count < 2 {
return
}
let danmakuText = String(singleDanmaku.split(separator: "\">")[1].split(separator: "</d>")[0])
if stredSpdP[5] == "0" {
showDanmakus.append(["Appear": stredSpdP[0], "Type": stredSpdP[1], "Size": stredSpdP[2], "Color": stredSpdP[3], "Text": danmakuText])
}
}
if (Double(showDanmakus[i]["Appear"]!)! - Double(showDanmakus[i - 1]["Appear"]!)!) < 1 {
showDanmakus.remove(at: i)
removedCount++
showDanmakus.sort { dict1, dict2 in
if let time1 = dict1["Appear"], let time2 = dict2["Appear"] {
return Double(time1)! < Double(time2)!
}
return false
}
}
removedCount = 0
var previousTopDanmakuIndex: Int?
var previousBottomDanmakuIndex: Int?
for i in 1..<showDanmakus.count {
if showDanmakus.count - removedCount - i <= 0 {
break
var removedCount = 0
for i in 1..<showDanmakus.count {
if showDanmakus.count - removedCount - i <= 0 {
break
}
if (Double(showDanmakus[i]["Appear"]!)! - Double(showDanmakus[i - 1]["Appear"]!)!) < 1 {
showDanmakus.remove(at: i)
removedCount++
}
}
let type = showDanmakus[i]["Type"]!
if type == "5" || type == "4" {
if let preIndex = type == "5" ? previousTopDanmakuIndex : previousBottomDanmakuIndex {
if Double(showDanmakus[i]["Appear"]!)! - Double(showDanmakus[preIndex]["Appear"]!)! < 10 {
showDanmakus.remove(at: i)
removedCount++
continue
removedCount = 0
var previousTopDanmakuIndex: Int?
var previousBottomDanmakuIndex: Int?
for i in 1..<showDanmakus.count {
if showDanmakus.count - removedCount - i <= 0 {
break
}
let type = showDanmakus[i]["Type"]!
if type == "5" || type == "4" {
if let preIndex = type == "5" ? previousTopDanmakuIndex : previousBottomDanmakuIndex {
if Double(showDanmakus[i]["Appear"]!)! - Double(showDanmakus[preIndex]["Appear"]!)! < 10 {
showDanmakus.remove(at: i)
removedCount++
continue
}
}
{ () -> UnsafeMutablePointer<Int?> in if type == "5" { &&previousTopDanmakuIndex } else { &&previousBottomDanmakuIndex } }().pointee = i
}
{ () -> UnsafeMutablePointer<Int?> in if type == "5" { &&previousTopDanmakuIndex } else { &&previousBottomDanmakuIndex } }().pointee = i
}
}
#if !os(watchOS)
if showDanmakus.count > 500 {
for _ in 1...5000 {
if showDanmakus.count <= 500 {
break
#if !os(watchOS)
if showDanmakus.count > 500 {
for _ in 1...5000 {
if showDanmakus.count <= 500 {
break
}
showDanmakus.remove(at: Int.random(in: 0..<showDanmakus.count))
}
showDanmakus.remove(at: Int.random(in: 0..<showDanmakus.count))
}
}
#else
// Less danmakus for watch
if showDanmakus.count > 200 {
for _ in 1...5000 {
if showDanmakus.count <= 200 {
break
#else
// Less danmakus for watch
if showDanmakus.count > 200 {
for _ in 1...5000 {
if showDanmakus.count <= 200 {
break
}
showDanmakus.remove(at: Int.random(in: 0..<showDanmakus.count))
}
showDanmakus.remove(at: Int.random(in: 0..<showDanmakus.count))
}
#endif
}
#endif
}
}
}
Expand Down

0 comments on commit ee401d2

Please sign in to comment.