Parcourir la source

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

(cherry picked from commit 6f49af0b6ca924a4e24ca7fee9d3c01923178b80)
Felix Paul Kühne il y a 9 ans
Parent
commit
95ad1b17e9
2 fichiers modifiés avec 20 ajouts et 39 suppressions
  1. 5 14
      Sources/VLCDownloadViewController.m
  2. 15 25
      Sources/VLCHTTPFileDownloader.m

+ 5 - 14
Sources/VLCDownloadViewController.m

@@ -114,20 +114,11 @@
     if ([self.urlField.text length] > 0) {
         NSURL *URLtoSave = [NSURL URLWithString:self.urlField.text];
         if (([URLtoSave.scheme isEqualToString:@"http"] || [URLtoSave.scheme isEqualToString:@"https"] || [URLtoSave.scheme isEqualToString:@"ftp"])) {
-            if ([URLtoSave.lastPathComponent isSupportedFormat] || [URLtoSave.lastPathComponent.pathExtension isEqualToString:@""]) {
-                [_currentDownloads addObject:URLtoSave];
-                [_currentDownloadFilename addObject:@""];
-                self.urlField.text = @"";
-                [self.downloadsTable reloadData];
-                [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];
-            }
+            [_currentDownloads addObject:URLtoSave];
+            [_currentDownloadFilename addObject:@""];
+            self.urlField.text = @"";
+            [self.downloadsTable reloadData];
+            [self _triggerNextDownload];
         } else {
             VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"SCHEME_NOT_SUPPORTED", nil)
                                                               message:[NSString stringWithFormat:NSLocalizedString(@"SCHEME_NOT_SUPPORTED_LONG", nil), URLtoSave.scheme]

+ 15 - 25
Sources/VLCHTTPFileDownloader.m

@@ -50,6 +50,11 @@
         _fileName = fileName;
     else
         _fileName = [url.lastPathComponent stringByRemovingPercentEncoding];
+
+    if (_fileName.pathExtension.length == 0 || ![_fileName isSupportedFormat]) {
+        _fileName = [_fileName stringByAppendingPathExtension:@"vlc"];
+    }
+
     _filePath = [basePath stringByAppendingPathComponent:_fileName];
     NSFileManager *fileManager = [NSFileManager defaultManager];
     if (![fileManager fileExistsAtPath:basePath])
@@ -98,34 +103,19 @@
 {
     _statusCode = [response statusCode];
     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]]
+        _expectedDownloadSize = [response expectedContentLength];
+        APLog(@"expected download size: %lli", _expectedDownloadSize);
+        if (_expectedDownloadSize  < [[UIDevice currentDevice] freeDiskspace].longLongValue)
+            [self.delegate downloadStarted];
+        else {
+            [_urlConnection cancel];
+            [self _downloadEnded];
+            VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil)
+                                                             message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _fileName, [[UIDevice currentDevice] model]]
                                                              delegate:self
-                                                    cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
+                                                    cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", 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];
-            APLog(@"expected download size: %lli", _expectedDownloadSize);
-            if (_expectedDownloadSize  < [[UIDevice currentDevice] freeDiskspace].longLongValue)
-                [self.delegate downloadStarted];
-            else {
-                [_urlConnection cancel];
-                [self _downloadEnded];
-                VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil)
-                                                                 message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _fileName, [[UIDevice currentDevice] model]]
-                                                                 delegate:self
-                                                        cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil)
-                                                        otherButtonTitles:nil];
-                [alert show];
-            }
         }
     } else {
         APLog(@"unhandled status code %lu", (unsigned long)_statusCode);