Commit 9beee90f authored by Tobias's avatar Tobias Committed by Felix Paul Kühne

MLFile now stores relative path in the path property. the absolut path/url can...

MLFile now stores relative path in the path property. the absolut path/url can be accessed by using the property url which returns an NSURL
parent 5ce76b3d
......@@ -183,7 +183,8 @@
for (NSManagedObject *mo in allMedia) {
if ([mo isKindOfClass:[MLFile class]]) {
duration = [[VLCTime timeWithNumber:[(MLFile *)mo duration]] stringValue];
MLFile *file = (MLFile *)mo;
duration = [[VLCTime timeWithNumber:file.duration] stringValue];
[mediaInHtml addObject:[NSString stringWithFormat:
@"<div style=\"background-image:url('thumbnail/%@.png')\"> \
<a href=\"download/%@\" class=\"inner\"> \
......@@ -194,19 +195,20 @@
</div> \
</a> \
</div>",
mo.objectID.URIRepresentation,
[[(MLFile *)mo url] stringByReplacingOccurrencesOfString:@"file://"withString:@""],
[(MLFile *)mo title],
duration, (float)([(MLFile *)mo fileSizeInBytes] / 1e6)]];
file.objectID.URIRepresentation,
file.url.path,
file.title,
duration, (float)(file.fileSizeInBytes / 1e6)]];
if (shouldReturnLibVLCXML) {
NSString *pathSub = [self _checkIfSubtitleWasFound:[(MLFile *)mo url]];
NSString *pathSub = [self _checkIfSubtitleWasFound:file.path];
if (pathSub)
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]];
[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:@"%@", mo.objectID.URIRepresentation] lastPathComponent], duration, file.fileSizeInBytes, hostName, file.url.path, pathSub]];
}
}
else if ([mo isKindOfClass:[MLShow class]]) {
NSArray *episodes = [(MLShow *)mo sortedEpisodes];
MLShow *show = (MLShow *)mo;
NSArray *episodes = [show sortedEpisodes];
[mediaInHtml addObject:[NSString stringWithFormat:
@"<div style=\"background-image:url('thumbnail/%@.png')\"> \
<a href=\"#\" class=\"inner folder\"> \
......@@ -218,7 +220,7 @@
</a> \
<div class=\"content\">",
mo.objectID.URIRepresentation,
[(MLShow *)mo name],
show.name,
(unsigned long)[episodes count]]];
for (MLShowEpisode *showEp in episodes) {
MLFile *anyFileFromEpisode = (MLFile *)[[showEp files] anyObject];
......@@ -234,21 +236,22 @@
</a> \
</div>",
showEp.objectID.URIRepresentation,
[[anyFileFromEpisode url] stringByReplacingOccurrencesOfString:@"file://"withString:@""],
anyFileFromEpisode.url.path,
showEp.seasonNumber,
showEp.episodeNumber,
showEp.name,
duration, (float)([anyFileFromEpisode fileSizeInBytes] / 1e6)]];
if (shouldReturnLibVLCXML) {
NSString *pathSub = [self _checkIfSubtitleWasFound:[anyFileFromEpisode url]];
NSString *pathSub = [self _checkIfSubtitleWasFound:[anyFileFromEpisode path]];
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, [anyFileFromEpisode fileSizeInBytes], hostName, [[anyFileFromEpisode url] stringByReplacingOccurrencesOfString:@"file://"withString:@""], pathSub]];
[mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@ - S%@E%@\" thumb=\"http://%@/download/%@/Thumbnails/File/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", show.name, showEp.seasonNumber, showEp.episodeNumber, hostName, pathLibrary, [[NSString stringWithFormat:@"%@", showEp.objectID.URIRepresentation] lastPathComponent], duration, [anyFileFromEpisode fileSizeInBytes], hostName, anyFileFromEpisode.url.path, pathSub]];
}
}
[mediaInHtml addObject:@"</div></div>"];
} else if ([mo isKindOfClass:[MLLabel class]]) {
NSArray *folderItems = [(MLLabel *)mo sortedFolderItems];
MLLabel *label = (MLLabel *)mo;
NSArray *folderItems = [label sortedFolderItems];
[mediaInHtml addObject:[NSString stringWithFormat:
@"<div style=\"background-image:url('thumbnail/%@.png')\"> \
<a href=\"#\" class=\"inner folder\"> \
......@@ -259,9 +262,9 @@
</div> \
</a> \
<div class=\"content\">",
mo.objectID.URIRepresentation,
[(MLLabel *)mo name],
(unsigned long)[folderItems count]]];
label.objectID.URIRepresentation,
label.name,
(unsigned long)folderItems.count]];
for (MLFile *file in folderItems) {
duration = [[VLCTime timeWithNumber:[file duration]] stringValue];
[mediaInHtml addObject:[NSString stringWithFormat:
......@@ -275,19 +278,20 @@
</a> \
</div>",
file.objectID.URIRepresentation,
[[file url] stringByReplacingOccurrencesOfString:@"file://"withString:@""],
file.url.path,
file.title,
duration, (float)([file fileSizeInBytes] / 1e6)]];
duration, (float)(file.fileSizeInBytes / 1e6)]];
if (shouldReturnLibVLCXML) {
NSString *pathSub = [self _checkIfSubtitleWasFound:[file url]];
NSString *pathSub = [self _checkIfSubtitleWasFound:file.path];
if (pathSub)
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]];
[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.path, pathSub]];
}
}
[mediaInHtml addObject:@"</div></div>"];
} else if ([mo isKindOfClass:[MLAlbum class]]) {
NSArray *albumTracks = [(MLAlbum *)mo sortedTracks];
MLAlbum *album = (MLAlbum *)mo;
NSArray *albumTracks = [album sortedTracks];
[mediaInHtml addObject:[NSString stringWithFormat:
@"<div style=\"background-image:url('thumbnail/%@.png')\"> \
<a href=\"#\" class=\"inner folder\"> \
......@@ -298,9 +302,9 @@
</div> \
</a> \
<div class=\"content\">",
mo.objectID.URIRepresentation,
[(MLAlbum *)mo name],
(unsigned long)[albumTracks count]]];
album.objectID.URIRepresentation,
album.name,
(unsigned long)albumTracks.count]];
for (MLAlbumTrack *track in albumTracks) {
MLFile *anyFileFromTrack = (MLFile *)[[track files] anyObject];
duration = [[VLCTime timeWithNumber:[anyFileFromTrack duration]] stringValue];
......@@ -315,11 +319,11 @@
</a> \
</div>",
track.objectID.URIRepresentation,
[[anyFileFromTrack url] stringByReplacingOccurrencesOfString:@"file://"withString:@""],
anyFileFromTrack.url.path,
track.title,
duration, (float)([anyFileFromTrack fileSizeInBytes] / 1e6)]];
if (shouldReturnLibVLCXML)
[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, [anyFileFromTrack fileSizeInBytes], hostName, [[anyFileFromTrack url] stringByReplacingOccurrencesOfString:@"file://"withString:@""]]];
[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, [anyFileFromTrack fileSizeInBytes], hostName, anyFileFromTrack.url.path]];
}
[mediaInHtml addObject:@"</div></div>"];
}
......@@ -506,10 +510,10 @@
return listOfSubtitles;
}
- (NSString *)_checkIfSubtitleWasFound:(NSString *)fileURL
- (NSString *)_checkIfSubtitleWasFound:(NSString *)filePath
{
NSString *subtitlePath;
NSString *fileName = [[fileURL lastPathComponent] stringByDeletingPathExtension];
NSString *fileName = [[filePath lastPathComponent] stringByDeletingPathExtension];
NSMutableArray *listOfSubtitles = [self _listOfSubtitles];
NSString *fileSub;
NSUInteger count = listOfSubtitles.count;
......
......@@ -175,9 +175,9 @@
[_mediaPlayer openVideoSubTitlesFromFile:self.pathToExternalSubtitlesFile];
VLCMedia *media;
if (self.fileFromMediaLibrary) {
MLFile *item = self.fileFromMediaLibrary;
media = [VLCMedia mediaWithURL:[NSURL URLWithString:item.url]];
MLFile *item = self.fileFromMediaLibrary;
if (item) {
media = [VLCMedia mediaWithURL:item.url];
media.delegate = self;
} else if (self.mediaList) {
media = [self.mediaList mediaAtIndex:self.itemInMediaListToBePlayedFirst];
......@@ -408,7 +408,7 @@
APLog(@"failed to save current media state - file removed?");
}
} else {
NSArray *files = [MLFile fileForURL:[[_mediaPlayer.media url] absoluteString]];
NSArray *files = [MLFile fileForURL:_mediaPlayer.media.url];
if (files.count > 0) {
MLFile *fileFromList = files.firstObject;
fileFromList.lastPosition = @([_mediaPlayer position]);
......@@ -727,7 +727,7 @@
if (mediaFile) {
return mediaFile;
} else if (self.mediaList) {
NSArray *results = [MLFile fileForURL:_mediaPlayer.media.url.absoluteString];
NSArray *results = [MLFile fileForURL:_mediaPlayer.media.url];
return results.firstObject;
}
......@@ -771,7 +771,7 @@
if (self.fileFromMediaLibrary)
item = self.fileFromMediaLibrary;
else if (self.mediaList) {
NSArray *matches = [MLFile fileForURL:[_mediaPlayer.media.url absoluteString]];
NSArray *matches = [MLFile fileForURL:_mediaPlayer.media.url];
item = matches.firstObject;
}
......
......@@ -436,9 +436,9 @@
trackCount = spuTracks.count;
if (trackCount == 0) {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *folderLocation = [[[NSURL URLWithString:theFile.url] path] stringByDeletingLastPathComponent];
NSString *folderLocation = [theFile.url.path stringByDeletingLastPathComponent];
NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
NSString *fileName = [[[[NSURL URLWithString:theFile.url] path] lastPathComponent] stringByDeletingPathExtension];
NSString *fileName = [theFile.path.lastPathComponent stringByDeletingPathExtension];
NSUInteger count = allfiles.count;
NSString *additionalFilePath;
for (unsigned int x = 0; x < count; x++) {
......
......@@ -424,9 +424,9 @@
trackCount = spuTracks.count;
if (trackCount == 0) {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *folderLocation = [[[NSURL URLWithString:theFile.url] path] stringByDeletingLastPathComponent];
NSString *folderLocation = [theFile.url.path stringByDeletingLastPathComponent];
NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
NSString *fileName = [[[[NSURL URLWithString:theFile.url] path] lastPathComponent] stringByDeletingPathExtension];
NSString *fileName = [theFile.path.lastPathComponent stringByDeletingPathExtension];
NSUInteger count = allfiles.count;
NSString *additionalFilePath;
for (unsigned int x = 0; x < count; x++) {
......
......@@ -380,9 +380,9 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
[self rearrangeFolderTrackNumbersForRemovedItem:mediaObject];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *folderLocation = [[[NSURL URLWithString:mediaObject.url] path] stringByDeletingLastPathComponent];
NSString *folderLocation = [[mediaObject.url path] stringByDeletingLastPathComponent];
NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
NSString *fileName = [[[[NSURL URLWithString:mediaObject.url] path] lastPathComponent] stringByDeletingPathExtension];
NSString *fileName = [mediaObject.path.lastPathComponent stringByDeletingPathExtension];
NSIndexSet *indexSet = [allfiles indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return ([obj rangeOfString:fileName].location != NSNotFound);
}];
......@@ -395,7 +395,7 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
[fileManager removeItemAtPath:[folderLocation stringByAppendingPathComponent:additionalFilePath] error:nil];
currentIndex = [indexSet indexGreaterThanIndex:currentIndex];
}
[fileManager removeItemAtPath:[[NSURL URLWithString:mediaObject.url] path] error:nil];
[fileManager removeItemAtURL:mediaObject.url error:nil];
}
- (void)_displayEmptyLibraryViewIfNeeded
......@@ -664,7 +664,7 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
VLCMedia *media;
for (NSInteger x = count - 1; x > -1; x--) {
file = [(MLAlbumTrack*)_tracks[x] files].anyObject;
media = [VLCMedia mediaWithURL: [NSURL URLWithString:file.url]];
media = [VLCMedia mediaWithURL:file.url];
[media parse];
[_list addMedia:media];
}
......@@ -678,7 +678,7 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
MLFile *file;
for (NSInteger x = count - 1; x > -1; x--) {
file = (MLFile *)_tracks[x];
[_list addMedia:[VLCMedia mediaWithURL:[NSURL URLWithString:file.url]]];
[_list addMedia:[VLCMedia mediaWithURL:file.url]];
}
_mediaToPlayIndex = indexPath.row;
} else {
......@@ -822,7 +822,7 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
MLFile *file;
for (NSInteger x = count - 1; x > -1; x--) {
file = [(MLAlbumTrack*)tracks[x] files].anyObject;
[list addMedia:[VLCMedia mediaWithURL: [NSURL URLWithString:file.url]]];
[list addMedia:[VLCMedia mediaWithURL:file.url]];
}
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate openMediaList:list atIndex:(int)[tracks indexOfObject:selectedObject]];
} else if ([selectedObject isKindOfClass:[MLFile class]] && [((MLFile *)selectedObject).labels count] > 0) {
......@@ -835,7 +835,7 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
MLFile *file;
for (NSInteger x = count - 1; x > -1; x--) {
file = (MLFile *)folderTracks[x];
[list addMedia:[VLCMedia mediaWithURL:[NSURL URLWithString:file.url]]];
[list addMedia:[VLCMedia mediaWithURL:file.url]];
}
[(VLCAppDelegate *)[UIApplication sharedApplication].delegate openMediaList:list atIndex:(int)[folderTracks indexOfObject:selectedObject]];
} else
......@@ -1317,11 +1317,11 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
NSURL *fileURL;
if ([mediaItem isKindOfClass:[MLFile class]])
fileURL = [NSURL URLWithString:[(MLFile *)mediaItem url]];
fileURL = [(MLFile *) mediaItem url];
else if ([mediaItem isKindOfClass:[MLAlbumTrack class]])
fileURL = [NSURL URLWithString:[(MLFile *)[[(MLAlbumTrack *)mediaItem files] anyObject] url]];
fileURL = [(MLFile *) [[(MLAlbumTrack *) mediaItem files] anyObject] url];
else if ([mediaItem isKindOfClass:[MLShowEpisode class]])
fileURL = [NSURL URLWithString:[(MLFile *)[[(MLShowEpisode *)mediaItem files] anyObject] url]];
fileURL = [(MLFile *) [[(MLShowEpisode *) mediaItem files] anyObject] url];
if ([fileURL isFileURL])
[fileURLobjects addObject:fileURL];
......
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