|
@@ -97,312 +97,352 @@
|
|
return [super expectsRequestBodyFromMethod:method atPath:path];
|
|
return [super expectsRequestBodyFromMethod:method atPath:path];
|
|
}
|
|
}
|
|
|
|
|
|
-- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
|
|
|
|
|
|
+- (NSObject<HTTPResponse> *)_httpPOSTresponseUploadJSON
|
|
{
|
|
{
|
|
- if ([method isEqualToString:@"POST"] && [path isEqualToString:@"/upload.json"])
|
|
|
|
- return [[HTTPDataResponse alloc] initWithData:[@"\"OK\"" dataUsingEncoding:NSUTF8StringEncoding]];
|
|
|
|
|
|
+ return [[HTTPDataResponse alloc] initWithData:[@"\"OK\"" dataUsingEncoding:NSUTF8StringEncoding]];
|
|
|
|
+}
|
|
|
|
|
|
#if TARGET_OS_IOS
|
|
#if TARGET_OS_IOS
|
|
- if ([path hasPrefix:@"/download/"]) {
|
|
|
|
- NSString *filePath = [[path stringByReplacingOccurrencesOfString:@"/download/" withString:@""]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
- HTTPFileResponse *fileResponse = [[HTTPFileResponse alloc] initWithFilePath:filePath forConnection:self];
|
|
|
|
- fileResponse.contentType = @"application/octet-stream";
|
|
|
|
- return fileResponse;
|
|
|
|
- }
|
|
|
|
- if ([path hasPrefix:@"/thumbnail"]) {
|
|
|
|
- NSString *filePath = [[path stringByReplacingOccurrencesOfString:@"/thumbnail/" withString:@""]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
- filePath = [filePath stringByReplacingOccurrencesOfString:@".png" withString:@""];
|
|
|
|
-
|
|
|
|
- NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
|
|
|
|
- if (moc) {
|
|
|
|
- NSPersistentStoreCoordinator *psc = [moc persistentStoreCoordinator];
|
|
|
|
- if (psc) {
|
|
|
|
- NSManagedObject *mo = nil;
|
|
|
|
- @try {
|
|
|
|
- mo = [moc existingObjectWithID:[psc managedObjectIDForURIRepresentation:[NSURL URLWithString:filePath]] error:nil];
|
|
|
|
- }@catch (NSException *exeption) {
|
|
|
|
- // somebody gave us a malformed or stale URIRepresentation
|
|
|
|
- }
|
|
|
|
|
|
+- (NSObject<HTTPResponse> *)_httpGETDownloadForPath:(NSString *)path
|
|
|
|
+{
|
|
|
|
+ NSString *filePath = [[path stringByReplacingOccurrencesOfString:@"/download/" withString:@""]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
+ HTTPFileResponse *fileResponse = [[HTTPFileResponse alloc] initWithFilePath:filePath forConnection:self];
|
|
|
|
+ fileResponse.contentType = @"application/octet-stream";
|
|
|
|
+ return fileResponse;
|
|
|
|
+}
|
|
|
|
|
|
- NSData *theData;
|
|
|
|
- NSString *contentType;
|
|
|
|
-
|
|
|
|
- /* devices category 3 and faster include HW accelerated JPEG encoding
|
|
|
|
- * so we can make our transfers faster by using waaay smaller images */
|
|
|
|
- if ([[UIDevice currentDevice] speedCategory] < 3) {
|
|
|
|
- theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForManagedObject:mo]);
|
|
|
|
- contentType = @"image/png";
|
|
|
|
- } else {
|
|
|
|
- theData = UIImageJPEGRepresentation([VLCThumbnailsCache thumbnailForManagedObject:mo], .9);
|
|
|
|
- contentType = @"image/jpg";
|
|
|
|
- }
|
|
|
|
|
|
+- (NSObject<HTTPResponse> *)_httpGETThumbnailForPath:(NSString *)path
|
|
|
|
+{
|
|
|
|
+ NSString *filePath = [[path stringByReplacingOccurrencesOfString:@"/thumbnail/" withString:@""]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
+ filePath = [filePath stringByReplacingOccurrencesOfString:@".png" withString:@""];
|
|
|
|
+
|
|
|
|
+ NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
|
|
|
|
+ if (moc) {
|
|
|
|
+ NSPersistentStoreCoordinator *psc = [moc persistentStoreCoordinator];
|
|
|
|
+ if (psc) {
|
|
|
|
+ NSManagedObject *mo = nil;
|
|
|
|
+ @try {
|
|
|
|
+ mo = [moc existingObjectWithID:[psc managedObjectIDForURIRepresentation:[NSURL URLWithString:filePath]] error:nil];
|
|
|
|
+ }@catch (NSException *exeption) {
|
|
|
|
+ // somebody gave us a malformed or stale URIRepresentation
|
|
|
|
+ }
|
|
|
|
|
|
- if (theData) {
|
|
|
|
- HTTPDataResponse *dataResponse = [[HTTPDataResponse alloc] initWithData:theData];
|
|
|
|
- dataResponse.contentType = contentType;
|
|
|
|
- return dataResponse;
|
|
|
|
- }
|
|
|
|
|
|
+ NSData *theData;
|
|
|
|
+ NSString *contentType;
|
|
|
|
+
|
|
|
|
+ /* devices category 3 and faster include HW accelerated JPEG encoding
|
|
|
|
+ * so we can make our transfers faster by using waaay smaller images */
|
|
|
|
+ if ([[UIDevice currentDevice] speedCategory] < 3) {
|
|
|
|
+ theData = UIImagePNGRepresentation([VLCThumbnailsCache thumbnailForManagedObject:mo]);
|
|
|
|
+ contentType = @"image/png";
|
|
|
|
+ } else {
|
|
|
|
+ theData = UIImageJPEGRepresentation([VLCThumbnailsCache thumbnailForManagedObject:mo], .9);
|
|
|
|
+ contentType = @"image/jpg";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (theData) {
|
|
|
|
+ HTTPDataResponse *dataResponse = [[HTTPDataResponse alloc] initWithData:theData];
|
|
|
|
+ dataResponse.contentType = contentType;
|
|
|
|
+ return dataResponse;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (NSObject<HTTPResponse> *)_httpGETLibraryForPath:(NSString *)path
|
|
|
|
+{
|
|
NSString *filePath = [self filePathForURI:path];
|
|
NSString *filePath = [self filePathForURI:path];
|
|
NSString *documentRoot = [config documentRoot];
|
|
NSString *documentRoot = [config documentRoot];
|
|
NSString *relativePath = [filePath substringFromIndex:[documentRoot length]];
|
|
NSString *relativePath = [filePath substringFromIndex:[documentRoot length]];
|
|
BOOL shouldReturnLibVLCXML = [relativePath isEqualToString:@"/libMediaVLC.xml"];
|
|
BOOL shouldReturnLibVLCXML = [relativePath isEqualToString:@"/libMediaVLC.xml"];
|
|
|
|
|
|
- if ([relativePath isEqualToString:@"/index.html"] || shouldReturnLibVLCXML) {
|
|
|
|
- NSMutableArray *allMedia = [[NSMutableArray alloc] init];
|
|
|
|
|
|
+ NSMutableArray *allMedia = [[NSMutableArray alloc] init];
|
|
|
|
|
|
- /* add all albums */
|
|
|
|
- NSArray *allAlbums = [MLAlbum allAlbums];
|
|
|
|
- for (MLAlbum *album in allAlbums) {
|
|
|
|
- if (album.name.length > 0 && album.tracks.count > 1)
|
|
|
|
- [allMedia addObject:album];
|
|
|
|
- }
|
|
|
|
|
|
+ /* add all albums */
|
|
|
|
+ NSArray *allAlbums = [MLAlbum allAlbums];
|
|
|
|
+ for (MLAlbum *album in allAlbums) {
|
|
|
|
+ if (album.name.length > 0 && album.tracks.count > 1)
|
|
|
|
+ [allMedia addObject:album];
|
|
|
|
+ }
|
|
|
|
|
|
- /* add all shows */
|
|
|
|
- NSArray *allShows = [MLShow allShows];
|
|
|
|
- for (MLShow *show in allShows) {
|
|
|
|
- if (show.name.length > 0 && show.episodes.count > 1)
|
|
|
|
- [allMedia addObject:show];
|
|
|
|
- }
|
|
|
|
|
|
+ /* add all shows */
|
|
|
|
+ NSArray *allShows = [MLShow allShows];
|
|
|
|
+ for (MLShow *show in allShows) {
|
|
|
|
+ if (show.name.length > 0 && show.episodes.count > 1)
|
|
|
|
+ [allMedia addObject:show];
|
|
|
|
+ }
|
|
|
|
|
|
- /* add all folders*/
|
|
|
|
- NSArray *allFolders = [MLLabel allLabels];
|
|
|
|
- for (MLLabel *folder in allFolders)
|
|
|
|
- [allMedia addObject:folder];
|
|
|
|
|
|
+ /* add all folders*/
|
|
|
|
+ NSArray *allFolders = [MLLabel allLabels];
|
|
|
|
+ for (MLLabel *folder in allFolders)
|
|
|
|
+ [allMedia addObject:folder];
|
|
|
|
|
|
- /* add all remaining files */
|
|
|
|
- NSArray *allFiles = [MLFile allFiles];
|
|
|
|
- for (MLFile *file in allFiles) {
|
|
|
|
- if (file.labels.count > 0) continue;
|
|
|
|
|
|
+ /* add all remaining files */
|
|
|
|
+ NSArray *allFiles = [MLFile allFiles];
|
|
|
|
+ for (MLFile *file in allFiles) {
|
|
|
|
+ if (file.labels.count > 0) continue;
|
|
|
|
|
|
- if (!file.isShowEpisode && !file.isAlbumTrack)
|
|
|
|
|
|
+ if (!file.isShowEpisode && !file.isAlbumTrack)
|
|
|
|
+ [allMedia addObject:file];
|
|
|
|
+ else if (file.isShowEpisode) {
|
|
|
|
+ if (file.showEpisode.show.episodes.count < 2)
|
|
|
|
+ [allMedia addObject:file];
|
|
|
|
+ } else if (file.isAlbumTrack) {
|
|
|
|
+ if (file.albumTrack.album.tracks.count < 2)
|
|
[allMedia addObject:file];
|
|
[allMedia addObject:file];
|
|
- else if (file.isShowEpisode) {
|
|
|
|
- if (file.showEpisode.show.episodes.count < 2)
|
|
|
|
- [allMedia addObject:file];
|
|
|
|
- } else if (file.isAlbumTrack) {
|
|
|
|
- if (file.albumTrack.album.tracks.count < 2)
|
|
|
|
- [allMedia addObject:file];
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- NSUInteger mediaCount = allMedia.count;
|
|
|
|
- NSMutableArray *mediaInHtml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
|
|
|
|
- NSMutableArray *mediaInXml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
|
|
|
|
- NSString *hostName = [[VLCHTTPUploaderController sharedInstance] hostname];
|
|
|
|
- NSString *duration;
|
|
|
|
-
|
|
|
|
- for (NSManagedObject *mo in allMedia) {
|
|
|
|
- if ([mo isKindOfClass:[MLFile class]]) {
|
|
|
|
- MLFile *file = (MLFile *)mo;
|
|
|
|
- duration = [[VLCTime timeWithNumber:file.duration] stringValue];
|
|
|
|
|
|
+ NSUInteger mediaCount = allMedia.count;
|
|
|
|
+ NSMutableArray *mediaInHtml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
|
|
|
|
+ NSMutableArray *mediaInXml = [[NSMutableArray alloc] initWithCapacity:mediaCount];
|
|
|
|
+ NSString *hostName = [[VLCHTTPUploaderController sharedInstance] hostname];
|
|
|
|
+ NSString *duration;
|
|
|
|
+
|
|
|
|
+ for (NSManagedObject *mo in allMedia) {
|
|
|
|
+ if ([mo isKindOfClass:[MLFile class]]) {
|
|
|
|
+ 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\"> \
|
|
|
|
+ <div class=\"down icon\"></div> \
|
|
|
|
+ <div class=\"infos\"> \
|
|
|
|
+ <span class=\"first-line\">%@</span> \
|
|
|
|
+ <span class=\"second-line\">%@ - %0.2f MB</span> \
|
|
|
|
+ </div> \
|
|
|
|
+ </a> \
|
|
|
|
+ </div>",
|
|
|
|
+ file.objectID.URIRepresentation,
|
|
|
|
+ [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
|
|
|
|
+ file.title,
|
|
|
|
+ duration, (float)(file.fileSizeInBytes / 1e6)]];
|
|
|
|
+ if (shouldReturnLibVLCXML) {
|
|
|
|
+ NSString *pathSub = [self _checkIfSubtitleWasFound:file.path];
|
|
|
|
+ if (pathSub)
|
|
|
|
+ pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
|
|
|
|
+ [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", file.title, hostName, file.objectID.URIRepresentation.absoluteString, duration, file.fileSizeInBytes, hostName, [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if ([mo isKindOfClass:[MLShow class]]) {
|
|
|
|
+ MLShow *show = (MLShow *)mo;
|
|
|
|
+ NSArray *episodes = [show sortedEpisodes];
|
|
|
|
+ [mediaInHtml addObject:[NSString stringWithFormat:
|
|
|
|
+ @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
|
|
+ <a href=\"#\" class=\"inner folder\"> \
|
|
|
|
+ <div class=\"open icon\"></div> \
|
|
|
|
+ <div class=\"infos\"> \
|
|
|
|
+ <span class=\"first-line\">%@</span> \
|
|
|
|
+ <span class=\"second-line\">%lu items</span> \
|
|
|
|
+ </div> \
|
|
|
|
+ </a> \
|
|
|
|
+ <div class=\"content\">",
|
|
|
|
+ mo.objectID.URIRepresentation,
|
|
|
|
+ show.name,
|
|
|
|
+ (unsigned long)[episodes count]]];
|
|
|
|
+ for (MLShowEpisode *showEp in episodes) {
|
|
|
|
+ MLFile *anyFileFromEpisode = (MLFile *)[[showEp files] anyObject];
|
|
|
|
+ duration = [[VLCTime timeWithNumber:[anyFileFromEpisode duration]] stringValue];
|
|
[mediaInHtml addObject:[NSString stringWithFormat:
|
|
[mediaInHtml addObject:[NSString stringWithFormat:
|
|
@"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
@"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
<a href=\"download/%@\" class=\"inner\"> \
|
|
<a href=\"download/%@\" class=\"inner\"> \
|
|
<div class=\"down icon\"></div> \
|
|
<div class=\"down icon\"></div> \
|
|
<div class=\"infos\"> \
|
|
<div class=\"infos\"> \
|
|
- <span class=\"first-line\">%@</span> \
|
|
|
|
|
|
+ <span class=\"first-line\">S%@E%@ - %@</span> \
|
|
<span class=\"second-line\">%@ - %0.2f MB</span> \
|
|
<span class=\"second-line\">%@ - %0.2f MB</span> \
|
|
</div> \
|
|
</div> \
|
|
</a> \
|
|
</a> \
|
|
</div>",
|
|
</div>",
|
|
- file.objectID.URIRepresentation,
|
|
|
|
- [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
|
|
|
|
- file.title,
|
|
|
|
- duration, (float)(file.fileSizeInBytes / 1e6)]];
|
|
|
|
|
|
+ showEp.objectID.URIRepresentation,
|
|
|
|
+ [anyFileFromEpisode.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
|
|
|
|
+ showEp.seasonNumber,
|
|
|
|
+ showEp.episodeNumber,
|
|
|
|
+ showEp.name,
|
|
|
|
+ duration, (float)([anyFileFromEpisode fileSizeInBytes] / 1e6)]];
|
|
if (shouldReturnLibVLCXML) {
|
|
if (shouldReturnLibVLCXML) {
|
|
- NSString *pathSub = [self _checkIfSubtitleWasFound:file.path];
|
|
|
|
- if (pathSub)
|
|
|
|
|
|
+ NSString *pathSub = [self _checkIfSubtitleWasFound:[anyFileFromEpisode path]];
|
|
|
|
+ if (![pathSub isEqualToString:@""])
|
|
pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
|
|
pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
|
|
- [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", file.title, hostName, file.objectID.URIRepresentation.absoluteString, duration, file.fileSizeInBytes, hostName, [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
|
|
|
|
|
|
+ [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@ - S%@E%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", show.name, showEp.seasonNumber, showEp.episodeNumber, hostName, showEp.objectID.URIRepresentation, duration, [anyFileFromEpisode fileSizeInBytes], hostName, [anyFileFromEpisode.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else if ([mo isKindOfClass:[MLShow class]]) {
|
|
|
|
- MLShow *show = (MLShow *)mo;
|
|
|
|
- NSArray *episodes = [show sortedEpisodes];
|
|
|
|
|
|
+ [mediaInHtml addObject:@"</div></div>"];
|
|
|
|
+ } else if ([mo isKindOfClass:[MLLabel class]]) {
|
|
|
|
+ MLLabel *label = (MLLabel *)mo;
|
|
|
|
+ NSArray *folderItems = [label sortedFolderItems];
|
|
|
|
+ [mediaInHtml addObject:[NSString stringWithFormat:
|
|
|
|
+ @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
|
|
+ <a href=\"#\" class=\"inner folder\"> \
|
|
|
|
+ <div class=\"open icon\"></div> \
|
|
|
|
+ <div class=\"infos\"> \
|
|
|
|
+ <span class=\"first-line\">%@</span> \
|
|
|
|
+ <span class=\"second-line\">%lu items</span> \
|
|
|
|
+ </div> \
|
|
|
|
+ </a> \
|
|
|
|
+ <div class=\"content\">",
|
|
|
|
+ label.objectID.URIRepresentation,
|
|
|
|
+ label.name,
|
|
|
|
+ (unsigned long)folderItems.count]];
|
|
|
|
+ for (MLFile *file in folderItems) {
|
|
|
|
+ duration = [[VLCTime timeWithNumber:[file duration]] stringValue];
|
|
[mediaInHtml addObject:[NSString stringWithFormat:
|
|
[mediaInHtml addObject:[NSString stringWithFormat:
|
|
@"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
@"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
- <a href=\"#\" class=\"inner folder\"> \
|
|
|
|
- <div class=\"open icon\"></div> \
|
|
|
|
- <div class=\"infos\"> \
|
|
|
|
- <span class=\"first-line\">%@</span> \
|
|
|
|
- <span class=\"second-line\">%lu items</span> \
|
|
|
|
- </div> \
|
|
|
|
- </a> \
|
|
|
|
- <div class=\"content\">",
|
|
|
|
- mo.objectID.URIRepresentation,
|
|
|
|
- show.name,
|
|
|
|
- (unsigned long)[episodes count]]];
|
|
|
|
- for (MLShowEpisode *showEp in episodes) {
|
|
|
|
- MLFile *anyFileFromEpisode = (MLFile *)[[showEp files] anyObject];
|
|
|
|
- duration = [[VLCTime timeWithNumber:[anyFileFromEpisode duration]] stringValue];
|
|
|
|
- [mediaInHtml addObject:[NSString stringWithFormat:
|
|
|
|
- @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
|
|
- <a href=\"download/%@\" class=\"inner\"> \
|
|
|
|
- <div class=\"down icon\"></div> \
|
|
|
|
- <div class=\"infos\"> \
|
|
|
|
- <span class=\"first-line\">S%@E%@ - %@</span> \
|
|
|
|
- <span class=\"second-line\">%@ - %0.2f MB</span> \
|
|
|
|
- </div> \
|
|
|
|
- </a> \
|
|
|
|
- </div>",
|
|
|
|
- showEp.objectID.URIRepresentation,
|
|
|
|
- [anyFileFromEpisode.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
|
|
|
|
- showEp.seasonNumber,
|
|
|
|
- showEp.episodeNumber,
|
|
|
|
- showEp.name,
|
|
|
|
- duration, (float)([anyFileFromEpisode fileSizeInBytes] / 1e6)]];
|
|
|
|
- if (shouldReturnLibVLCXML) {
|
|
|
|
- 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://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", show.name, showEp.seasonNumber, showEp.episodeNumber, hostName, showEp.objectID.URIRepresentation, duration, [anyFileFromEpisode fileSizeInBytes], hostName, [anyFileFromEpisode.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- [mediaInHtml addObject:@"</div></div>"];
|
|
|
|
- } else if ([mo isKindOfClass:[MLLabel class]]) {
|
|
|
|
- MLLabel *label = (MLLabel *)mo;
|
|
|
|
- NSArray *folderItems = [label sortedFolderItems];
|
|
|
|
- [mediaInHtml addObject:[NSString stringWithFormat:
|
|
|
|
- @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
|
|
- <a href=\"#\" class=\"inner folder\"> \
|
|
|
|
- <div class=\"open icon\"></div> \
|
|
|
|
|
|
+ <a href=\"download/%@\" class=\"inner\"> \
|
|
|
|
+ <div class=\"down icon\"></div> \
|
|
<div class=\"infos\"> \
|
|
<div class=\"infos\"> \
|
|
<span class=\"first-line\">%@</span> \
|
|
<span class=\"first-line\">%@</span> \
|
|
- <span class=\"second-line\">%lu items</span> \
|
|
|
|
|
|
+ <span class=\"second-line\">%@ - %0.2f MB</span> \
|
|
</div> \
|
|
</div> \
|
|
</a> \
|
|
</a> \
|
|
- <div class=\"content\">",
|
|
|
|
- label.objectID.URIRepresentation,
|
|
|
|
- label.name,
|
|
|
|
- (unsigned long)folderItems.count]];
|
|
|
|
- for (MLFile *file in folderItems) {
|
|
|
|
- duration = [[VLCTime timeWithNumber:[file duration]] stringValue];
|
|
|
|
- [mediaInHtml addObject:[NSString stringWithFormat:
|
|
|
|
- @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
|
|
- <a href=\"download/%@\" class=\"inner\"> \
|
|
|
|
- <div class=\"down icon\"></div> \
|
|
|
|
- <div class=\"infos\"> \
|
|
|
|
- <span class=\"first-line\">%@</span> \
|
|
|
|
- <span class=\"second-line\">%@ - %0.2f MB</span> \
|
|
|
|
- </div> \
|
|
|
|
- </a> \
|
|
|
|
- </div>",
|
|
|
|
- file.objectID.URIRepresentation,
|
|
|
|
- [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
|
|
|
|
- file.title,
|
|
|
|
- duration, (float)(file.fileSizeInBytes / 1e6)]];
|
|
|
|
- if (shouldReturnLibVLCXML) {
|
|
|
|
- NSString *pathSub = [self _checkIfSubtitleWasFound:file.path];
|
|
|
|
- if (pathSub)
|
|
|
|
- pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
|
|
|
|
- [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", file.title, hostName, file.objectID.URIRepresentation, duration, file.fileSizeInBytes, hostName, [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
|
|
|
|
- }
|
|
|
|
|
|
+ </div>",
|
|
|
|
+ file.objectID.URIRepresentation,
|
|
|
|
+ [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
|
|
|
|
+ file.title,
|
|
|
|
+ duration, (float)(file.fileSizeInBytes / 1e6)]];
|
|
|
|
+ if (shouldReturnLibVLCXML) {
|
|
|
|
+ NSString *pathSub = [self _checkIfSubtitleWasFound:file.path];
|
|
|
|
+ if (pathSub)
|
|
|
|
+ pathSub = [NSString stringWithFormat:@"http://%@/download/%@", hostName, pathSub];
|
|
|
|
+ [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"%@\"/>", file.title, hostName, file.objectID.URIRepresentation, duration, file.fileSizeInBytes, hostName, [file.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pathSub]];
|
|
}
|
|
}
|
|
- [mediaInHtml addObject:@"</div></div>"];
|
|
|
|
- } else if ([mo isKindOfClass:[MLAlbum class]]) {
|
|
|
|
- MLAlbum *album = (MLAlbum *)mo;
|
|
|
|
- NSArray *albumTracks = [album sortedTracks];
|
|
|
|
|
|
+ }
|
|
|
|
+ [mediaInHtml addObject:@"</div></div>"];
|
|
|
|
+ } else if ([mo isKindOfClass:[MLAlbum class]]) {
|
|
|
|
+ MLAlbum *album = (MLAlbum *)mo;
|
|
|
|
+ NSArray *albumTracks = [album sortedTracks];
|
|
|
|
+ [mediaInHtml addObject:[NSString stringWithFormat:
|
|
|
|
+ @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
|
|
+ <a href=\"#\" class=\"inner folder\"> \
|
|
|
|
+ <div class=\"open icon\"></div> \
|
|
|
|
+ <div class=\"infos\"> \
|
|
|
|
+ <span class=\"first-line\">%@</span> \
|
|
|
|
+ <span class=\"second-line\">%lu items</span> \
|
|
|
|
+ </div> \
|
|
|
|
+ </a> \
|
|
|
|
+ <div class=\"content\">",
|
|
|
|
+ album.objectID.URIRepresentation,
|
|
|
|
+ album.name,
|
|
|
|
+ (unsigned long)albumTracks.count]];
|
|
|
|
+ for (MLAlbumTrack *track in albumTracks) {
|
|
|
|
+ MLFile *anyFileFromTrack = [track anyFileFromTrack];
|
|
|
|
+ duration = [[VLCTime timeWithNumber:[anyFileFromTrack duration]] stringValue];
|
|
[mediaInHtml addObject:[NSString stringWithFormat:
|
|
[mediaInHtml addObject:[NSString stringWithFormat:
|
|
@"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
@"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
- <a href=\"#\" class=\"inner folder\"> \
|
|
|
|
- <div class=\"open icon\"></div> \
|
|
|
|
|
|
+ <a href=\"download/%@\" class=\"inner\"> \
|
|
|
|
+ <div class=\"down icon\"></div> \
|
|
<div class=\"infos\"> \
|
|
<div class=\"infos\"> \
|
|
<span class=\"first-line\">%@</span> \
|
|
<span class=\"first-line\">%@</span> \
|
|
- <span class=\"second-line\">%lu items</span> \
|
|
|
|
|
|
+ <span class=\"second-line\">%@ - %0.2f MB</span> \
|
|
</div> \
|
|
</div> \
|
|
</a> \
|
|
</a> \
|
|
- <div class=\"content\">",
|
|
|
|
- album.objectID.URIRepresentation,
|
|
|
|
- album.name,
|
|
|
|
- (unsigned long)albumTracks.count]];
|
|
|
|
- for (MLAlbumTrack *track in albumTracks) {
|
|
|
|
- MLFile *anyFileFromTrack = [track anyFileFromTrack];
|
|
|
|
- duration = [[VLCTime timeWithNumber:[anyFileFromTrack duration]] stringValue];
|
|
|
|
- [mediaInHtml addObject:[NSString stringWithFormat:
|
|
|
|
- @"<div style=\"background-image:url('thumbnail/%@.png')\"> \
|
|
|
|
- <a href=\"download/%@\" class=\"inner\"> \
|
|
|
|
- <div class=\"down icon\"></div> \
|
|
|
|
- <div class=\"infos\"> \
|
|
|
|
- <span class=\"first-line\">%@</span> \
|
|
|
|
- <span class=\"second-line\">%@ - %0.2f MB</span> \
|
|
|
|
- </div> \
|
|
|
|
- </a> \
|
|
|
|
- </div>",
|
|
|
|
- track.objectID.URIRepresentation,
|
|
|
|
- [anyFileFromTrack.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
|
|
|
|
- track.title,
|
|
|
|
- duration, (float)([anyFileFromTrack fileSizeInBytes] / 1e6)]];
|
|
|
|
- if (shouldReturnLibVLCXML)
|
|
|
|
- [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"\"/>", track.title, hostName, track.objectID.URIRepresentation, duration, [anyFileFromTrack fileSizeInBytes], hostName, [anyFileFromTrack.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
|
|
|
|
- }
|
|
|
|
- [mediaInHtml addObject:@"</div></div>"];
|
|
|
|
|
|
+ </div>",
|
|
|
|
+ track.objectID.URIRepresentation,
|
|
|
|
+ [anyFileFromTrack.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
|
|
|
|
+ track.title,
|
|
|
|
+ duration, (float)([anyFileFromTrack fileSizeInBytes] / 1e6)]];
|
|
|
|
+ if (shouldReturnLibVLCXML)
|
|
|
|
+ [mediaInXml addObject:[NSString stringWithFormat:@"<Media title=\"%@\" thumb=\"http://%@/thumbnail/%@.png\" duration=\"%@\" size=\"%li\" pathfile=\"http://%@/download/%@\" pathSubtitle=\"\"/>", track.title, hostName, track.objectID.URIRepresentation, duration, [anyFileFromTrack fileSizeInBytes], hostName, [anyFileFromTrack.url.path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
|
|
}
|
|
}
|
|
|
|
+ [mediaInHtml addObject:@"</div></div>"];
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
- UIDevice *currentDevice = [UIDevice currentDevice];
|
|
|
|
- NSString *deviceModel = [currentDevice model];
|
|
|
|
- NSDictionary *replacementDict;
|
|
|
|
- HTTPDynamicFileResponse *fileResponse;
|
|
|
|
-
|
|
|
|
- if (shouldReturnLibVLCXML) {
|
|
|
|
- replacementDict = @{@"FILES" : [mediaInXml componentsJoinedByString:@" "],
|
|
|
|
- @"NB_FILE" : [NSString stringWithFormat:@"%li", (unsigned long)mediaInXml.count],
|
|
|
|
- @"LIB_TITLE" : [currentDevice name]};
|
|
|
|
-
|
|
|
|
- fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
|
|
|
|
- forConnection:self
|
|
|
|
- separator:@"%%"
|
|
|
|
- replacementDictionary:replacementDict];
|
|
|
|
- fileResponse.contentType = @"application/xml";
|
|
|
|
- } else {
|
|
|
|
- replacementDict = @{@"FILES" : [mediaInHtml componentsJoinedByString:@" "],
|
|
|
|
- @"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE", nil),
|
|
|
|
- @"WEBINTF_DROPFILES" : NSLocalizedString(@"WEBINTF_DROPFILES", nil),
|
|
|
|
- @"WEBINTF_DROPFILES_LONG" : [NSString stringWithFormat:NSLocalizedString(@"WEBINTF_DROPFILES_LONG", nil), deviceModel],
|
|
|
|
- @"WEBINTF_DOWNLOADFILES" : NSLocalizedString(@"WEBINTF_DOWNLOADFILES", nil),
|
|
|
|
- @"WEBINTF_DOWNLOADFILES_LONG" : [NSString stringWithFormat: NSLocalizedString(@"WEBINTF_DOWNLOADFILES_LONG", nil), deviceModel]};
|
|
|
|
- fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
|
|
|
|
- forConnection:self
|
|
|
|
- separator:@"%%"
|
|
|
|
- replacementDictionary:replacementDict];
|
|
|
|
- fileResponse.contentType = @"text/html";
|
|
|
|
- }
|
|
|
|
|
|
+ UIDevice *currentDevice = [UIDevice currentDevice];
|
|
|
|
+ NSString *deviceModel = [currentDevice model];
|
|
|
|
+ NSDictionary *replacementDict;
|
|
|
|
+ HTTPDynamicFileResponse *fileResponse;
|
|
|
|
+
|
|
|
|
+ if (shouldReturnLibVLCXML) {
|
|
|
|
+ replacementDict = @{@"FILES" : [mediaInXml componentsJoinedByString:@" "],
|
|
|
|
+ @"NB_FILE" : [NSString stringWithFormat:@"%li", (unsigned long)mediaInXml.count],
|
|
|
|
+ @"LIB_TITLE" : [currentDevice name]};
|
|
|
|
+
|
|
|
|
+ fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
|
|
|
|
+ forConnection:self
|
|
|
|
+ separator:@"%%"
|
|
|
|
+ replacementDictionary:replacementDict];
|
|
|
|
+ fileResponse.contentType = @"application/xml";
|
|
|
|
+ } else {
|
|
|
|
+ replacementDict = @{@"FILES" : [mediaInHtml componentsJoinedByString:@" "],
|
|
|
|
+ @"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE", nil),
|
|
|
|
+ @"WEBINTF_DROPFILES" : NSLocalizedString(@"WEBINTF_DROPFILES", nil),
|
|
|
|
+ @"WEBINTF_DROPFILES_LONG" : [NSString stringWithFormat:NSLocalizedString(@"WEBINTF_DROPFILES_LONG", nil), deviceModel],
|
|
|
|
+ @"WEBINTF_DOWNLOADFILES" : NSLocalizedString(@"WEBINTF_DOWNLOADFILES", nil),
|
|
|
|
+ @"WEBINTF_DOWNLOADFILES_LONG" : [NSString stringWithFormat: NSLocalizedString(@"WEBINTF_DOWNLOADFILES_LONG", nil), deviceModel]};
|
|
|
|
+ fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
|
|
|
|
+ forConnection:self
|
|
|
|
+ separator:@"%%"
|
|
|
|
+ replacementDictionary:replacementDict];
|
|
|
|
+ fileResponse.contentType = @"text/html";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return fileResponse;
|
|
|
|
+}
|
|
#else
|
|
#else
|
|
- UIDevice *currentDevice = [UIDevice currentDevice];
|
|
|
|
- NSString *deviceModel = [currentDevice model];
|
|
|
|
- NSString *filePath = [self filePathForURI:path];
|
|
|
|
- NSString *documentRoot = [config documentRoot];
|
|
|
|
- NSString *relativePath = [filePath substringFromIndex:[documentRoot length]];
|
|
|
|
- NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE_ATV", nil),
|
|
|
|
- @"WEBINTF_DROPFILES" : NSLocalizedString(@"WEBINTF_DROPFILES", nil),
|
|
|
|
- @"WEBINTF_DROPFILES_LONG" : [NSString stringWithFormat:NSLocalizedString(@"WEBINTF_DROPFILES_LONG_ATV", nil), deviceModel]};
|
|
|
|
-
|
|
|
|
- HTTPDynamicFileResponse *fileResponse;
|
|
|
|
- if ([relativePath isEqualToString:@"/index.html"]) {
|
|
|
|
- fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
|
|
|
|
- forConnection:self
|
|
|
|
- separator:@"%%"
|
|
|
|
- replacementDictionary:replacementDict];
|
|
|
|
- fileResponse.contentType = @"text/html";
|
|
|
|
|
|
+- (NSObject<HTTPResponse> *)_httpGETLibraryForPath:(NSString *)path
|
|
|
|
+{
|
|
|
|
+ UIDevice *currentDevice = [UIDevice currentDevice];
|
|
|
|
+ NSString *deviceModel = [currentDevice model];
|
|
|
|
+ NSString *filePath = [self filePathForURI:path];
|
|
|
|
+ NSString *documentRoot = [config documentRoot];
|
|
|
|
+ NSString *relativePath = [filePath substringFromIndex:[documentRoot length]];
|
|
|
|
+ NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE_ATV", nil),
|
|
|
|
+ @"WEBINTF_DROPFILES" : NSLocalizedString(@"WEBINTF_DROPFILES", nil),
|
|
|
|
+ @"WEBINTF_DROPFILES_LONG" : [NSString stringWithFormat:NSLocalizedString(@"WEBINTF_DROPFILES_LONG_ATV", nil), deviceModel]};
|
|
|
|
+
|
|
|
|
+ HTTPDynamicFileResponse *fileResponse;
|
|
|
|
+ if ([relativePath isEqualToString:@"/index.html"]) {
|
|
|
|
+ fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
|
|
|
|
+ forConnection:self
|
|
|
|
+ separator:@"%%"
|
|
|
|
+ replacementDictionary:replacementDict];
|
|
|
|
+ fileResponse.contentType = @"text/html";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return fileResponse;
|
|
|
|
+}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- return fileResponse;
|
|
|
|
- } else if ([relativePath isEqualToString:@"/style.css"]) {
|
|
|
|
|
|
+
|
|
|
|
+- (NSObject<HTTPResponse> *)_httpGETCSSForPath:(NSString *)path
|
|
|
|
+{
|
|
#if TARGET_OS_IOS
|
|
#if TARGET_OS_IOS
|
|
- NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE", nil)};
|
|
|
|
|
|
+ NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE", nil)};
|
|
#else
|
|
#else
|
|
- NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE_ATV", nil)};
|
|
|
|
|
|
+ NSDictionary *replacementDict = @{@"WEBINTF_TITLE" : NSLocalizedString(@"WEBINTF_TITLE_ATV", nil)};
|
|
#endif
|
|
#endif
|
|
- HTTPDynamicFileResponse *fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
|
|
|
|
- forConnection:self
|
|
|
|
- separator:@"%%"
|
|
|
|
- replacementDictionary:replacementDict];
|
|
|
|
- fileResponse.contentType = @"text/css";
|
|
|
|
- return fileResponse;
|
|
|
|
|
|
+ HTTPDynamicFileResponse *fileResponse = [[HTTPDynamicFileResponse alloc] initWithFilePath:[self filePathForURI:path]
|
|
|
|
+ forConnection:self
|
|
|
|
+ separator:@"%%"
|
|
|
|
+ replacementDictionary:replacementDict];
|
|
|
|
+ fileResponse.contentType = @"text/css";
|
|
|
|
+ return fileResponse;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
|
|
|
|
+{
|
|
|
|
+ if ([method isEqualToString:@"POST"] && [path isEqualToString:@"/upload.json"])
|
|
|
|
+ return [self _httpPOSTresponseUploadJSON];
|
|
|
|
+
|
|
|
|
+#if TARGET_OS_IOS
|
|
|
|
+ if ([path hasPrefix:@"/download/"]) {
|
|
|
|
+ return [self _httpGETDownloadForPath:path];
|
|
|
|
+ }
|
|
|
|
+ if ([path hasPrefix:@"/thumbnail"]) {
|
|
|
|
+ return [self _httpGETThumbnailForPath:path];
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+ NSString *filePath = [self filePathForURI:path];
|
|
|
|
+ NSString *documentRoot = [config documentRoot];
|
|
|
|
+ NSString *relativePath = [filePath substringFromIndex:[documentRoot length]];
|
|
|
|
+
|
|
|
|
+ if ([relativePath isEqualToString:@"/index.html"] || [relativePath isEqualToString:@"/libMediaVLC.xml"]) {
|
|
|
|
+ return [self _httpGETLibraryForPath:path];
|
|
|
|
+ } else if ([relativePath isEqualToString:@"/style.css"]) {
|
|
|
|
+ return [self _httpGETCSSForPath:path];
|
|
}
|
|
}
|
|
|
|
|
|
return [super httpResponseForMethod:method URI:path];
|
|
return [super httpResponseForMethod:method URI:path];
|