From abfb633db5f19cd918cea6ba5a70a1e16e0b8e96 Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Thu, 13 Mar 2025 16:08:23 +0100 Subject: [PATCH] works --- Sora/{ => Utils}/DownloadManager/DownloadManager.swift | 9 +++++---- Sora/Views/MediaInfoView/MediaInfoView.swift | 2 +- Sulfur.xcodeproj/project.pbxproj | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) rename Sora/{ => Utils}/DownloadManager/DownloadManager.swift (95%) diff --git a/Sora/DownloadManager/DownloadManager.swift b/Sora/Utils/DownloadManager/DownloadManager.swift similarity index 95% rename from Sora/DownloadManager/DownloadManager.swift rename to Sora/Utils/DownloadManager/DownloadManager.swift index f078bb6..d86e355 100644 --- a/Sora/DownloadManager/DownloadManager.swift +++ b/Sora/Utils/DownloadManager/DownloadManager.swift @@ -38,13 +38,13 @@ class DownloadManager { } } - func downloadAndConvertHLS(from url: URL, title: String, episode: Int, subtitleURL: URL? = nil, sourceName: String, completion: @escaping (Bool, URL?) -> Void) { + func downloadAndConvertHLS(from url: URL, title: String, episode: Int, subtitleURL: URL? = nil, module: ScrapingModule, completion: @escaping (Bool, URL?) -> Void) { guard let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { completion(false, nil) return } - let folderURL = documentsDirectory.appendingPathComponent(title + "-" + sourceName) + let folderURL = documentsDirectory.appendingPathComponent(title + "-" + module.metadata.sourceName) if (!FileManager.default.fileExists(atPath: folderURL.path)) { do { try FileManager.default.createDirectory(at: folderURL, withIntermediateDirectories: true, attributes: nil) @@ -55,7 +55,7 @@ class DownloadManager { } } - let outputFileName = "\(title)_Episode\(episode)_\(sourceName).mp4" + let outputFileName = "\(title)_Episode\(episode)_\(module.metadata.sourceName).mp4" let outputFileURL = folderURL.appendingPathComponent(outputFileName) let fileExtension = url.pathExtension.lowercased() @@ -99,7 +99,7 @@ class DownloadManager { } task.resume() } else if fileExtension == "m3u8" { - let conversionKey = "\(title)_\(episode)_\(sourceName)" + let conversionKey = "\(title)_\(episode)_\(module.metadata.sourceName)" activeConversions[conversionKey] = true if UIApplication.shared.applicationState != .active && backgroundTaskIdentifier == .invalid { @@ -126,6 +126,7 @@ class DownloadManager { ffmpegCommand.append(contentsOf: ["-fflags", "+genpts"]) ffmpegCommand.append(contentsOf: ["-reconnect", "1", "-reconnect_streamed", "1", "-reconnect_delay_max", "5"]) + ffmpegCommand.append(contentsOf: ["-headers", "Referer: \(module.metadata.baseUrl)"]) let multiThreads = UserDefaults.standard.bool(forKey: "multiThreads") if multiThreads { diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index f1d2943..bf948f9 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -497,7 +497,7 @@ struct MediaInfoView: View { } let subtitleFileURL = subtitles != nil ? URL(string: subtitles!) : nil - DownloadManager.shared.downloadAndConvertHLS(from: streamURL, title: title, episode: selectedEpisodeNumber, subtitleURL: subtitleFileURL, sourceName: module.metadata.sourceName) { success, fileURL in + DownloadManager.shared.downloadAndConvertHLS(from: streamURL, title: title, episode: selectedEpisodeNumber, subtitleURL: subtitleFileURL, module: module) { success, fileURL in return } diff --git a/Sulfur.xcodeproj/project.pbxproj b/Sulfur.xcodeproj/project.pbxproj index 6e03a51..0b17dcd 100644 --- a/Sulfur.xcodeproj/project.pbxproj +++ b/Sulfur.xcodeproj/project.pbxproj @@ -234,7 +234,6 @@ 133D7C6C2D2BE2500075467E /* Sora */ = { isa = PBXGroup; children = ( - 13DB7CEA2D7DED50004371D3 /* DownloadManager */, 130C6BF82D53A4C200DC1432 /* Sora.entitlements */, 13DC0C412D2EC9BA00D0F966 /* Info.plist */, 13103E802D589D6C000F0673 /* Tracking Services */, @@ -293,6 +292,7 @@ 133D7C852D2BE2640075467E /* Utils */ = { isa = PBXGroup; children = ( + 13DB7CEA2D7DED50004371D3 /* DownloadManager */, 13C0E5E82D5F85DD00E7F619 /* ContinueWatching */, 13103E8C2D58E037000F0673 /* SkeletonCells */, 13DC0C442D302C6A00D0F966 /* MediaPlayer */,