Batch torrents are torrents that have multiple files bundled within one torrent file. RealDebrid does support these, but it is difficult to get them to work. The main flow requires setting a specific combination in RealDebrid to allow for link generation. However, this is not intuitive to users and is bad API design on RealDebrid's part. Ferrite's implementation presents users with all the possible files from batches (duplicates deleted) and selects the user-chosen file to download. That way, only the user chosen file is presented to play on an external video player. This still needs work for optimization purposes, but this commit does produce a working build. Signed-off-by: kingbri <bdashore3@gmail.com>
61 lines
2 KiB
Swift
61 lines
2 KiB
Swift
//
|
|
// BatchChoiceView.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 7/24/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct BatchChoiceView: View {
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
@EnvironmentObject var debridManager: DebridManager
|
|
@EnvironmentObject var scrapingModel: ScrapingViewModel
|
|
@EnvironmentObject var navigationModel: NavigationViewModel
|
|
|
|
var body: some View {
|
|
NavView {
|
|
List {
|
|
// To present this sheet, an RD item had to be set, this force unwrap is therefore safe
|
|
ForEach(debridManager.selectedRealDebridItem!.files, id: \.self) { file in
|
|
Button(file.name) {
|
|
debridManager.selectedRealDebridFile = file
|
|
|
|
if let searchResult = scrapingModel.selectedSearchResult {
|
|
Task {
|
|
await debridManager.fetchRdDownload(searchResult: searchResult, iaFile: file)
|
|
|
|
// The download may complete before this sheet dismisses
|
|
try? await Task.sleep(seconds: 1)
|
|
navigationModel.currentChoiceSheet = .magnet
|
|
|
|
debridManager.selectedRealDebridFile = nil
|
|
debridManager.selectedRealDebridItem = nil
|
|
}
|
|
}
|
|
|
|
dismiss()
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle("Select a file")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
Button("Done") {
|
|
debridManager.selectedRealDebridItem = nil
|
|
|
|
dismiss()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct BatchChoiceView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
BatchChoiceView()
|
|
}
|
|
}
|