فهرست منبع

External subtitles over ftp (refs #10668)

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Pierre SAGASPE 11 سال پیش
والد
کامیت
ee3a23451c

+ 1 - 0
Sources/VLCAppDelegate.h

@@ -38,6 +38,7 @@
 - (void)openMediaFromManagedObject:(NSManagedObject *)file;
 - (void)openMovieFromURL:(NSURL *)url;
 - (void)openMediaList:(VLCMediaList*)list atIndex:(int)index;
+- (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath;
 
 @property (nonatomic, readonly) VLCPlaylistViewController *playlistViewController;
 @property (nonatomic, readonly) VLCDropboxTableViewController *dropboxTableViewController;

+ 15 - 1
Sources/VLCAppDelegate.m

@@ -372,13 +372,27 @@
     [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)
         _movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
 
     _movieViewController.mediaList = list;
     _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];
     navCon.modalPresentationStyle = UIModalPresentationFullScreen;

+ 2 - 1
Sources/VLCConstants.h

@@ -34,6 +34,7 @@
 #define kVLCSettingSubtitlesBoldFontDefaulValue @NO
 #define kVLCSettingSubtitlesFontColor @"quartztext-color"
 #define kVLCSettingSubtitlesFontColorDefaultValue @"16777215"
+#define kVLCSettingSubtitlesFilePath @"sub-file"
 #define kVLCSettingDeinterlace @"deinterlace"
 #define kVLCSettingDeinterlaceDefaultValue @(0)
 #define kVLCSettingNetworkCaching @"network-caching"
@@ -54,7 +55,7 @@
 #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 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 kBlobHash @"521923d214b9ae628da7987cf621e94c4afdd726"

+ 49 - 1
Sources/VLCLocalServerFolderListViewController.m

@@ -463,10 +463,58 @@
 #pragma mark - communication with playback engine
 - (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]];
 
     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

+ 1 - 0
Sources/VLCMovieViewController.h

@@ -84,6 +84,7 @@
 
 @property (nonatomic, strong) MLFile *fileFromMediaLibrary;
 @property (nonatomic, strong) NSURL *url;
+@property (nonatomic, strong) NSString *urlExternalSrt;
 @property (nonatomic, retain) VLCMediaList *mediaList;
 @property (nonatomic, readwrite) int itemInMediaListToBePlayedFirst;
 

+ 11 - 2
Sources/VLCMovieViewController.m

@@ -407,7 +407,11 @@
         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 setDelegate:self];
     [_mediaPlayer setDrawable:self.movieView];
@@ -636,7 +640,12 @@
         _mediaList = nil;
     if (_url)
         _url = nil;
-
+    if (_urlExternalSrt) {
+            NSFileManager *fileManager = [NSFileManager defaultManager];
+            if ([fileManager fileExistsAtPath:_urlExternalSrt])
+                [fileManager removeItemAtPath:_urlExternalSrt error:nil];
+            _urlExternalSrt = nil;
+    }
     _playerIsSetup = NO;
 }