2007-10-09 01:20:46 +00:00
|
|
|
//
|
|
|
|
// M3uContainer.m
|
|
|
|
// M3u
|
|
|
|
//
|
|
|
|
// Created by Zaphod Beeblebrox on 10/8/07.
|
|
|
|
// Copyright 2007 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "M3uContainer.h"
|
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
2007-10-09 01:20:46 +00:00
|
|
|
|
|
|
|
@implementation M3uContainer
|
|
|
|
|
|
|
|
+ (NSArray *)fileTypes
|
|
|
|
{
|
2013-10-08 03:27:38 +00:00
|
|
|
return [NSArray arrayWithObjects:@"m3u", @"m3u8", nil];
|
2007-10-09 01:20:46 +00:00
|
|
|
}
|
|
|
|
|
2007-10-14 18:56:23 +00:00
|
|
|
+ (NSArray *)mimeTypes
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects:@"audio/x-mpegurl", @"audio/mpegurl", nil];
|
|
|
|
}
|
|
|
|
|
2015-04-13 07:39:24 +00:00
|
|
|
+ (float)priority
|
|
|
|
{
|
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
|
2007-10-09 01:20:46 +00:00
|
|
|
+ (NSURL *)urlForPath:(NSString *)path relativeTo:(NSString *)baseFilename
|
|
|
|
{
|
2007-10-15 22:19:14 +00:00
|
|
|
NSRange protocolRange = [path rangeOfString:@"://"];
|
|
|
|
if (protocolRange.location != NSNotFound)
|
2007-10-09 01:20:46 +00:00
|
|
|
{
|
|
|
|
return [NSURL URLWithString:path];
|
|
|
|
}
|
2007-10-15 22:19:14 +00:00
|
|
|
|
2007-10-09 01:20:46 +00:00
|
|
|
NSMutableString *unixPath = [path mutableCopy];
|
2007-10-15 22:19:14 +00:00
|
|
|
|
2007-10-19 03:06:52 +00:00
|
|
|
//Get the fragment
|
2007-10-15 22:57:30 +00:00
|
|
|
NSString *fragment = @"";
|
2007-10-19 03:06:52 +00:00
|
|
|
NSScanner *scanner = [NSScanner scannerWithString:unixPath];
|
|
|
|
NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"#1234567890"];
|
|
|
|
while (![scanner isAtEnd]) {
|
|
|
|
NSString *possibleFragment;
|
|
|
|
[scanner scanUpToString:@"#" intoString:nil];
|
|
|
|
|
|
|
|
if ([scanner scanCharactersFromSet:characterSet intoString:&possibleFragment] && [scanner isAtEnd])
|
|
|
|
{
|
|
|
|
fragment = possibleFragment;
|
|
|
|
[unixPath deleteCharactersInRange:NSMakeRange([scanner scanLocation] - [possibleFragment length], [possibleFragment length])];
|
|
|
|
break;
|
|
|
|
}
|
2007-10-15 22:57:30 +00:00
|
|
|
}
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Fragment: %@", fragment);
|
2007-10-15 22:19:14 +00:00
|
|
|
|
2007-10-15 22:57:30 +00:00
|
|
|
if (![unixPath hasPrefix:@"/"]) {
|
|
|
|
//Only relative paths would have windows backslashes.
|
|
|
|
[unixPath replaceOccurrencesOfString:@"\\" withString:@"/" options:0 range:NSMakeRange(0, [unixPath length])];
|
|
|
|
|
|
|
|
NSString *basePath = [[[baseFilename stringByStandardizingPath] stringByDeletingLastPathComponent] stringByAppendingString:@"/"];
|
2007-10-15 22:19:14 +00:00
|
|
|
|
2007-10-15 22:57:30 +00:00
|
|
|
[unixPath insertString:basePath atIndex:0];
|
|
|
|
}
|
2007-10-09 01:20:46 +00:00
|
|
|
|
2007-10-15 22:57:30 +00:00
|
|
|
//Append the fragment
|
2008-08-26 17:45:16 +00:00
|
|
|
NSURL *url = [NSURL URLWithString:[[[NSURL fileURLWithPath:unixPath] absoluteString] stringByAppendingString: fragment]];
|
|
|
|
[unixPath release];
|
|
|
|
return url;
|
2007-10-09 01:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url
|
|
|
|
{
|
|
|
|
if (![url isFileURL])
|
|
|
|
return [NSArray array];
|
|
|
|
|
|
|
|
NSString *filename = [url path];
|
|
|
|
|
2007-10-20 15:08:06 +00:00
|
|
|
NSStringEncoding encoding;
|
2007-10-09 01:20:46 +00:00
|
|
|
NSError *error = nil;
|
2007-10-20 15:08:06 +00:00
|
|
|
NSString *contents = [NSString stringWithContentsOfFile:filename usedEncoding:&encoding error:&error];
|
|
|
|
if (error) {
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Trying UTF8");
|
2007-10-20 15:08:06 +00:00
|
|
|
error = nil;
|
|
|
|
contents = [NSString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:&error];
|
|
|
|
}
|
|
|
|
if (error) {
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Trying windows CP1251");
|
2007-10-20 15:08:06 +00:00
|
|
|
error = nil;
|
|
|
|
contents = [NSString stringWithContentsOfFile:filename encoding:NSWindowsCP1251StringEncoding error:&error];
|
|
|
|
}
|
|
|
|
if (error) {
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Trying latin1");
|
2007-10-20 15:08:06 +00:00
|
|
|
error = nil;
|
|
|
|
contents = [NSString stringWithContentsOfFile:filename encoding:NSISOLatin1StringEncoding error:&error];
|
|
|
|
}
|
2007-10-09 01:20:46 +00:00
|
|
|
if (error || !contents) {
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"Could not open file...%@ %@ %@", filename, contents, error);
|
2007-10-20 15:08:06 +00:00
|
|
|
return nil;
|
2007-10-09 01:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableArray *entries = [NSMutableArray array];
|
|
|
|
|
2013-10-10 08:44:45 +00:00
|
|
|
for (NSString *entry in [contents componentsSeparatedByString:@"\n"])
|
|
|
|
{
|
|
|
|
entry = [entry stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
|
|
|
|
2007-10-09 01:20:46 +00:00
|
|
|
if ([entry hasPrefix:@"#"] || [entry isEqualToString:@""]) //Ignore extra info
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//Need to add basePath, and convert to URL
|
2007-10-15 22:57:30 +00:00
|
|
|
[entries addObject:[self urlForPath:entry relativeTo:filename]];
|
2007-10-09 01:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|