Set season to 0 if not available
This commit is contained in:
1 parent
6f1abcab3c
commit
f6b0962970
5 files changed
+47
-25
No files matched your search
@@ -24,7 +24,7 @@ typedef enum SBCachePolicy : NSUInteger {
|
|||||||
} SBCachePolicy;
|
} SBCachePolicy;
|
||||||
|
|
||||||
#pragma mark Helper routines
|
#pragma mark Helper routines
|
||||||
+ (NSDictionary *)parseFilename:(NSString *)filename;
|
+ (NSDictionary<NSString *, NSString *> *)parseFilename:(NSString *)filename;
|
||||||
+ (NSString *)urlEncoded:(NSString *)string;
|
+ (NSString *)urlEncoded:(NSString *)string;
|
||||||
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url withCachePolicy:(SBCachePolicy)policy;
|
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url withCachePolicy:(SBCachePolicy)policy;
|
||||||
|
|
||||||
|
|||||||
@@ -33,13 +33,14 @@
|
|||||||
|
|
||||||
#pragma mark Helper routines
|
#pragma mark Helper routines
|
||||||
|
|
||||||
+ (NSDictionary *)parseFilename:(NSString *)filename
|
+ (NSDictionary<NSString *, NSString *> *)parseFilename:(NSString *)filename
|
||||||
{
|
{
|
||||||
NSMutableDictionary *results = nil;
|
NSMutableDictionary<NSString *, NSString *> *results = nil;
|
||||||
|
|
||||||
NSParameterAssert(filename);
|
NSParameterAssert(filename);
|
||||||
NSParameterAssert(filename.length);
|
NSParameterAssert(filename.length);
|
||||||
|
|
||||||
|
// Try with the usual anime filename
|
||||||
NSString *regexString = @"^\\[(.+)\\](?:(?:\\s|_)+)?([^()]+)(?:(?:\\s|_)+)(?:(?:-\\s|-_|Ep)+)([0-9][0-9]?)";
|
NSString *regexString = @"^\\[(.+)\\](?:(?:\\s|_)+)?([^()]+)(?:(?:\\s|_)+)(?:(?:-\\s|-_|Ep)+)([0-9][0-9]?)";
|
||||||
NSDictionary *resultDictionary = [filename dictionaryByMatchingRegex:regexString
|
NSDictionary *resultDictionary = [filename dictionaryByMatchingRegex:regexString
|
||||||
withKeysAndCaptures:@"fanSubGroup", 1, @"seriesName", 2, @"episodeNumber", 3, nil];
|
withKeysAndCaptures:@"fanSubGroup", 1, @"seriesName", 2, @"episodeNumber", 3, nil];
|
||||||
@@ -55,11 +56,12 @@
|
|||||||
|
|
||||||
return [results autorelease];
|
return [results autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Else use the ParseFilename perl script
|
||||||
NSTask *task = [[NSTask alloc] init];
|
NSTask *task = [[NSTask alloc] init];
|
||||||
[task setLaunchPath:@"/usr/bin/perl"];
|
[task setLaunchPath:@"/usr/bin/perl"];
|
||||||
|
|
||||||
NSMutableArray *args = [[NSMutableArray alloc] initWithCapacity:3];
|
NSMutableArray<NSString *> *args = [[NSMutableArray alloc] initWithCapacity:3];
|
||||||
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"ParseFilename" ofType:@""];
|
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"ParseFilename" ofType:@""];
|
||||||
[args addObject:[NSString stringWithFormat:@"-I%@/lib", path]];
|
[args addObject:[NSString stringWithFormat:@"-I%@/lib", path]];
|
||||||
[args addObject:[NSString stringWithFormat:@"%@/ParseFilename.pl", path]];
|
[args addObject:[NSString stringWithFormat:@"%@/ParseFilename.pl", path]];
|
||||||
@@ -76,33 +78,48 @@
|
|||||||
|
|
||||||
NSData *outputData = [[stdOut fileHandleForReading] readDataToEndOfFile];
|
NSData *outputData = [[stdOut fileHandleForReading] readDataToEndOfFile];
|
||||||
NSString *outputString = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
|
NSString *outputString = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
|
||||||
NSArray *lines = [outputString componentsSeparatedByString:@"\n"];
|
NSArray<NSString *> *lines = [outputString componentsSeparatedByString:@"\n"];
|
||||||
|
|
||||||
if ([lines count]) {
|
if (lines.count) {
|
||||||
if ([(NSString *) [lines objectAtIndex:0] isEqualToString:@"tv"]) {
|
|
||||||
if ([lines count] >= 4) {
|
if ([lines.firstObject isEqualToString:@"tv"]) {
|
||||||
|
|
||||||
|
if (lines.count >= 4) {
|
||||||
|
|
||||||
results = [[NSMutableDictionary alloc] initWithCapacity:4];
|
results = [[NSMutableDictionary alloc] initWithCapacity:4];
|
||||||
[results setValue:@"tv" forKey:@"type"];
|
results[@"type"] = @"tv";
|
||||||
NSString *newSeriesName=[[lines objectAtIndex:1]
|
|
||||||
stringByReplacingOccurrencesOfString:@"."
|
NSString *newSeriesName=[lines[1] stringByReplacingOccurrencesOfString:@"."
|
||||||
withString:@" "];
|
withString:@" "];
|
||||||
[results setValue:newSeriesName forKey:@"seriesName"];
|
results[@"seriesName"] = newSeriesName;
|
||||||
[results setValue:[lines objectAtIndex:2] forKey:@"seasonNum"];
|
|
||||||
[results setValue:[lines objectAtIndex:3] forKey:@"episodeNum"];
|
if ([lines[2] integerValue]) {
|
||||||
|
results[@"seasonNum"] = lines[2];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
results[@"seasonNum"] = @"0";
|
||||||
|
}
|
||||||
|
|
||||||
|
results[@"episodeNum"] = lines[3];
|
||||||
}
|
}
|
||||||
} else if ([(NSString *) [lines objectAtIndex:0] isEqualToString:@"movie"]) {
|
}
|
||||||
if ([lines count] >= 2) {
|
else if ([lines.firstObject isEqualToString:@"movie"]) {
|
||||||
results = [[NSMutableDictionary alloc] initWithCapacity:4];
|
|
||||||
[results setValue:@"movie" forKey:@"type"];
|
if (lines.count >= 2) {
|
||||||
NSString *newTitle=[[lines objectAtIndex:1]
|
|
||||||
stringByReplacingOccurrencesOfString:@"."
|
results = [[NSMutableDictionary alloc] initWithCapacity:2];
|
||||||
withString:@" "];
|
results[@"type"] = @"movie";
|
||||||
|
|
||||||
|
NSString *newTitle=[lines[1] stringByReplacingOccurrencesOfString:@"."
|
||||||
|
withString:@" "];
|
||||||
|
|
||||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"(" withString:@" "];
|
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"(" withString:@" "];
|
||||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@")" withString:@" "];
|
newTitle = [newTitle stringByReplacingOccurrencesOfString:@")" withString:@" "];
|
||||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"[" withString:@" "];
|
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"[" withString:@" "];
|
||||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"]" withString:@" "];
|
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"]" withString:@" "];
|
||||||
newTitle = [newTitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
newTitle = [newTitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||||
[results setValue:newTitle forKey:@"title"];
|
|
||||||
|
results[@"title"] = newTitle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -635,6 +635,10 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!filename) {
|
||||||
|
filename = self.fileURL.lastPathComponent;
|
||||||
|
}
|
||||||
|
|
||||||
importWindow = [[SBMetadataSearchController alloc] initWithDelegate:self searchString:filename];
|
importWindow = [[SBMetadataSearchController alloc] initWithDelegate:self searchString:filename];
|
||||||
|
|
||||||
[NSApp beginSheet:[importWindow window]
|
[NSApp beginSheet:[importWindow window]
|
||||||
|
|||||||
@@ -190,7 +190,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[searchButton setEnabled:NO];
|
[searchButton setEnabled:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ if ($file->isTVshow()) {
|
|||||||
} elsif ($file->isEpisode()) {
|
} elsif ($file->isEpisode()) {
|
||||||
print "tv" . "\n";
|
print "tv" . "\n";
|
||||||
print $file->{name} . "\n";
|
print $file->{name} . "\n";
|
||||||
|
print $file->{season} . "\n";
|
||||||
print $file->{episode} . "\n";
|
print $file->{episode} . "\n";
|
||||||
print $file->{part} . "\n";
|
print $file->{part} . "\n";
|
||||||
} elsif ($file->isMovie()) {
|
} elsif ($file->isMovie()) {
|
||||||
|
|||||||
Reference in new issue
Block a user