Commit 89650cb5 authored by Pierre SAGASPE's avatar Pierre SAGASPE Committed by Carola Nitz

VLCServerBrowsingController: add the subtitle download locally when download...

VLCServerBrowsingController: add the subtitle download locally when download the media and if subtitle URL is not nil

(cherry picked from commit e127aa59)
parent 3b4541b8
......@@ -29,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly, nullable) NSString *filename;
@property (nonatomic, readonly, nullable) NSString *duration;
@property (nonatomic, readonly, nullable) NSString *subtitleType;
@property (nonatomic, readonly, nullable) NSURL *subtitleURL;
@property (nonatomic, readonly, nullable) NSURL *thumbnailURL;
@property (nonatomic, readonly, nullable) NSURL *URLcontainer;
......
......@@ -222,6 +222,9 @@
subtitleURLString = [VLCPlexWebAPI urlAuth:subtitleURLString authentification:auth];
_subtitleURL = subtitleURLString.length ? [NSURL URLWithString:subtitleURLString] : nil;
NSString *subType = dictionary[@"codecSubtitle"];
_subtitleType = subType.length ? subType : nil;
}
return self;
}
......
......@@ -2,7 +2,7 @@
* VLCNetworkServerBrowser-Protocol.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* Copyright (c) 2015-2018 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
......@@ -49,10 +49,11 @@ NS_ASSUME_NONNULL_BEGIN
@optional
@property (nonatomic, readonly, nullable) NSString *filename;
@property (nonatomic, readonly, nullable) NSString *duration;
@property (nonatomic, readonly, nullable) NSString *subtitleType;
@property (nonatomic, readonly, nullable) NSURL *subtitleURL;
@property (nonatomic, readonly, nullable) NSURL *thumbnailURL;
@property (nonatomic, getter=isDownloadable, readonly) BOOL downloadable;
@end
NS_ASSUME_NONNULL_END
\ No newline at end of file
NS_ASSUME_NONNULL_END
/*****************************************************************************
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* Copyright (c) 2015-2018 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
......@@ -270,10 +270,45 @@
NSString *extension = urlExtension.length != 0 ? urlExtension : @"vlc";
filename = [filename stringByAppendingPathExtension:extension];
}
[[VLCDownloadViewController sharedInstance] addURLToDownloadList:item.URL
fileNameOfMedia:filename];
[[VLCDownloadViewController sharedInstance] addURLToDownloadList:item.URL fileNameOfMedia:filename];
if (item.subtitleURL)
[self getFileSubtitleFromServer:item];
}
#endif
- (void)getFileSubtitleFromServer:(id<VLCNetworkServerBrowserItem>)item
{
NSString *filename = nil;
if ([item respondsToSelector:@selector(filename)])
filename = item.filename;
else
filename = item.name;
NSString *FileSubtitlePath = nil;
NSURL *subtitleURL = item.subtitleURL;
NSString *extension = [subtitleURL pathExtension];
if ([extension isEqualToString:@""])
extension = item.subtitleType;
filename = [NSString stringWithFormat:@"%@.%@", [filename stringByDeletingPathExtension], extension];
NSData *receivedSub = [NSData dataWithContentsOfURL:subtitleURL]; // TODO: fix synchronous load
if (receivedSub.length < [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) {
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *directoryPath = searchPaths[0];
FileSubtitlePath = [directoryPath stringByAppendingPathComponent:filename];
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];
} else
APLog(@"Disk full");
}
#endif
@end
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