Ticket #145: ripped-tv-shows.diff

File ripped-tv-shows.diff, 5.3 kB (added by anonymous, 8 months ago)
  • SapphireMetaData.h

    old new  
    862862 * 
    863863 * @return The file size 
    864864 */ 
    865 - (long long)size; 
     865- (unsigned long long)size; 
    866866 
    867867/*! 
    868868 * @brief Returns the file's duration in seconds 
  • SapphireMetaData.m

    old new  
    16111611        [self combinedDataChanged];      
    16121612} 
    16131613 
     1614/*! 
     1615 * 
     1616 */ 
     1617static id totalFileSize(NSString *path, NSDictionary *props) 
     1618{ 
     1619    unsigned long long size = [[props objectForKey:NSFileSize] unsignedLongLongValue]; 
     1620 
     1621        /* Our file may be a directory containing VIDEO_TS */ 
     1622    if( [props objectForKey:NSFileType] == NSFileTypeDirectory ) 
     1623    { 
     1624        NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:path]; 
     1625        NSString *content; 
     1626         
     1627        while( content = [enumerator nextObject] ) 
     1628        { 
     1629                        NSDictionary *subprops = [[NSFileManager defaultManager] fileAttributesAtPath:[path stringByAppendingPathComponent:content] traverseLink:NO]; 
     1630                        size += [[subprops objectForKey:NSFileSize] unsignedLongLongValue]; 
     1631        } 
     1632    } 
     1633     
     1634    return [NSNumber numberWithUnsignedLongLong:size]; 
     1635} 
     1636 
    16141637BOOL updateMetaData(id <SapphireFileMetaDataProtocol> file) 
    16151638{ 
    16161639        BOOL updated =FALSE; 
     
    16241647                NSDictionary *props = [[NSFileManager defaultManager] fileAttributesAtPath:path traverseLink:YES]; 
    16251648                int modTime = [[props objectForKey:NSFileModificationDate] timeIntervalSince1970]; 
    16261649                /*Set modified, size, and version*/ 
     1650                id num = totalFileSize(path, props); 
    16271651                [fileMeta setObject:[NSNumber numberWithInt:modTime] forKey:MODIFIED_KEY]; 
    1628                 [fileMeta setObject:[props objectForKey:NSFileSize] forKey:SIZE_KEY]; 
     1652                [fileMeta setObject:num forKey:SIZE_KEY]; 
    16291653                [fileMeta setObject:[NSNumber numberWithInt:META_FILE_VERSION] forKey:META_VERSION_KEY]; 
    16301654                 
    16311655                if([file fileContainerType] == FILE_CONTAINER_TYPE_QT_MOVIE) 
     
    18131837                [metaData setObject:join forKey:JOINED_FILE_KEY]; 
    18141838} 
    18151839 
    1816 - (long long)size 
     1840- (unsigned long long)size 
    18171841{ 
    1818         return [[metaData objectForKey:SIZE_KEY] longLongValue]; 
     1842        return [[metaData objectForKey:SIZE_KEY] unsignedLongLongValue]; 
    18191843} 
    18201844 
    18211845- (float)duration 
  • SapphireTVShowImporter.m

    old new  
    477477        [tdict release]; 
    478478} 
    479479 
     480-(NSMutableString *) createShortDesc:(NSMutableDictionary *)info 
     481{ 
     482/*  Get the first sentence */ 
     483/*      NSString *desc = [[info objectForKey:META_DESCRIPTION_KEY] substringToIndex:[[info objectForKey:META_DESCRIPTION_KEY] rangeOfString:@"."].location+1]; */ 
     484 
     485        return [NSMutableString stringWithFormat:@"%@ / ", [info objectForKey:META_TITLE_KEY]]; 
     486} 
     487 
     488/*  
     489 * Combine the meta data from multiple episodes into the first episode given. 
     490 * 
     491 * This will change the episode name to "Episode X - Y" and the summary 
     492 * will contain the episode names. 
     493 */ 
     494- (void)combine:(NSMutableDictionary *)info withMultipleEpisodes:(NSMutableArray *)episodes 
     495{ 
     496        NSEnumerator   *enumerator = [episodes objectEnumerator]; 
     497        NSMutableString *shortDesc = [self createShortDesc:info]; 
     498        id episode; 
     499 
     500        while( episode = [enumerator nextObject] ) 
     501        { 
     502                [self combine:info with:episode]; 
     503                [shortDesc appendString:[self createShortDesc:episode]]; 
     504        } 
     505 
     506        // lose the last " /" on the short description. 
     507        NSRange truncate; 
     508        truncate.location = [shortDesc length] - 3; 
     509        truncate.length   = 3; 
     510        [shortDesc deleteCharactersInRange:truncate]; 
     511 
     512        /* If there is more than one extra episode the title and description  
     513         * become unreadable - make nicer versions of these */ 
     514        if( [episodes count] > 1 ) 
     515        { 
     516                int fromEp = [[info objectForKey:META_EPISODE_NUMBER_KEY]   intValue]; 
     517                int toEp   = [[info objectForKey:META_EPISODE_2_NUMBER_KEY] intValue]; 
     518 
     519                [info setObject:[NSString stringWithFormat:@"Episodes %d - %d", fromEp, toEp] forKey:META_TITLE_KEY]; 
     520                [info setObject:shortDesc forKey:META_DESCRIPTION_KEY]; 
     521        } 
     522} 
     523 
    480524- (ImportState) importMetaData:(id <SapphireFileMetaDataProtocol>)metaData 
    481525{ 
    482526        currentData = metaData; 
     
    592636                otherEp = overriddenEpisode; 
    593637 
    594638        /*Get the episode's info*/ 
    595         NSMutableDictionary *info = nil, *info2 = nil; 
     639        NSMutableDictionary *info = nil; 
     640        NSMutableArray *otherEpisodes = nil; 
    596641        if(ep != 0) 
    597642        { 
    598643                /*Match on s/e*/ 
    599644                info = [self getInfo:show forSeason:season episode:ep]; 
    600645                if(otherEp != 0) 
    601                         info2 = [self getInfo:show forSeason:season episode:otherEp]; 
     646                { 
     647                        otherEpisodes = [[NSMutableArray alloc] init]; 
     648                        int idx = 0; 
     649                         
     650                        for(idx = 1; idx <= otherEp - ep; ++idx) 
     651                                [otherEpisodes addObject:[self getInfo:show forSeason:season episode:ep+idx]]; 
     652                } 
    602653        } 
    603654        else 
    604655        { 
     
    638689                [[NSURLDownload alloc] initWithRequest:request delegate:myDelegate]; 
    639690                [myDelegate release]; 
    640691        } 
    641          
    642         if(info2 != nil) 
    643                 [self combine:info with:info2]; 
     692 
     693        if(otherEpisodes != nil) 
     694                [self combine:info withMultipleEpisodes:otherEpisodes]; 
     695        [otherEpisodes release]; 
    644696        /*Import the info*/ 
    645697        [info removeObjectForKey:LINK_KEY]; 
    646698        [metaData importInfo:info fromSource:META_TVRAGE_IMPORT_KEY withTime:[[NSDate date] timeIntervalSince1970]];