Debrid: Add Premiumize to InstantAvailability

Also add the requirement to the protocol.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri 2024-06-03 16:15:17 -04:00
parent 37ef64224e
commit f902142fee
3 changed files with 27 additions and 17 deletions

View file

@ -118,6 +118,29 @@ public class Premiumize: OAuthDebridSource {
// MARK: - Instant availability
public func instantAvailability(magnets: [Magnet]) async throws -> [DebridIA] {
var collectedIA: [DebridIA] = []
// Only strip magnets that don't have an associated link for PM
let strippedMagnets: [Magnet] = magnets.compactMap {
if let magnetLink = $0.link {
return Magnet(hash: $0.hash, link: magnetLink)
} else {
return nil
}
}
let availableMagnets = try await divideCacheRequests(magnets: strippedMagnets)
// Split DDL requests into chunks of 10
for chunk in availableMagnets.chunked(into: 10) {
let tempIA = try await divideDDLRequests(magnetChunk: chunk)
collectedIA += tempIA
}
return collectedIA
}
// Function to divide and execute DDL endpoint requests in parallel
// Calls this for 10 requests at a time to not overwhelm API servers
public func divideDDLRequests(magnetChunk: [Magnet]) async throws -> [DebridIA] {

View file

@ -17,6 +17,8 @@ public protocol DebridSource {
func setApiKey(_ key: String) -> Bool
func logout() async
func instantAvailability(magnets: [Magnet]) async throws -> [DebridIA]
// Fetches a download link from a source
// Include the instant availability information with the args
func getDownloadLink(magnet: Magnet, ia: DebridIA?, iaFile: DebridIAFile?) async throws -> String

View file

@ -246,23 +246,8 @@ public class DebridManager: ObservableObject {
if enabledDebrids.contains(.premiumize) {
do {
// Only strip magnets that don't have an associated link for PM
let strippedResultMagnets: [Magnet] = resultMagnets.compactMap {
if let magnetLink = $0.link {
return Magnet(hash: $0.hash, link: magnetLink)
} else {
return nil
}
}
let availableMagnets = try await premiumize.divideCacheRequests(magnets: strippedResultMagnets)
// Split DDL requests into chunks of 10
for chunk in availableMagnets.chunked(into: 10) {
let tempIA = try await premiumize.divideDDLRequests(magnetChunk: chunk)
premiumizeIAValues += tempIA
}
let fetchedPremiumizeIA = try await premiumize.instantAvailability(magnets: sendMagnets)
premiumizeIAValues += fetchedPremiumizeIA
} catch {
await sendDebridError(error, prefix: "Premiumize IA fetch error")
}