Commit b96da671 authored by Felix Paul Kühne's avatar Felix Paul Kühne
Browse files

Implement subtitles downloading

parent 3ff84d71
...@@ -52,8 +52,6 @@ ...@@ -52,8 +52,6 @@
[defaults synchronize]; [defaults synchronize];
} }
_osoFetcher.subtitleLanguageId = selectedLocale; _osoFetcher.subtitleLanguageId = selectedLocale;
} }
#pragma mark - OSO Fetcher delegation #pragma mark - OSO Fetcher delegation
...@@ -80,6 +78,19 @@ ...@@ -80,6 +78,19 @@
[self.tableView reloadData]; [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 #pragma mark - table view datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
...@@ -142,8 +153,6 @@ ...@@ -142,8 +153,6 @@
MDFSubtitleLanguage *item; MDFSubtitleLanguage *item;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *currentCode = [defaults stringForKey:kVLCSettingLastUsedSubtitlesSearchLanguage]; NSString *currentCode = [defaults stringForKey:kVLCSettingLastUsedSubtitlesSearchLanguage];
if (!currentCode)
currentCode = @"eng"; // FIXME
for (NSUInteger i = 0; i < count; i++) { for (NSUInteger i = 0; i < count; i++) {
NSString *itemID = item.ID; NSString *itemID = item.ID;
...@@ -166,6 +175,13 @@ ...@@ -166,6 +175,13 @@
handler:nil]]; handler:nil]];
[self presentViewController:alertController animated:YES completion: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];
} }
} }
......
...@@ -167,6 +167,13 @@ typedef NS_ENUM(NSInteger, VLCPlayerScanState) ...@@ -167,6 +167,13 @@ typedef NS_ENUM(NSInteger, VLCPlayerScanState)
[self stopAudioDescriptionAnimation]; [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]; [super viewWillDisappear:animated];
} }
......
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