Show
Ignore:
Timestamp:
01/10/08 11:10:56 (4 years ago)
Author:
gbooker
Message:

Two episode in a file support
Refs #14

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/SapphireTVShowImporter.m

    r442 r451  
    105105         
    106106        /*Initialize the regexes*/ 
    107         regcomp(&letterMarking, "[\\. -]?S[0-9]+E[S0-9]+", REG_EXTENDED | REG_ICASE); 
    108         regcomp(&seasonByEpisode, "[\\. -]?[0-9]+x[S0-9]+", REG_EXTENDED | REG_ICASE); 
     107        regcomp(&letterMarking, "[\\. -]?S[0-9]+E[S0-9]+(-E[0-9]+)?", REG_EXTENDED | REG_ICASE); 
     108        regcomp(&seasonByEpisode, "[\\. -]?[0-9]+x[S0-9]+(-[0-9]+)?", REG_EXTENDED | REG_ICASE); 
    109109        regcomp(&seasonEpisodeTriple, "[\\. -][0-9]{1,3}[S0-9]{2}[\\. -]", REG_EXTENDED | REG_ICASE);    
    110110        return self; 
     
    449449} 
    450450 
     451- (void)combine:(NSMutableDictionary *)info with:(NSMutableDictionary *)info2 
     452{ 
     453        NSMutableDictionary *tdict = [info2 mutableCopy]; 
     454        [tdict addEntriesFromDictionary:info]; 
     455        NSString *secname = [info2 objectForKey:META_TITLE_KEY]; 
     456        NSString *origname = [info objectForKey:META_TITLE_KEY]; 
     457        if(secname != nil && origname != nil) 
     458                [tdict setObject:[NSString stringWithFormat:@"%@ / %@", origname, secname] forKey:META_TITLE_KEY]; 
     459 
     460        if([info objectForKey:META_EPISODE_NUMBER_KEY] != nil) 
     461        { 
     462                NSNumber *secondEp = [info2 objectForKey:META_EPISODE_NUMBER_KEY]; 
     463                [tdict setObject:secondEp forKey:META_EPISODE_2_NUMBER_KEY]; 
     464        } 
     465        NSString *secdesc = [info2 objectForKey:META_DESCRIPTION_KEY]; 
     466        NSString *origdesc = [info objectForKey:META_DESCRIPTION_KEY]; 
     467        if(secdesc != nil && origdesc != nil) 
     468                [tdict setObject:[NSString stringWithFormat:@"%@ / %@", origdesc, secdesc] forKey:META_DESCRIPTION_KEY]; 
     469 
     470        if([info objectForKey:META_ABSOLUTE_EP_NUMBER_KEY] != nil) 
     471        { 
     472                NSNumber *secondEp = [info2 objectForKey:META_ABSOLUTE_EP_NUMBER_KEY]; 
     473                [tdict setObject:secondEp forKey:META_ABSOLUTE_EP_2_NUMBER_KEY]; 
     474        } 
     475         
     476        [info addEntriesFromDictionary:tdict]; 
     477        [tdict release]; 
     478} 
     479 
    451480- (BOOL) importMetaData:(id <SapphireFileMetaDataProtocol>)metaData 
    452481{ 
     
    469498        /*Check regexes to see if this is a tv show*/ 
    470499        int index = NSNotFound; 
     500        int secondEp = -1; 
    471501        regmatch_t matches[3]; 
    472502        NSData *fileNameData = [fileName dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 
     
    477507                index = matches[0].rm_so; 
    478508                scanString = [fileName substringFromIndex:index]; 
     509                secondEp = matches[1].rm_so; 
    479510        } 
    480511        else if(!regexec(&seasonByEpisode, theFileName, 3, matches, 0)) 
     
    482513                index = matches[0].rm_so; 
    483514                scanString = [fileName substringFromIndex:index]; 
     515                secondEp = matches[1].rm_so; 
    484516        } 
    485517        else if(!regexec(&seasonEpisodeTriple, theFileName, 3, matches, 0)) 
     
    541573                return NO; 
    542574         
     575        int otherEp = 0; 
     576        if(secondEp != -1) 
     577        { 
     578                [scanner setScanLocation:secondEp - index]; 
     579                [scanner scanUpToCharactersFromSet:digits intoString:nil]; 
     580                [scanner scanInt:&otherEp]; 
     581        } 
     582         
    543583        /*Get the episode's info*/ 
    544         NSMutableDictionary *info = nil; 
     584        NSMutableDictionary *info = nil, *info2 = nil; 
    545585        if(ep != 0) 
     586        { 
    546587                /*Match on s/e*/ 
    547588                info = [self getInfo:show forSeason:season episode:ep]; 
     589                if(otherEp != 0) 
     590                        info2 = [self getInfo:show forSeason:season episode:otherEp]; 
     591        } 
    548592        else 
    549593        { 
     
    564608                                                                        [NSString stringWithFormat:@"Season %d",[[info objectForKey:META_SEASON_NUMBER_KEY] intValue]]]; 
    565609                                                 
    566         [[NSFileManager defaultManager]constructPath:previewArtPath]; 
     610        [[NSFileManager defaultManager] constructPath:previewArtPath]; 
    567611        /*Check for screen cap locally and on server*/ 
    568612        NSString *showInfoUrl = [info objectForKey:LINK_KEY]; 
     
    585629        } 
    586630         
     631        if(info2 != nil) 
     632                [self combine:info with:info2]; 
    587633        /*Import the info*/ 
    588634        [info removeObjectForKey:LINK_KEY];