mirror of
https://github.com/cranci1/Sora.git
synced 2026-01-11 20:10:24 +00:00
Fix One Pace (#212)
This commit is contained in:
parent
0dac0566dd
commit
f03f4c0b8a
1 changed files with 25 additions and 16 deletions
|
|
@ -1197,7 +1197,7 @@ extension JSController: AVAssetDownloadDelegate {
|
||||||
let download = activeDownloads[downloadIndex]
|
let download = activeDownloads[downloadIndex]
|
||||||
|
|
||||||
// Move the downloaded file to Application Support directory for persistence
|
// Move the downloaded file to Application Support directory for persistence
|
||||||
guard let persistentURL = moveToApplicationSupportDirectory(from: location, filename: download.title ?? download.originalURL.lastPathComponent) else {
|
guard let persistentURL = moveToApplicationSupportDirectory(from: location, filename: download.title ?? download.originalURL.lastPathComponent, originalURL: download.originalURL) else {
|
||||||
print("Failed to move downloaded file to persistent storage")
|
print("Failed to move downloaded file to persistent storage")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -1245,8 +1245,9 @@ extension JSController: AVAssetDownloadDelegate {
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - location: The original location from the download task
|
/// - location: The original location from the download task
|
||||||
/// - filename: Name to use for the file
|
/// - filename: Name to use for the file
|
||||||
|
/// - originalURL: The original download URL to determine proper file extension
|
||||||
/// - Returns: URL to the new persistent location or nil if move failed
|
/// - Returns: URL to the new persistent location or nil if move failed
|
||||||
private func moveToApplicationSupportDirectory(from location: URL, filename: String) -> URL? {
|
private func moveToApplicationSupportDirectory(from location: URL, filename: String, originalURL: URL) -> URL? {
|
||||||
let fileManager = FileManager.default
|
let fileManager = FileManager.default
|
||||||
|
|
||||||
// Get Application Support directory
|
// Get Application Support directory
|
||||||
|
|
@ -1269,23 +1270,31 @@ extension JSController: AVAssetDownloadDelegate {
|
||||||
let safeFilename = filename.replacingOccurrences(of: "/", with: "-")
|
let safeFilename = filename.replacingOccurrences(of: "/", with: "-")
|
||||||
.replacingOccurrences(of: ":", with: "-")
|
.replacingOccurrences(of: ":", with: "-")
|
||||||
|
|
||||||
// Determine file extension based on the source location
|
// Determine file extension based on the original download URL, not the downloaded file
|
||||||
let fileExtension: String
|
let fileExtension: String
|
||||||
if location.pathExtension.isEmpty {
|
|
||||||
// If no extension from the source, check if it's likely an HLS download (which becomes .movpkg)
|
// Check the original URL to determine if this was an HLS stream or direct MP4
|
||||||
// or preserve original URL extension
|
let originalURLString = originalURL.absoluteString.lowercased()
|
||||||
if safeFilename.contains(".m3u8") || safeFilename.contains("hls") {
|
let originalPathExtension = originalURL.pathExtension.lowercased()
|
||||||
fileExtension = "movpkg"
|
|
||||||
print("Using .movpkg extension for HLS download: \(safeFilename)")
|
if originalURLString.contains(".m3u8") || originalURLString.contains("/hls/") || originalURLString.contains("m3u8") {
|
||||||
} else {
|
// This was an HLS stream, keep as .movpkg
|
||||||
fileExtension = "mp4" // Default for direct video downloads
|
fileExtension = "movpkg"
|
||||||
print("Using .mp4 extension for direct video download: \(safeFilename)")
|
print("Using .movpkg extension for HLS download: \(safeFilename)")
|
||||||
}
|
} else if originalPathExtension == "mp4" || originalURLString.contains(".mp4") || originalURLString.contains("download") {
|
||||||
|
// This was a direct MP4 download, use .mp4 extension regardless of what AVAssetDownloadTask created
|
||||||
|
fileExtension = "mp4"
|
||||||
|
print("Using .mp4 extension for direct MP4 download: \(safeFilename)")
|
||||||
} else {
|
} else {
|
||||||
// Use the extension from the downloaded file
|
// Fallback: check the downloaded file extension
|
||||||
let sourceExtension = location.pathExtension.lowercased()
|
let sourceExtension = location.pathExtension.lowercased()
|
||||||
fileExtension = (sourceExtension == "movpkg") ? "movpkg" : "mp4"
|
if sourceExtension == "movpkg" && originalURLString.contains("m3u8") {
|
||||||
print("Using extension from source file: \(sourceExtension) -> \(fileExtension)")
|
fileExtension = "movpkg"
|
||||||
|
print("Using .movpkg extension for HLS stream: \(safeFilename)")
|
||||||
|
} else {
|
||||||
|
fileExtension = "mp4"
|
||||||
|
print("Using .mp4 extension as fallback: \(safeFilename)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Final destination will be: \(safeFilename)-\(uniqueID).\(fileExtension)")
|
print("Final destination will be: \(safeFilename)-\(uniqueID).\(fileExtension)")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue