Browse Source

Implement subtitles downloading

Felix Paul Kühne 9 years ago
parent
commit
b96da67131

+ 20 - 4
Apple-TV/Playback/Playback Info/VLCPlaybackInfoSubtitlesFetcherViewController.m

@@ -52,8 +52,6 @@
         [defaults synchronize];
     }
     _osoFetcher.subtitleLanguageId = selectedLocale;
-
-
 }
 
 #pragma mark - OSO Fetcher delegation
@@ -80,6 +78,19 @@
     [self.tableView reloadData];
 }
 
+- (void)MDFOSOFetcher:(MDFOSOFetcher *)aFetcher didFailToDownloadForItem:(MDFSubtitleItem *)subtitleItem
+{
+    // FIXME: missing error handling
+    [self dismissViewControllerAnimated:YES completion:nil];
+}
+
+- (void)MDFOSOFetcher:(MDFOSOFetcher *)aFetcher subtitleDownloadSucceededForItem:(MDFSubtitleItem *)subtitleItem atPath:(NSString *)pathToFile
+{
+    VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
+    [vpc.mediaPlayer openVideoSubTitlesFromFile:pathToFile];
+    [self dismissViewControllerAnimated:YES completion:nil];
+}
+
 #pragma mark - table view datasource
 
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@@ -142,8 +153,6 @@
         MDFSubtitleLanguage *item;
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
         NSString *currentCode = [defaults stringForKey:kVLCSettingLastUsedSubtitlesSearchLanguage];
-        if (!currentCode)
-            currentCode = @"eng"; // FIXME
 
         for (NSUInteger i = 0; i < count; i++) {
             NSString *itemID = item.ID;
@@ -166,6 +175,13 @@
                                                           handler:nil]];
 
         [self presentViewController:alertController animated:YES completion:nil];
+    } else {
+        MDFSubtitleItem *item = _searchResults[indexPath.row];
+        NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+        NSString *folderPath = [searchPaths[0] stringByAppendingPathComponent:@"tempsubs"];
+        [[NSFileManager defaultManager] createDirectoryAtPath:folderPath withIntermediateDirectories:YES attributes:nil error:nil];
+        NSString *subStorageLocation = [folderPath stringByAppendingPathComponent:item.name];
+        [_osoFetcher downloadSubtitleItem:item toPath:subStorageLocation];
     }
 }
 

+ 7 - 0
Apple-TV/Playback/VLCFullscreenMovieTVViewController.m

@@ -167,6 +167,13 @@ typedef NS_ENUM(NSInteger, VLCPlayerScanState)
 
     [self stopAudioDescriptionAnimation];
 
+    /* delete potentially downloaded subs */
+    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+    NSString* tempSubsDirPath = [searchPaths[0] stringByAppendingPathComponent:@"tempsubs"];
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    if ([fileManager fileExistsAtPath:tempSubsDirPath])
+        [fileManager removeItemAtPath:tempSubsDirPath error:nil];
+
     [super viewWillDisappear:animated];
 }