| 1 | /* |
|---|
| 2 | * NSFileManager-Extensions.m |
|---|
| 3 | * Sapphire |
|---|
| 4 | * |
|---|
| 5 | * Created by Patrick Merrill on Dec. 09, 2007. |
|---|
| 6 | * Copyright 2007 Sapphire Development Team and/or www.nanopi.net |
|---|
| 7 | * All rights reserved. |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
|---|
| 10 | * General Public License as published by the Free Software Foundation; either version 3 of the License, |
|---|
| 11 | * or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
|---|
| 14 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|---|
| 15 | * Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License along with this program; if not, |
|---|
| 18 | * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #import "NSFileManager-Extensions.h" |
|---|
| 22 | #import "SapphireMetaDataSupport.h" |
|---|
| 23 | |
|---|
| 24 | @implementation NSFileManager (SapphireExtensions) |
|---|
| 25 | - (BOOL)constructPath:(NSString *)proposedPath |
|---|
| 26 | { |
|---|
| 27 | BOOL isDir ; |
|---|
| 28 | if(!([self fileExistsAtPath:proposedPath isDirectory:&isDir]&& isDir)) |
|---|
| 29 | if(![self createDirectoryAtPath:proposedPath attributes:nil]) |
|---|
| 30 | if([self constructPath:[proposedPath stringByDeletingLastPathComponent]]) |
|---|
| 31 | return [self createDirectoryAtPath:proposedPath attributes:nil]; |
|---|
| 32 | else |
|---|
| 33 | return NO; |
|---|
| 34 | return YES; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | // Static set of file extensions to filter |
|---|
| 38 | static NSSet *videoExtensions = nil; |
|---|
| 39 | static NSSet *audioExtensions = nil; |
|---|
| 40 | static NSSet *allExtensions = nil; |
|---|
| 41 | |
|---|
| 42 | + (void)load |
|---|
| 43 | { |
|---|
| 44 | videoExtensions = [[NSSet alloc] initWithObjects: |
|---|
| 45 | @"avi", @"divx", @"xvid", |
|---|
| 46 | @"mov", |
|---|
| 47 | @"mpg", @"mpeg", @"m2v", @"ts", |
|---|
| 48 | @"wmv", @"asx", @"asf", |
|---|
| 49 | @"mkv", |
|---|
| 50 | @"flv", |
|---|
| 51 | @"mp4", @"m4v", |
|---|
| 52 | @"3gp", |
|---|
| 53 | @"pls", |
|---|
| 54 | @"avc", |
|---|
| 55 | @"ogm", |
|---|
| 56 | @"dv", |
|---|
| 57 | @"fli", |
|---|
| 58 | nil]; |
|---|
| 59 | audioExtensions = [[NSSet alloc] initWithObjects: |
|---|
| 60 | @"m4b", @"m4a", |
|---|
| 61 | @"mp3", @"mp2", |
|---|
| 62 | @"wma", |
|---|
| 63 | @"wav", |
|---|
| 64 | @"aif", @"aiff", |
|---|
| 65 | @"flac", |
|---|
| 66 | @"alac", |
|---|
| 67 | @"m3u", |
|---|
| 68 | @"ac3", |
|---|
| 69 | nil]; |
|---|
| 70 | NSMutableSet *mutSet = [videoExtensions mutableCopy]; |
|---|
| 71 | [mutSet unionSet:audioExtensions]; |
|---|
| 72 | allExtensions = [[NSSet alloc] initWithSet:mutSet]; |
|---|
| 73 | [mutSet release]; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | + (NSSet *)videoExtensions |
|---|
| 77 | { |
|---|
| 78 | return videoExtensions; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | + (NSSet *)audioExtensions |
|---|
| 82 | { |
|---|
| 83 | return audioExtensions; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | - (BOOL)hasVIDEO_TS:(NSString *)path |
|---|
| 87 | { |
|---|
| 88 | BOOL isDir = NO; |
|---|
| 89 | NSFileManager *fm = [NSFileManager defaultManager]; |
|---|
| 90 | if([fm fileExistsAtPath:[path stringByAppendingPathComponent:@"VIDEO_TS"] isDirectory:&isDir] && isDir) |
|---|
| 91 | return YES; |
|---|
| 92 | return NO; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | - (BOOL)isDirectory:(NSString *)path |
|---|
| 96 | { |
|---|
| 97 | BOOL isDir = NO; |
|---|
| 98 | BOOL exists = [self fileExistsAtPath:path isDirectory:&isDir]; |
|---|
| 99 | BOOL ret = exists && isDir; |
|---|
| 100 | if(ret) |
|---|
| 101 | { |
|---|
| 102 | if([self hasVIDEO_TS:path]) |
|---|
| 103 | return NO; |
|---|
| 104 | } |
|---|
| 105 | return ret; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | - (BOOL)acceptFilePath:(NSString *)path |
|---|
| 109 | { |
|---|
| 110 | if(path == nil) |
|---|
| 111 | return NO; |
|---|
| 112 | NSString *name = [path lastPathComponent]; |
|---|
| 113 | |
|---|
| 114 | /*Skip hidden files*/ |
|---|
| 115 | if([name hasPrefix:@"."]) |
|---|
| 116 | return NO; |
|---|
| 117 | |
|---|
| 118 | /*Skip the Cover Art directory*/ |
|---|
| 119 | if([name isEqualToString:@"Cover Art"]) |
|---|
| 120 | return NO; |
|---|
| 121 | |
|---|
| 122 | path = [path stringByResolvingSymlinksInPath]; |
|---|
| 123 | return ([self isDirectory:path] || [self hasVIDEO_TS:path] || [allExtensions containsObject:[path pathExtension]]); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | + (NSString *)previewArtPathForTV:(NSString *)show season:(unsigned int)seasonNum |
|---|
| 127 | { |
|---|
| 128 | return [NSString stringWithFormat:@"%@/@TV/%@/%@", [SapphireMetaDataSupport collectionArtPath], |
|---|
| 129 | show, |
|---|
| 130 | [NSString stringWithFormat:@"Season %d", seasonNum]]; |
|---|
| 131 | } |
|---|
| 132 | @end |
|---|