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

shared local library: Adding management subtitles

Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 9c077418
<?xml version = "1.0" encoding="UTF-8" standalone="yes" ?>
<MediaContainer size="%%NB_FILE%%" identifier="org.videolan.vlc-ios" libraryTitle="%%LIB_TITLE%%">
<!-- <Media title="" thumb="" duration="" size="" pathfile=""/> -->
<!-- <Media title="" thumb="" duration="" size="" pathfile="" pathSubtitle=""/> -->
%%FILES%%
</MediaContainer>
\ No newline at end of file
......@@ -22,6 +22,7 @@
#import "VLCHTTPUploaderController.h"
#import "HTTPDynamicFileResponse.h"
#import "VLCThumbnailsCache.h"
#import "NSString+SupportedMedia.h"
@interface VLCHTTPConnection()
{
......@@ -36,7 +37,6 @@
@end
@implementation VLCHTTPConnection
- (BOOL)supportsMethod:(NSString *)method atPath:(NSString *)path
......@@ -177,7 +177,7 @@
NSMutableArray *mediaInXml = [[NSMutableArray alloc] initWithCapacity:allMedia.count];
self.uploadController = [[VLCHTTPUploaderController alloc] init];
NSString *hostName = [self.uploadController hostname];
NSString *pathLibrary =[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pathLibrary = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *duration;
for (NSManagedObject *mo in allMedia) {
......@@ -197,9 +197,12 @@
[[(MLFile *)mo url] stringByReplacingOccurrencesOfString:@"file://"withString:@""],
[(MLFile *)mo title],
duration, (float)([(MLFile *)mo fileSizeInBytes] / 1e6)]];
[mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/download/%@/Thumbnails/File/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\"/>",
[(MLFile *)mo title], hostName, pathLibrary, [[NSString stringWithFormat:@"%@", mo.objectID.URIRepresentation] lastPathComponent], duration, [(MLFile *)mo fileSizeInBytes],
hostName, [[(MLFile *)mo url] stringByReplacingOccurrencesOfString:@"file://"withString:@""]]];
if ([relativePath isEqualToString:@"/libMediaVLC.xml"]) {
NSString *pathSub = [self _checkSubtitleFound:[(MLFile *)mo url]];
if (![pathSub isEqualToString:@""])
pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
[mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/download/%@/Thumbnails/File/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", [(MLFile *)mo title], hostName, pathLibrary, [[NSString stringWithFormat:@"%@", mo.objectID.URIRepresentation] lastPathComponent], duration, [(MLFile *)mo fileSizeInBytes], hostName, [[(MLFile *)mo url] stringByReplacingOccurrencesOfString:@"file://"withString:@""], pathSub]];
}
}
else if ([mo isKindOfClass:[MLShow class]]) {
NSArray *episodes = [(MLShow *)mo sortedEpisodes];
......@@ -234,11 +237,12 @@
showEp.episodeNumber,
showEp.name,
duration, (float)([(MLFile *)[[showEp files] anyObject] fileSizeInBytes] / 1e6)]];
[mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@ - S%@E%@\" thumb=\"http://%@/download/%@/Thumbnails/File/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\"/>",
[(MLShow *)mo name], showEp.seasonNumber, showEp.episodeNumber,
hostName, pathLibrary, [[NSString stringWithFormat:@"%@", showEp.objectID.URIRepresentation] lastPathComponent], duration,
[(MLFile *)[[showEp files] anyObject] fileSizeInBytes],
hostName, [[(MLFile *)[[showEp files] anyObject] url] stringByReplacingOccurrencesOfString:@"file://"withString:@""]]];
if ([relativePath isEqualToString:@"/libMediaVLC.xml"]) {
NSString *pathSub = [self _checkSubtitleFound:[(MLFile *)[[showEp files] anyObject] url]];
if (![pathSub isEqualToString:@""])
pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
[mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@ - S%@E%@\" thumb=\"http://%@/download/%@/Thumbnails/File/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", [(MLShow *)mo name], showEp.seasonNumber, showEp.episodeNumber, hostName, pathLibrary, [[NSString stringWithFormat:@"%@", showEp.objectID.URIRepresentation] lastPathComponent], duration, [(MLFile *)[[showEp files] anyObject] fileSizeInBytes], hostName, [[(MLFile *)[[showEp files] anyObject] url] stringByReplacingOccurrencesOfString:@"file://"withString:@""], pathSub]];
}
}
[mediaInHtml addObject:@"</div></div>"];
} else if ([mo isKindOfClass:[MLLabel class]]) {
......@@ -272,9 +276,12 @@
[[file url] stringByReplacingOccurrencesOfString:@"file://"withString:@""],
file.title,
duration, (float)([file fileSizeInBytes] / 1e6)]];
[mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/download/%@/Thumbnails/File/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\"/>",
file.title, hostName, pathLibrary, [[NSString stringWithFormat:@"%@", file.objectID.URIRepresentation] lastPathComponent], duration, [file fileSizeInBytes],
hostName, [[file url] stringByReplacingOccurrencesOfString:@"file://"withString:@""]]];
if ([relativePath isEqualToString:@"/libMediaVLC.xml"]) {
NSString *pathSub = [self _checkSubtitleFound:[file url]];
if (![pathSub isEqualToString:@""])
pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
[mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/download/%@/Thumbnails/File/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", file.title, hostName, pathLibrary, [[NSString stringWithFormat:@"%@", file.objectID.URIRepresentation] lastPathComponent], duration, [file fileSizeInBytes], hostName, [[file url] stringByReplacingOccurrencesOfString:@"file://"withString:@""], pathSub]];
}
}
[mediaInHtml addObject:@"</div></div>"];
} else if ([mo isKindOfClass:[MLAlbum class]]) {
......@@ -308,9 +315,8 @@
[[(MLFile *)[[track files] anyObject] url] stringByReplacingOccurrencesOfString:@"file://"withString:@""],
track.title,
duration, (float)([(MLFile *)[[track files] anyObject] fileSizeInBytes] / 1e6)]];
[mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/download/%@/Thumbnails/File/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\"/>",
track.title, hostName, pathLibrary, [[NSString stringWithFormat:@"%@", track.objectID.URIRepresentation] lastPathComponent], duration, [(MLFile *)[[track files] anyObject] fileSizeInBytes],
hostName, [[(MLFile *)[[track files] anyObject] url] stringByReplacingOccurrencesOfString:@"file://"withString:@""]]];
if ([relativePath isEqualToString:@"/libMediaVLC.xml"])
[mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/download/%@/Thumbnails/File/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"\"/>", track.title, hostName, pathLibrary, [[NSString stringWithFormat:@"%@", track.objectID.URIRepresentation] lastPathComponent], duration, [(MLFile *)[[track files] anyObject] fileSizeInBytes], hostName, [[(MLFile *)[[track files] anyObject] url] stringByReplacingOccurrencesOfString:@"file://"withString:@""]]];
}
[mediaInHtml addObject:@"</div></div>"];
}
......@@ -445,4 +451,35 @@
return [super shouldDie];
}
#pragma mark subtitle
- (NSMutableArray *)_listOfSubtitle
{
NSMutableArray *listOfSubtitle = [[NSMutableArray alloc] init];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSArray *allfiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil];
NSString *filePath;
for (int count = 0; count < allfiles.count; count++) {
filePath = [[NSString stringWithFormat:@"%@/%@", documentsDirectory, allfiles[count]] stringByReplacingOccurrencesOfString:@"file://"withString:@""];
if ([filePath isSupportedSubtitleFormat])
[listOfSubtitle addObject:filePath];
}
return listOfSubtitle;
}
- (NSString *)_checkSubtitleFound:(NSString *)fileURL
{
NSString *subtitlePath = @"";
NSString *fileName = [[fileURL lastPathComponent] stringByDeletingPathExtension];
NSMutableArray *listOfSubtitle = [[NSMutableArray alloc] init];
listOfSubtitle = [self _listOfSubtitle];
NSString *fileSub;
for (int count = 0; count < listOfSubtitle.count; count++) {
fileSub = [NSString stringWithFormat:@"%@", listOfSubtitle[count]];
if ([fileSub rangeOfString:fileName].location != NSNotFound)
subtitlePath = [listOfSubtitle objectAtIndex:count];
}
return subtitlePath;
}
@end
......@@ -223,10 +223,16 @@
else
[ObjList addObjectsFromArray:_mutableObjectList];
NSString *URLofSubtitle = nil;
if (![[[ObjList objectAtIndex:indexPath.row] objectForKey:@"pathSubtitle"] isEqualToString:@""]) {
NSURL *url = [NSURL URLWithString:[[[ObjList objectAtIndex:indexPath.row] objectForKey:@"pathSubtitle"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
URLofSubtitle = [self _getFileSubtitleFromServer:url modeStream:YES];
}
NSURL *itemURL = [NSURL URLWithString:[[ObjList objectAtIndex:indexPath.row] objectForKey:@"pathfile"]];
if (itemURL) {
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate openMovieWithExternalSubtitleFromURL:itemURL externalSubURL:nil];
[appDelegate openMovieWithExternalSubtitleFromURL:itemURL externalSubURL:URLofSubtitle];
}
[tableView deselectRowAtIndexPath:indexPath animated:NO];
......@@ -251,6 +257,27 @@
[self.tableView reloadData];
}
- (NSString *)_getFileSubtitleFromServer:(NSURL *)url modeStream:(BOOL)modeStream
{
NSData *receivedSub = [NSData dataWithContentsOfURL:url];
NSArray *searchPaths = nil;
if (modeStream)
searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
else
searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *directoryPath = [searchPaths objectAtIndex:0];
NSString *FileSubtitlePath = [directoryPath stringByAppendingPathComponent:[[url path] lastPathComponent]];
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];
return FileSubtitlePath;
}
#pragma mark - VLCLocalNetworkListCell delegation
- (void)triggerDownloadForCell:(VLCLocalNetworkListCell *)cell
......@@ -267,6 +294,12 @@
NSInteger size = [[[ObjList objectAtIndex:0] objectForKey:@"size"] integerValue];
if (size < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
NSString *URLofSubtitle = nil;
if (![[[ObjList objectAtIndex:0] objectForKey:@"pathSubtitle"] isEqualToString:@""]) {
NSURL *url = [NSURL URLWithString:[[[ObjList objectAtIndex:0] objectForKey:@"pathSubtitle"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
URLofSubtitle = [self _getFileSubtitleFromServer:url modeStream:NO];
}
[self _downloadFileFromMediaItem:itemURL];
[cell.statusLabel showStatusMessage:NSLocalizedString(@"DOWNLOADING", nil)];
} else {
......
......@@ -73,6 +73,8 @@
[_dicoInfo setObject:[attributeDict objectForKey:@"size"] forKey:@"size"];
if([attributeDict objectForKey:@"pathfile"])
[_dicoInfo setObject:[attributeDict objectForKey:@"pathfile"] forKey:@"pathfile"];
if([attributeDict objectForKey:@"pathSubtitle"])
[_dicoInfo setObject:[attributeDict objectForKey:@"pathSubtitle"] forKey:@"pathSubtitle"];
}
}
......
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