Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xjbeta committed Jul 16, 2024
2 parents 37b6b49 + a182152 commit 9f3e43c
Show file tree
Hide file tree
Showing 34 changed files with 2,209 additions and 2,450 deletions.
82 changes: 26 additions & 56 deletions IINA+.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "e1a2a270e94ff27f6dd19686d853234eb5215f464533d87c0820af5a66b0e602",
"originHash" : "3ee7d1c78fc4d98bd1c9eaf35f9b4a263d0b9b98d97f310ecc74fcc7cf1d66ed",
"pins" : [
{
"identity" : "alamofire",
Expand Down Expand Up @@ -37,24 +37,6 @@
"version" : "1.2.8"
}
},
{
"identity" : "pmkalamofire",
"kind" : "remoteSourceControl",
"location" : "https://github.com/PromiseKit/PMKAlamofire",
"state" : {
"revision" : "e1791b81d309d4b4853127d72473978f86e96ebe",
"version" : "4.0.0"
}
},
{
"identity" : "promisekit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mxcl/PromiseKit",
"state" : {
"revision" : "8a98e31a47854d3180882c8068cc4d9381bf382d",
"version" : "6.22.1"
}
},
{
"identity" : "sdwebimage",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -103,10 +85,10 @@
{
"identity" : "swifter",
"kind" : "remoteSourceControl",
"location" : "https://github.com/httpswift/swifter",
"location" : "https://github.com/xjbeta/swifter",
"state" : {
"revision" : "9483a5d459b45c3ffd059f7b55f9638e268632fd",
"version" : "1.5.0"
"branch" : "dev",
"revision" : "b2b6331a083c5d036324c8449cc57fb17c257c3c"
}
},
{
Expand Down
34 changes: 23 additions & 11 deletions IINA+/Core Data/Bookmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,24 @@ public class Bookmark: NSManagedObject {
}
*/
updating = true
Processes.shared.videoDecoder.liveInfo(url).done(on: .main) {
self.setInfo($0)
}.ensure {
self.updateDate = Date()
self.updating = false
self.save()
}.catch(on: .main) {
let s = "Get live status error: \($0) \n - \(self.url)"
Log(s)
self.liveTitle = self.url
self.state = LiveState.none.raw

Task {
do {
let info = try await Processes.shared.videoDecoder.liveInfo(url)
await setInfo(info)
} catch let error {
await setInfoError(error)
}

await MainActor.run {
updateDate = Date()
updating = false
save()
}
}
}

@MainActor
private func setInfo(_ info: LiveInfo) {
liveTitle = info.title
liveName = info.name
Expand All @@ -90,6 +94,14 @@ public class Bookmark: NSManagedObject {
state = LiveState.none.raw
}
}

@MainActor
private func setInfoError(_ error: any Error) {
let s = "Get live status error: \(error) \n - \(url)"
Log(s)
self.liveTitle = url
self.state = LiveState.none.raw
}

private func updateImage() {
image = nil
Expand Down
24 changes: 0 additions & 24 deletions IINA+/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,27 +200,6 @@ class Preferences: NSObject {
}
}

var kuaiShouCookies: String {
get {
return defaults(.kuaiShouCookies) as? String ?? ""
}
set {
defaultsSet(newValue, forKey: .kuaiShouCookies)
}
}

var kuaiShouCookiesDate: Date? {
get {
return defaults(.kuaiShouCookiesDate) as? Date
}
set {
if let v = newValue {
defaultsSet(v, forKey: .kuaiShouCookiesDate)
} else {
prefs.removeObject(forKey: PreferenceKeys.kuaiShouCookiesDate.rawValue)
}
}
}

var customMpvPath: String {
get {
Expand Down Expand Up @@ -277,9 +256,6 @@ enum PreferenceKeys: String {
case bilibiliCodec
case bililiveHevc

case kuaiShouCookies
case kuaiShouCookiesDate

case updateInfo070

case customMpvPath
Expand Down
118 changes: 118 additions & 0 deletions IINA+/Utils/BilibiliDynamicManger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// BilibiliDynamicManger.swift
// IINA+
//
// Created by xjbeta on 2024/7/12.
// Copyright © 2024 xjbeta. All rights reserved.
//

import Cocoa

protocol BilibiliDynamicMangerDelegate {
func bilibiliDynamicStatusChanged(_ isLoading: Bool)

func bilibiliDynamicCardsContains(_ bvid: String) -> Bool

func bilibiliDynamicInitCards(_ cards: [BilibiliCard])
func bilibiliDynamicAppendCards(_ cards: [BilibiliCard])
func bilibiliDynamicInsertCards(_ cards: [BilibiliCard])

func bilibiliDynamicCards() -> [BilibiliCard]
}

actor BilibiliDynamicManger {

private var lock = NSLock()

private var bookmarkLoaderTimer: Date?

let bilibili = Processes.shared.videoDecoder.bilibili

var canLoadMore = true

private var delegate: BilibiliDynamicMangerDelegate?

func setDelegate(_ newDelegate: BilibiliDynamicMangerDelegate) {
delegate = newDelegate
}

func loadBilibiliCards(_ action: BilibiliDynamicAction = .init😅) {
Task {
await withCheckedContinuation { continuation in
lock.lock()
defer { lock.unlock() }
Task {
await loadCards(action)
continuation.resume()
}
}
}
}

private func loadCards(_ action: BilibiliDynamicAction = .init😅) async {
guard canLoadMore, let delegate = delegate else { return }

if let date = bookmarkLoaderTimer,
date.secondsSinceNow < 5 {
Log("ignore load more")
return
}

let uuid = UUID().uuidString
canLoadMore = false

await MainActor.run {
delegate.bilibiliDynamicStatusChanged(true)
}

var dynamicID = -1


let bilibiliCards = delegate.bilibiliDynamicCards()

switch action {
case .history:
dynamicID = bilibiliCards.last?.dynamicId ?? -1
case .new:
dynamicID = bilibiliCards.first?.dynamicId ?? -1
default:
break
}

Log("\(uuid), start, \(dynamicID)")

do {
let uid = try await bilibili.getUid()
let cards = try await bilibili.dynamicList(uid, action, dynamicID)

await MainActor.run {
switch action {
case .init😅:
delegate.bilibiliDynamicInitCards(cards)
case .history:
let appends = cards.filter { card in
!delegate.bilibiliDynamicCardsContains(card.bvid)
}
delegate.bilibiliDynamicAppendCards(appends)
case .new:
let appends = cards.filter { card in
!delegate.bilibiliDynamicCardsContains(card.bvid)
}
if appends.count > 0 {
delegate.bilibiliDynamicInsertCards(appends)
}
}
}
} catch let error {
Log("Get bilibili dynamicList error: \(error)")
}

canLoadMore = true
await MainActor.run {
delegate.bilibiliDynamicStatusChanged(false)
}
bookmarkLoaderTimer = Date()
Log("\(uuid), finish, \(dynamicID)")
}

}
Loading

0 comments on commit 9f3e43c

Please sign in to comment.