Explorar o código

Filter files displayed by the FTP server browser

Unlike other server browsers, the FTP server browser displays all files that are found in a certain folder, which includes files that cannot be played by VLC like metadata files or subtitles. This commit implements filtering of displayed files so that only playable video and audio files are displayed.

In addition, this commit also fixes a bug where when a server browser implements the subtitleURL property, the VLCServerBrowsingController would not use the URL.

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
(cherry picked from commit 75c033625d2399923a997240ee3f2c0c1ad18fff)
(cherry picked from commit 04305f03bcc5f2bdd5fc95800d7b50928a051220)
Benjamin Adolphi %!s(int64=9) %!d(string=hai) anos
pai
achega
adbeefe07e

+ 2 - 1
SharedSources/ServerBrowsing/FTP/VLCNetworkServerBrowserFTP.h

@@ -24,10 +24,11 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface VLCNetworkServerBrowserItemFTP : NSObject <VLCNetworkServerBrowserItem>
 
-- (instancetype)initWithDictionary:(NSDictionary *)dict baseURL:(NSURL *)baseURL;
+- (instancetype)initWithDictionary:(NSDictionary *)dict baseURL:(NSURL *)baseURL subtitleURL:(NSURL *)subtitleURL;
 
 @property (nonatomic, readwrite) NSArray<id<VLCNetworkServerBrowserItem>> *items;
 @property (nonatomic, getter=isDownloadable, readonly) BOOL downloadable;
+@property (nonatomic, readonly, nullable) NSURL *subtitleURL;
 
 @end
 

+ 16 - 1
SharedSources/ServerBrowsing/FTP/VLCNetworkServerBrowserFTP.m

@@ -12,6 +12,7 @@
 
 #import "VLCNetworkServerBrowserFTP.h"
 #import "WhiteRaccoon.h"
+#import "NSString+SupportedMedia.h"
 
 @interface VLCNetworkServerBrowserFTP () <WRRequestDelegate>
 @property (nonatomic) NSURL *url;
@@ -91,9 +92,22 @@
 
 #pragma mark - white raccoon delegation
 
+- (NSURL*)searchSubtitleForFile:(NSString *)filename inSubtitleList:(NSArray *)subtitleList
+{
+    NSString *filenameNoExt = [[filename lastPathComponent] stringByDeletingPathExtension];
+
+    for (NSString *subtitle in subtitleList) {
+        if ([[[subtitle lastPathComponent] stringByDeletingPathExtension] isEqualToString:filenameNoExt])
+            return [self.url URLByAppendingPathComponent:subtitle];
+    }
+
+    return nil;
+}
+
 - (void)requestCompleted:(WRRequest *)request
 {
     if (request == _FTPListDirRequest) {
+        NSMutableArray *subtitleList = [[NSMutableArray alloc] init];
         NSMutableArray *filteredList = [[NSMutableArray alloc] init];
         NSArray *rawList = [(WRRequestListDirectory*)request filesInfo];
         NSUInteger count = rawList.count;
@@ -151,7 +165,7 @@
 @implementation VLCNetworkServerBrowserItemFTP
 @synthesize name = _name, container = _container, fileSizeBytes = _fileSizeBytes, URL = _URL;
 
-- (instancetype)initWithDictionary:(NSDictionary *)dict baseURL:(NSURL *)baseURL
+- (instancetype)initWithDictionary:(NSDictionary *)dict baseURL:(NSURL *)baseURL subtitleURL:(NSURL *)subtitleURL
 {
     self = [super init];
     if (self) {
@@ -166,6 +180,7 @@
             _container = [dict[(id)kCFFTPResourceType] intValue] == 4;
             _fileSizeBytes = dict[(id)kCFFTPResourceSize];
             _URL = [baseURL URLByAppendingPathComponent:_name];
+            _subtitleURL = subtitleURL;
         }
     }
     return self;

+ 1 - 1
SharedSources/ServerBrowsing/VLCServerBrowsingController.m

@@ -171,7 +171,7 @@
         NSString *URLofSubtitle = nil;
         NSURL *remoteSubtitleURL = nil;
         if ([loopItem respondsToSelector:@selector(subtitleURL)]) {
-            [loopItem subtitleURL];
+            remoteSubtitleURL = [loopItem subtitleURL];
         }
         if (remoteSubtitleURL == nil) {
             NSArray *subtitlesList = [self _searchSubtitle:loopItem.URL.lastPathComponent];