mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-19 15:46:17 +00:00
fix: resolve correct filename for auto-captured downloads
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import Foundation
|
||||
|
||||
struct RawMediaFormat: Decodable {
|
||||
let format_id: String?
|
||||
}
|
||||
|
||||
struct MediaMetadata: Decodable {
|
||||
let id: String?
|
||||
let formats: [RawMediaFormat]?
|
||||
}
|
||||
|
||||
let executableURL = URL(fileURLWithPath: "/Users/nima/Documents/Code/Firelink/Sources/Firelink/yt-dlp")
|
||||
let arguments = [
|
||||
"-J",
|
||||
"--no-warnings",
|
||||
"--ignore-no-formats-error",
|
||||
"--no-playlist",
|
||||
"--force-ipv4",
|
||||
"https://www.youtube.com/watch?v=jNQXAC9IVRw"
|
||||
]
|
||||
|
||||
let process = Process()
|
||||
let outputPipe = Pipe()
|
||||
let errorPipe = Pipe()
|
||||
|
||||
process.executableURL = executableURL
|
||||
process.arguments = arguments
|
||||
process.standardOutput = outputPipe
|
||||
process.standardError = errorPipe
|
||||
|
||||
do {
|
||||
try process.run()
|
||||
process.waitUntilExit()
|
||||
|
||||
let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
|
||||
|
||||
if process.terminationStatus == 0 {
|
||||
do {
|
||||
let metadata = try JSONDecoder().decode(MediaMetadata.self, from: outputData)
|
||||
print("Successfully decoded metadata with \(metadata.formats?.count ?? 0) formats")
|
||||
} catch {
|
||||
print("Decoding failed: \(error)")
|
||||
}
|
||||
} else {
|
||||
print("Failed! Exit code: \(process.terminationStatus)")
|
||||
print(String(data: errorPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? "")
|
||||
}
|
||||
} catch {
|
||||
print("Process run threw error: \(error.localizedDescription)")
|
||||
}
|
||||
Reference in New Issue
Block a user