Commit 6f49af0b authored by Felix Paul Kühne's avatar Felix Paul Kühne

downloads: let the user download anything over http and save it in a way it is...

downloads: let the user download anything over http and save it in a way it is displayed in the library (closes #16928)

It's the user's responsibility if it doesn't play
parent ff70ae0d
...@@ -114,20 +114,11 @@ ...@@ -114,20 +114,11 @@
if ([self.urlField.text length] > 0) { if ([self.urlField.text length] > 0) {
NSURL *URLtoSave = [NSURL URLWithString:self.urlField.text]; NSURL *URLtoSave = [NSURL URLWithString:self.urlField.text];
if (([URLtoSave.scheme isEqualToString:@"http"] || [URLtoSave.scheme isEqualToString:@"https"] || [URLtoSave.scheme isEqualToString:@"ftp"])) { if (([URLtoSave.scheme isEqualToString:@"http"] || [URLtoSave.scheme isEqualToString:@"https"] || [URLtoSave.scheme isEqualToString:@"ftp"])) {
if ([URLtoSave.lastPathComponent isSupportedFormat] || [URLtoSave.lastPathComponent.pathExtension isEqualToString:@""]) {
[_currentDownloads addObject:URLtoSave]; [_currentDownloads addObject:URLtoSave];
[_currentDownloadFilename addObject:@""]; [_currentDownloadFilename addObject:@""];
self.urlField.text = @""; self.urlField.text = @"";
[self.downloadsTable reloadData]; [self.downloadsTable reloadData];
[self _triggerNextDownload]; [self _triggerNextDownload];
} else {
VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), URLtoSave.lastPathComponent]
delegate:self
cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
otherButtonTitles:nil];
[alert show];
}
} else { } else {
VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil) VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"SCHEME_NOT_SUPPORTED_LONG", nil), URLtoSave.scheme] message:[NSString stringWithFormat:NSLocalizedString(@"SCHEME_NOT_SUPPORTED_LONG", nil), URLtoSave.scheme]
......
...@@ -50,6 +50,11 @@ ...@@ -50,6 +50,11 @@
_fileName = fileName; _fileName = fileName;
else else
_fileName = [url.lastPathComponent stringByRemovingPercentEncoding]; _fileName = [url.lastPathComponent stringByRemovingPercentEncoding];
if (_fileName.pathExtension.length == 0 || ![_fileName isSupportedFormat]) {
_fileName = [_fileName stringByAppendingPathExtension:@"vlc"];
}
_filePath = [basePath stringByAppendingPathComponent:_fileName]; _filePath = [basePath stringByAppendingPathComponent:_fileName];
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:basePath]) if (![fileManager fileExistsAtPath:basePath])
...@@ -98,20 +103,6 @@ ...@@ -98,20 +103,6 @@
{ {
_statusCode = [response statusCode]; _statusCode = [response statusCode];
if (_statusCode == 200) { if (_statusCode == 200) {
if (![[response suggestedFilename] isSupportedFormat]) {
VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), [response suggestedFilename]]
delegate:self
cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
otherButtonTitles:nil];
[alert show];
[_urlConnection cancel];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:_filePath])
[fileManager removeItemAtPath:_filePath error:nil];
[self _downloadEnded];
} else {
_expectedDownloadSize = [response expectedContentLength]; _expectedDownloadSize = [response expectedContentLength];
APLog(@"expected download size: %lli", _expectedDownloadSize); APLog(@"expected download size: %lli", _expectedDownloadSize);
if (_expectedDownloadSize < [[UIDevice currentDevice] freeDiskspace].longLongValue) if (_expectedDownloadSize < [[UIDevice currentDevice] freeDiskspace].longLongValue)
...@@ -126,7 +117,6 @@ ...@@ -126,7 +117,6 @@
otherButtonTitles:nil]; otherButtonTitles:nil];
[alert show]; [alert show];
} }
}
} else { } else {
APLog(@"unhandled status code %lu", (unsigned long)_statusCode); APLog(@"unhandled status code %lu", (unsigned long)_statusCode);
if ([self.delegate respondsToSelector:@selector(downloadFailedWithErrorDescription:)]) if ([self.delegate respondsToSelector:@selector(downloadFailedWithErrorDescription:)])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment