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>
99 lines
3.4 KiB
Swift
99 lines
3.4 KiB
Swift
//
|
|
// MagnetChoiceView.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 7/20/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
import ActivityView
|
|
|
|
struct MagnetChoiceView: View {
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
@EnvironmentObject var scrapingModel: ScrapingViewModel
|
|
@EnvironmentObject var debridManager: DebridManager
|
|
|
|
@AppStorage("RealDebrid.Enabled") var realDebridEnabled = false
|
|
|
|
@State private var showActivityView = false
|
|
@State private var activityItem: ActivityItem?
|
|
|
|
var body: some View {
|
|
NavView {
|
|
Form {
|
|
if realDebridEnabled, debridManager.matchSearchResult(result: scrapingModel.selectedSearchResult) != .none {
|
|
Section("Real Debrid options") {
|
|
Button("Play on Outplayer") {
|
|
guard let downloadUrl = URL(string: "outplayer://\(debridManager.realDebridDownloadUrl)") else {
|
|
return
|
|
}
|
|
|
|
UIApplication.shared.open(downloadUrl)
|
|
}
|
|
|
|
Button("Play on VLC") {
|
|
guard let downloadUrl = URL(string: "vlc://\(debridManager.realDebridDownloadUrl)") else {
|
|
return
|
|
}
|
|
|
|
UIApplication.shared.open(downloadUrl)
|
|
}
|
|
|
|
Button("Play on Infuse") {
|
|
guard let downloadUrl = URL(string: "infuse://x-callback-url/play?url=\(debridManager.realDebridDownloadUrl)") else {
|
|
return
|
|
}
|
|
|
|
UIApplication.shared.open(downloadUrl)
|
|
}
|
|
|
|
Button("Copy download URL") {
|
|
UIPasteboard.general.string = debridManager.realDebridDownloadUrl
|
|
}
|
|
|
|
Button("Share download URL") {
|
|
guard let url = URL(string: debridManager.realDebridDownloadUrl) else {
|
|
return
|
|
}
|
|
|
|
activityItem = ActivityItem(items: url)
|
|
showActivityView.toggle()
|
|
}
|
|
}
|
|
}
|
|
|
|
Section("Magnet options") {
|
|
Button("Copy magnet") {
|
|
UIPasteboard.general.string = scrapingModel.selectedSearchResult?.magnetLink
|
|
}
|
|
|
|
Button("Share magnet") {
|
|
if let result = scrapingModel.selectedSearchResult, let url = URL(string: result.magnetLink) {
|
|
activityItem = ActivityItem(items: url)
|
|
showActivityView.toggle()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.activitySheet($activityItem)
|
|
.navigationTitle("Link actions")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
Button("Done") {
|
|
debridManager.realDebridDownloadUrl = ""
|
|
|
|
dismiss()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct MagnetChoiceView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
MagnetChoiceView()
|
|
}
|
|
}
|