YouTube-Video im MP3-Format in iOS Swift herunterladen
Gibt es eine Möglichkeit, .mp3-Links für YouTube-Videos zu erhalten? Ich habe versucht, mehrere Online-Youtube-zu-MP3-Konverter-Sites aufzurufen, aber alles lädt nur die Datei im System herunter und gibt keinen MP3-Link.
Ode
Kann ich auf irgendeine Weise Dateien von einem Link herunterladen? Nehmen wir also an, es gibt einen Link wie www.somesongdownloader.com, der beim Laden dieses Links in die MP3-Datei des Browsers heruntergeladen wird. aber wenn ich versuche, das gleiche von meinem ios-Code herunterzuladen, lädt es gerade die Php-Akte nicht mp3 Akte herunter. unten ist mein Code -
Below-Code funktioniert gut für MP3-Links, die ich für YouTube-Videos nicht bekommen kann, aber dieser Code funktioniert nicht für URLs, die MP3-Dateien zum Herunterladen im Browser bereitstellen -
class func loadFileAsync(url: NSURL, completion:(path:String, error:NSError!) -> Void) {
print("Inside loadFileAsync")
let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
let destinationUrl = documentsUrl.URLByAppendingPathComponent(url.lastPathComponent!)
if NSFileManager().fileExistsAtPath(destinationUrl.path!) {
print("file already exists [\(destinationUrl.path!)]")
completion(path: destinationUrl.path!, error:nil)
} else {
let sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: sessionConfig, delegate: nil, delegateQueue: nil)
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "GET"
let task = session.dataTaskWithRequest(request, completionHandler: { (data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
if (error == nil) {
if let response = response as? NSHTTPURLResponse {
print("response=\(response)")
if response.statusCode == 200 {
if data!.writeToURL(destinationUrl, atomically: true) {
print("file saved [\(destinationUrl.path!)]")
completion(path: destinationUrl.path!, error:error)
} else {
print("error saving file")
let error = NSError(domain:"Error saving file", code:1001, userInfo:nil)
completion(path: destinationUrl.path!, error:error)
}
}
}
}
else {
print("Failure: \(error!.localizedDescription)");
completion(path: destinationUrl.path!, error:error)
}
})
task.resume()
}
}