Commit ee3a2345 authored by Pierre SAGASPE's avatar Pierre SAGASPE Committed by Felix Paul Kühne

External subtitles over ftp (refs #10668)

Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 1502026b
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
- (void)openMediaFromManagedObject:(NSManagedObject *)file; - (void)openMediaFromManagedObject:(NSManagedObject *)file;
- (void)openMovieFromURL:(NSURL *)url; - (void)openMovieFromURL:(NSURL *)url;
- (void)openMediaList:(VLCMediaList*)list atIndex:(int)index; - (void)openMediaList:(VLCMediaList*)list atIndex:(int)index;
- (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath;
@property (nonatomic, readonly) VLCPlaylistViewController *playlistViewController; @property (nonatomic, readonly) VLCPlaylistViewController *playlistViewController;
@property (nonatomic, readonly) VLCDropboxTableViewController *dropboxTableViewController; @property (nonatomic, readonly) VLCDropboxTableViewController *dropboxTableViewController;
......
...@@ -372,13 +372,27 @@ ...@@ -372,13 +372,27 @@
[self.window.rootViewController presentViewController:navCon animated:YES completion:nil]; [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
} }
- (void)openMediaList:(VLCMediaList*)list atIndex:(int)index - (void)openMediaList:(VLCMediaList *)list atIndex:(int)index
{ {
if (!_movieViewController) if (!_movieViewController)
_movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil]; _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
_movieViewController.mediaList = list; _movieViewController.mediaList = list;
_movieViewController.itemInMediaListToBePlayedFirst = index; _movieViewController.itemInMediaListToBePlayedFirst = index;
_movieViewController.urlExternalSrt = nil;
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_movieViewController];
navCon.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
}
- (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath
{
if (!_movieViewController)
_movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
_movieViewController.url = url;
_movieViewController.urlExternalSrt = SubtitlePath;
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_movieViewController]; UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_movieViewController];
navCon.modalPresentationStyle = UIModalPresentationFullScreen; navCon.modalPresentationStyle = UIModalPresentationFullScreen;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#define kVLCSettingSubtitlesBoldFontDefaulValue @NO #define kVLCSettingSubtitlesBoldFontDefaulValue @NO
#define kVLCSettingSubtitlesFontColor @"quartztext-color" #define kVLCSettingSubtitlesFontColor @"quartztext-color"
#define kVLCSettingSubtitlesFontColorDefaultValue @"16777215" #define kVLCSettingSubtitlesFontColorDefaultValue @"16777215"
#define kVLCSettingSubtitlesFilePath @"sub-file"
#define kVLCSettingDeinterlace @"deinterlace" #define kVLCSettingDeinterlace @"deinterlace"
#define kVLCSettingDeinterlaceDefaultValue @(0) #define kVLCSettingDeinterlaceDefaultValue @(0)
#define kVLCSettingNetworkCaching @"network-caching" #define kVLCSettingNetworkCaching @"network-caching"
...@@ -54,7 +55,7 @@ ...@@ -54,7 +55,7 @@
#define kVLCLastFTPPassword @"last-ftp-pass" #define kVLCLastFTPPassword @"last-ftp-pass"
#define kSupportedFileExtensions @"\\.(3gp|3gp|3gp2|3gpp|amv|asf|avi|axv|divx|dv|flv|f4v|gvi|gxf|m1v|m2p|m2t|m2ts|m2v|m4v|mks|mkv|moov|mov|mp2v|mp4|mpeg|mpeg1|mpeg2|mpeg4|mpg|mpv|mt2s|mts|mxf|mxg|nsv|nuv|oga|ogg|ogm|ogv|ogx|spx|ps|qt|rec|rm|rmvb|tod|ts|tts|vob|vro|webm|wm|wmv|wtv|xesc)$" #define kSupportedFileExtensions @"\\.(3gp|3gp|3gp2|3gpp|amv|asf|avi|axv|divx|dv|flv|f4v|gvi|gxf|m1v|m2p|m2t|m2ts|m2v|m4v|mks|mkv|moov|mov|mp2v|mp4|mpeg|mpeg1|mpeg2|mpeg4|mpg|mpv|mt2s|mts|mxf|mxg|nsv|nuv|oga|ogg|ogm|ogv|ogx|spx|ps|qt|rec|rm|rmvb|tod|ts|tts|vob|vro|webm|wm|wmv|wtv|xesc)$"
#define kSupportedSubtitleFileExtensions @"\\.(cdg|idx|srt|sub|utf|ass|ssa|aqt|jss|psb|rt|smi|txt|smil)$" #define kSupportedSubtitleFileExtensions @"\\.(srt|sub|cdg|idx|utf|ass|ssa|aqt|jss|psb|rt|smi|txt|smil)$"
#define kSupportedAudioFileExtensions @"\\.(aac|aiff|aif|amr|aob|ape|axa|caf|flac|it|m2a|m4a|m4b|mka|mlp|mod|mp1|mp2|mp3|mpa|mpc|mpga|oga|ogg|oma|opus|rmi|s3m|spx|tta|voc|vqf|wav|w64|wma|wv|xa|xm)$" #define kSupportedAudioFileExtensions @"\\.(aac|aiff|aif|amr|aob|ape|axa|caf|flac|it|m2a|m4a|m4b|mka|mlp|mod|mp1|mp2|mp3|mpa|mpc|mpga|oga|ogg|oma|opus|rmi|s3m|spx|tta|voc|vqf|wav|w64|wma|wv|xa|xm)$"
#define kBlobHash @"521923d214b9ae628da7987cf621e94c4afdd726" #define kBlobHash @"521923d214b9ae628da7987cf621e94c4afdd726"
......
...@@ -463,10 +463,58 @@ ...@@ -463,10 +463,58 @@
#pragma mark - communication with playback engine #pragma mark - communication with playback engine
- (void)_streamFTPFile:(NSString *)fileName - (void)_streamFTPFile:(NSString *)fileName
{ {
NSString *URLofSubtitle = nil;
NSMutableArray *SubtitlesList = [[NSMutableArray alloc] init];
[SubtitlesList removeAllObjects];
SubtitlesList = [self _searchSubtitle:fileName];
if(SubtitlesList.count > 0)
URLofSubtitle = [self _getFileSubtitleFromFtpServer:SubtitlesList[0]];
NSURL *URLToPlay = [NSURL URLWithString:[[@"ftp" stringByAppendingFormat:@"://%@%@/%@/%@", [self _credentials], _ftpServerAddress, _ftpServerPath, fileName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSURL *URLToPlay = [NSURL URLWithString:[[@"ftp" stringByAppendingFormat:@"://%@%@/%@/%@", [self _credentials], _ftpServerAddress, _ftpServerPath, fileName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate; VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate openMovieFromURL:URLToPlay]; [appDelegate openMovieWithExternalSubtitleFromURL:URLToPlay externalSubURL:URLofSubtitle];
}
- (NSMutableArray *)_searchSubtitle:(NSString *)url
{
NSString *urlTemp = [[url lastPathComponent] stringByDeletingPathExtension];
NSMutableArray *ObjList = [[NSMutableArray alloc] init];
[ObjList removeAllObjects];
for (int loop = 0; loop < _objectList.count; loop++)
[ObjList addObject:[_objectList[loop] objectForKey:(id)kCFFTPResourceName]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[c] %@", urlTemp];
NSArray *results = [ObjList filteredArrayUsingPredicate:predicate];
[ObjList removeAllObjects];
for (int cnt = 0; cnt < results.count; cnt++) {
if ([results[cnt] isSupportedSubtitleFormat])
[ObjList addObject:results[cnt]];
}
return ObjList;
}
- (NSString *)_getFileSubtitleFromFtpServer:(NSString *)fileName
{
NSURL *url = [NSURL URLWithString:[[@"ftp" stringByAppendingFormat:@"://%@%@/%@/%@", [self _credentials], _ftpServerAddress, _ftpServerPath, fileName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *receivedSub = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *directoryPath = searchPaths[0];
NSString *FileSubtitlePath = [directoryPath stringByAppendingPathComponent:[fileName lastPathComponent]];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:FileSubtitlePath]) {
//create local subtitle file
[fileManager createFileAtPath:FileSubtitlePath contents:nil attributes:nil];
if (![fileManager fileExistsAtPath:FileSubtitlePath])
APLog(@"file creation failed, no data was saved");
}
[receivedSub writeToFile:FileSubtitlePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
return FileSubtitlePath;
} }
#pragma mark - Search Display Controller Delegate #pragma mark - Search Display Controller Delegate
......
...@@ -84,6 +84,7 @@ ...@@ -84,6 +84,7 @@
@property (nonatomic, strong) MLFile *fileFromMediaLibrary; @property (nonatomic, strong) MLFile *fileFromMediaLibrary;
@property (nonatomic, strong) NSURL *url; @property (nonatomic, strong) NSURL *url;
@property (nonatomic, strong) NSString *urlExternalSrt;
@property (nonatomic, retain) VLCMediaList *mediaList; @property (nonatomic, retain) VLCMediaList *mediaList;
@property (nonatomic, readwrite) int itemInMediaListToBePlayedFirst; @property (nonatomic, readwrite) int itemInMediaListToBePlayedFirst;
......
...@@ -407,7 +407,11 @@ ...@@ -407,7 +407,11 @@
return; return;
} }
_listPlayer = [[VLCMediaListPlayer alloc] init]; if (self.urlExternalSrt)
_listPlayer = [[VLCMediaListPlayer alloc] initWithOptions:@[[NSString stringWithFormat:@"--%@=%@", kVLCSettingSubtitlesFilePath, [self urlExternalSrt]]]];
else
_listPlayer = [[VLCMediaListPlayer alloc] init];
_mediaPlayer = _listPlayer.mediaPlayer; _mediaPlayer = _listPlayer.mediaPlayer;
[_mediaPlayer setDelegate:self]; [_mediaPlayer setDelegate:self];
[_mediaPlayer setDrawable:self.movieView]; [_mediaPlayer setDrawable:self.movieView];
...@@ -636,7 +640,12 @@ ...@@ -636,7 +640,12 @@
_mediaList = nil; _mediaList = nil;
if (_url) if (_url)
_url = nil; _url = nil;
if (_urlExternalSrt) {
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:_urlExternalSrt])
[fileManager removeItemAtPath:_urlExternalSrt error:nil];
_urlExternalSrt = nil;
}
_playerIsSetup = NO; _playerIsSetup = NO;
} }
......
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