Commit b8d72040 authored by Felix Paul Kühne's avatar Felix Paul Kühne

network stream: mostly re-write the SPU via http detector (fixes #132)

This adds support for https, works-around an issue in libvlc when using private API to set a subtitle and uses libvlc 3.0's feature to play subtitles via http so they no longer need to be downloaded first
parent 322e8ed4
......@@ -342,30 +342,29 @@ forRowAtIndexPath:(NSIndexPath *)indexPath
#pragma mark - internals
- (void)_openURLStringAndDismiss:(NSString *)url
{
NSURL *URLscheme = [NSURL URLWithString:url];
NSString *URLofSubtitle = nil;
NSURL *playbackURL = [NSURL URLWithString:url];
NSURL *subtitlesURL = nil;
if ([URLscheme.scheme isEqualToString:@"http"] && self.ScanSubToggleSwitch.on) {
URLofSubtitle = [self _checkURLofSubtitle:url];
if (([playbackURL.scheme isEqualToString:@"http"] || [playbackURL.scheme isEqualToString:@"https"]) && self.ScanSubToggleSwitch.on) {
subtitlesURL = [self _checkURLofSubtitle:playbackURL];
}
VLCMedia *media = [VLCMedia mediaWithURL:[NSURL URLWithString:url]];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:media];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:URLofSubtitle];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:subtitlesURL.absoluteString];
}
- (NSString *)_checkURLofSubtitle:(NSString *)url
- (NSURL *)_checkURLofSubtitle:(NSURL *)url
{
NSCharacterSet *characterFilter = [NSCharacterSet characterSetWithCharactersInString:@"\\.():$"];
NSString *subtitleFileExtensions = [[kSupportedSubtitleFileExtensions componentsSeparatedByCharactersInSet:characterFilter] componentsJoinedByString:@""];
NSArray *arraySubtitleFileExtensions = [subtitleFileExtensions componentsSeparatedByString:@"|"];
NSString *urlTemp = [[url stringByDeletingPathExtension] stringByAppendingString:@"."];
NSURL *urlWithoutExtension = [url URLByDeletingPathExtension];
NSUInteger count = arraySubtitleFileExtensions.count;
for (int i = 0; i < count; i++) {
NSString *checkAddress = [urlTemp stringByAppendingString:arraySubtitleFileExtensions[i]];
NSURL *checkURL = [NSURL URLWithString:checkAddress];
NSURL *checkURL = [urlWithoutExtension URLByAppendingPathExtension:arraySubtitleFileExtensions[i]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:checkURL];
request.HTTPMethod = @"HEAD";
......@@ -375,42 +374,13 @@ forRowAtIndexPath:(NSIndexPath *)indexPath
NSInteger httpStatus = [(NSHTTPURLResponse *)response statusCode];
if (httpStatus == 200) {
NSString *fileSubtitlePath = [self _getFileSubtitleFromServer:checkURL];
return fileSubtitlePath;
APLog(@"%s:found matching spu file: %@", __PRETTY_FUNCTION__, checkURL);
return checkURL;
}
}
return nil;
}
- (NSString *)_getFileSubtitleFromServer:(NSURL *)url
{
NSString *fileSubtitlePath = nil;
NSString *fileName = [[url path] lastPathComponent];
NSData *receivedSub = [NSData dataWithContentsOfURL:url];
if (receivedSub.length < [[UIDevice currentDevice] VLCFreeDiskSpace].longLongValue) {
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *directoryPath = [searchPaths objectAtIndex:0];
fileSubtitlePath = [directoryPath stringByAppendingPathComponent:fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:fileSubtitlePath]) {
[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 {
VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), fileName, [[UIDevice currentDevice] model]]
delegate:self
cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil)
otherButtonTitles:nil];
[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO];
}
return fileSubtitlePath;
}
- (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error
{
NSError __block *erreur = NULL;
......
......@@ -192,10 +192,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
_actualVideoOutputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_actualVideoOutputView.autoresizesSubviews = YES;
if (_pathToExternalSubtitlesFile)
_listPlayer = [[VLCMediaListPlayer alloc] initWithOptions:@[[NSString stringWithFormat:@"--%@=%@", kVLCSettingSubtitlesFilePath, _pathToExternalSubtitlesFile]] andDrawable:_actualVideoOutputView];
else
_listPlayer = [[VLCMediaListPlayer alloc] initWithDrawable:_actualVideoOutputView];
_listPlayer = [[VLCMediaListPlayer alloc] initWithDrawable:_actualVideoOutputView];
/* to enable debug logging for the playback library instance, switch the boolean below
* note that the library instance used for playback may not necessarily match the instance
......@@ -210,8 +207,6 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
[_mediaPlayer setDeinterlaceFilter:@"blend"];
else
[_mediaPlayer setDeinterlaceFilter:nil];
if (_pathToExternalSubtitlesFile)
[_mediaPlayer addPlaybackSlave:[NSURL fileURLWithPath:_pathToExternalSubtitlesFile] type:VLCMediaPlaybackSlaveTypeSubtitle enforce:YES];
VLCMedia *media = [_mediaList mediaAtIndex:_itemInMediaListToBePlayedFirst];
[media parseWithOptions:VLCMediaParseLocal];
......@@ -258,6 +253,17 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
[[self remoteControlService] subscribeToRemoteCommands];
if (_pathToExternalSubtitlesFile) {
/* this could be a path or an absolute string - let's see */
NSURL *subtitleURL = [NSURL URLWithString:_pathToExternalSubtitlesFile];
if (!subtitleURL) {
subtitleURL = [NSURL fileURLWithPath:_pathToExternalSubtitlesFile];
}
if (subtitleURL) {
[_mediaPlayer addPlaybackSlave:subtitleURL type:VLCMediaPlaybackSlaveTypeSubtitle enforce:YES];
}
}
_playerIsSetup = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStart object:self];
......@@ -293,12 +299,6 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
}
if (!_sessionWillRestart) {
_mediaList = nil;
if (_pathToExternalSubtitlesFile) {
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:_pathToExternalSubtitlesFile])
[fileManager removeItemAtPath:_pathToExternalSubtitlesFile error:nil];
_pathToExternalSubtitlesFile = nil;
}
}
_playerIsSetup = NO;
[_shuffleStack removeAllObjects];
......
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