Changeset 226

Show
Ignore:
Timestamp:
09/18/07 23:35:28 (1 year ago)
Author:
pmerrill
Message:
  • Implemented IMPAwards cover art fetching - Automated only.
  • Initial framework for Movie support in the browser
  • Initial framework for Movie support in the media preview
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/SapphireBrowser.m

    r214 r226  
    409409*/ 
    410410        NSString * displayName=nil ; 
     411        int fileCls=0 ; 
    411412        /*Check for no items*/ 
    412413        int nameCount = [_names count]; 
     
    445446                if(meta != nil) 
    446447                { 
    447                         /*Display episode number if availble*/ 
    448                         int eps= [meta episodeNumber] ; 
    449                         displayName=[meta episodeTitle] ; 
    450                         if(eps>0) 
    451                                 [[result textItem] setRightJustifiedText:[NSString stringWithFormat:@" %02d",eps]]; 
    452                         else 
    453                                 /*Fallback to size*/ 
    454                                 [[result textItem] setRightJustifiedText:[meta sizeString]]; 
     448                        fileCls=[meta fileClass] ; 
     449                        if(fileCls==FILE_CLASS_TV_SHOW) 
     450                        { 
     451                                /*Display episode number if availble*/ 
     452                                int eps= [meta episodeNumber] ; 
     453                                displayName=[meta episodeTitle] ; 
     454                                if(eps>0) 
     455                                        [[result textItem] setRightJustifiedText:[NSString stringWithFormat:@" %02d",eps]]; 
     456                                else 
     457                                        /*Fallback to size*/ 
     458                                        [[result textItem] setRightJustifiedText:[meta sizeString]]; 
     459                        } 
     460                        if(fileCls==FILE_CLASS_MOVIE) 
     461                        { 
     462                                int duration = [meta duration]; 
     463                                int secs = duration % 60; 
     464                                int mins = (duration /60) % 60; 
     465                                int hours = duration / 3600; 
     466                                NSString *durationStr = nil; 
     467                                if(hours != 0) 
     468                                        durationStr = [NSString stringWithFormat:@"%d:%02d:%02d", hours, mins, secs]; 
     469                                else if (mins != 0) 
     470                                        durationStr = [NSString stringWithFormat:@"%d:%02d", mins, secs]; 
     471                                else 
     472                                        durationStr = [NSString stringWithFormat:@"%ds", secs]; 
     473                                displayName=[meta movieTitle] ; 
     474                                [[result textItem] setRightJustifiedText:[NSString stringWithFormat:@" %@",durationStr]]; 
     475                        } 
    455476                        watched = [meta watched]; 
    456477                        favorite = [meta favorite] ; 
     
    468489        else if(!watched) [result setLeftIcon:[theme gem:BLUE_GEM_KEY]]; 
    469490        else if(favorite)[result setLeftIcon:[theme gem:YELLOW_GEM_KEY]]; 
     491        else if(fileCls==FILE_CLASS_AUDIO)[result setLeftIcon:[theme gem:GREEN_GEM_KEY]]; 
    470492        else [result setLeftIcon:[theme gem:RED_GEM_KEY]]; 
    471493                         
  • trunk/SapphireMediaPreview.m

    r204 r226  
    183183} 
    184184 
    185 /*! 
    186  * @brief Override the populating of metadata 
     185 
     186 
     187/*! 
     188 * @brief populate metadata for TV Shows 
    187189 */ 
    188190- (void)_populateMetadata 
     
    197199        NSMutableDictionary *allMeta = [meta getDisplayedMetaDataInOrder:&order]; 
    198200        /*Pull out the special ones*/ 
    199         /*Get the title*/ 
    200         NSString *value = [allMeta objectForKey:META_TITLE_KEY]; 
    201         if(value != nil) 
    202         { 
    203                 /*If there is an air date, put it in the title*/ 
    204                 NSDate *airDate = [allMeta objectForKey:META_SHOW_AIR_DATE]; 
    205                 if(airDate != nil) 
     201         
     202         
     203//      int fileCls = nil ; 
     204//      fileCls =[allMeta objectForKey:FILE_CLASS_KEY]; 
     205/*       
     206//       Movie Preview Handeling  
     207        if(fileCls==FILE_CLASS_MOVIE) 
     208        { 
     209                NSString *value = [allMeta objectForKey:META_TITLE_KEY]; 
     210                [_metadataLayer setTitle:value]; 
     211 
     212        } 
     213*/       
     214         
     215        /* TV Show Preview Handeling */ 
     216//      if(fileCls==FILE_CLASS_TV_SHOW) 
     217//      { 
     218                /*Get the title*/ 
     219                NSString *value = [allMeta objectForKey:META_TITLE_KEY]; 
     220                if(value != nil) 
    206221                { 
    207                         NSDateFormatter *format = [[NSDateFormatter alloc] init]; 
    208                         [format setDateStyle:NSDateFormatterShortStyle]; 
    209                         [format setTimeZone:NSDateFormatterNoStyle]; 
    210                         value = [[format stringFromDate:airDate]stringByAppendingFormat:@" - %@", value]; 
     222                        /*If there is an air date, put it in the title*/ 
     223                        NSDate *airDate = [allMeta objectForKey:META_SHOW_AIR_DATE]; 
     224                        if(airDate != nil) 
     225                        { 
     226                                NSDateFormatter *format = [[NSDateFormatter alloc] init]; 
     227                                [format setDateStyle:NSDateFormatterShortStyle]; 
     228                                [format setTimeZone:NSDateFormatterNoStyle]; 
     229                                value = [[format stringFromDate:airDate]stringByAppendingFormat:@" - %@", value]; 
     230                        } 
     231                        [_metadataLayer setTitle:value]; 
    211232                } 
    212                 [_metadataLayer setTitle:value]; 
    213         } 
    214  
    215         /*Get the rating*/ 
    216         value = [allMeta objectForKey:META_RATING_KEY]; 
    217         if(value != nil) 
    218                 [_metadataLayer setRating:value]; 
    219  
    220         /*Get the description*/ 
    221         value = [allMeta objectForKey:META_DESCRIPTION_KEY]; 
    222         if(value != nil) 
    223                 if([[SapphireSettings sharedSettings] displaySpoilers]) 
    224                        [_metadataLayer setSummary:value]; 
    225  
    226         /*Get the copyright*/ 
    227         value = [allMeta objectForKey:META_COPYRIGHT_KEY]; 
    228         if(value != nil) 
    229                 [_metadataLayer setCopyright:value]; 
    230          
    231         /*Get the season and epsiodes*/ 
    232         value = [allMeta objectForKey:META_EPISODE_AND_SEASON_KEY]; 
    233         if(value != nil) 
    234         { 
    235                 /*Remove the individuals so we don't display them*/ 
    236                 [allMeta removeObjectForKey:META_EPISODE_NUMBER_KEY]; 
    237                 [allMeta removeObjectForKey:META_SEASON_NUMBER_KEY]; 
    238         } 
     233 
     234               /*Get the rating*/ 
     235                value = [allMeta objectForKey:META_RATING_KEY]; 
     236               if(value != nil) 
     237                       [_metadataLayer setRating:value]; 
     238 
     239                /*Get the description*/ 
     240                value = [allMeta objectForKey:META_DESCRIPTION_KEY]; 
     241               if(value != nil) 
     242                       if([[SapphireSettings sharedSettings] displaySpoilers]) 
     243                               [_metadataLayer setSummary:value]; 
     244 
     245                /*Get the copyright*/ 
     246                value = [allMeta objectForKey:META_COPYRIGHT_KEY]; 
     247               if(value != nil) 
     248                       [_metadataLayer setCopyright:value]; 
     249         
     250                /*Get the season and epsiodes*/ 
     251               value = [allMeta objectForKey:META_EPISODE_AND_SEASON_KEY]; 
     252               if(value != nil) 
     253               { 
     254                       /*Remove the individuals so we don't display them*/ 
     255                       [allMeta removeObjectForKey:META_EPISODE_NUMBER_KEY]; 
     256                       [allMeta removeObjectForKey:META_SEASON_NUMBER_KEY]; 
     257                } 
     258//      } 
     259         
    239260         
    240261        NSMutableArray *values = [NSMutableArray array]; 
  • trunk/SapphireMetaData.h

    r222 r226  
    3535 
    3636//IMDB Type Info 
    37 #define META_MOVIE_TITLE                                @"Title" 
     37#define META_MOVIE_TITLE_KEY                    @"Title" 
     38#define META_MOVIE_RELEASE_DATE                 @"Released" 
    3839 
    3940//Special Display Only Info 
     
    4647#define META_DATA_FILE_INFO_KIND                                                @"MetaDataFileInfoKind" 
    4748 
     49#define FILE_CLASS_KEY                          @"File Class" 
    4850typedef enum { 
    4951        FILE_CLASS_UNKNOWN = 0, 
     
    181183- (int)seasonNumber; 
    182184- (NSString *)episodeTitle; 
     185- (NSString *)movieTitle; 
    183186- (NSString *)showID; 
    184187- (NSString *)showName ; 
  • trunk/SapphireMetaData.m

    r223 r226  
    3636#define VIDEO_DESC_KEY                          @"Video Description" 
    3737#define AUDIO_FORMAT_KEY                        @"Audio Format" 
    38 #define FILE_CLASS_KEY                                @"File Class" 
     38//#define FILE_CLASS_KEY                              @"File Class" 
    3939 
    4040@implementation NSString (episodeSorting) 
     
    13761376                META_COPYRIGHT_KEY, 
    13771377                META_TITLE_KEY, 
     1378                META_MOVIE_TITLE_KEY, 
    13781379                META_SHOW_AIR_DATE, 
    13791380                //These are displayed as line items 
     
    17221723        NSMutableDictionary *ret = [metaData mutableCopy]; 
    17231724        [ret addEntriesFromDictionary:[ret objectForKey:META_TVRAGE_IMPORT_KEY]]; 
     1725        [ret addEntriesFromDictionary:[ret objectForKey:META_IMDB_IMPORT_KEY]]; 
    17241726        [ret addEntriesFromDictionary:[ret objectForKey:META_XML_IMPORT_KEY]]; 
    17251727        combinedInfo = ret; 
     
    17651767        [self constructCombinedData]; 
    17661768        return [combinedInfo objectForKey:META_TITLE_KEY] ; 
     1769} 
     1770 
     1771/*! 
     1772* @brief Returns the title of the file 
     1773 * 
     1774 * @return The title of the file 
     1775 */ 
     1776- (NSString *)movieTitle 
     1777{ 
     1778        [self constructCombinedData]; 
     1779        return [combinedInfo objectForKey:META_MOVIE_TITLE_KEY] ; 
    17671780} 
    17681781 
  • trunk/SapphireMovieImporter.m

    r225 r226  
    1313 
    1414 /* IMDB XPATHS */ 
    15 #define IMDB_SEARCH_XPATH @"//td[starts-with(a/@href,'/title')]" 
    16 #define IMDB_RESULT_LINK_XPATH @"a/@href" 
    17 #define IMDB_RESULT_NAME_XPATH @"normalize-space(string())" 
     15#define IMDB_SEARCH_XPATH                               @"//td[starts-with(a/@href,'/title')]" 
     16#define IMDB_RESULT_LINK_XPATH                  @"a/@href" 
     17#define IMDB_RESULT_NAME_XPATH                  @"normalize-space(string())" 
     18#define IMDB_RESULT_TITLE_YEAR_XPATH    @"//div[@id='tn15title']/h1/replace(string(), '\n', '')" 
    1819  
    1920  
     
    2526{ 
    2627        NSString *destination; 
    27 
    28 - (id)initWithDest:(NSString *)dest; 
     28        NSArray *requestList ; 
     29         
     30
     31- (id)initWithRequest:(NSArray*)reqList withDestination:(NSString *)dest; 
     32-(void)getCoverArt ; 
    2933@end 
    3034 
     
    3337* @brief Initialize a cover art downloader 
    3438 * 
     39 * @param reqList The list of url requests to try 
    3540 * @param dest The path to save the file 
    3641 */ 
    37 - (id)initWithDest:(NSString *)dest 
     42- (id)initWithRequest:(NSArray*)reqList withDestination:(NSString *)dest; 
    3843{ 
    3944        self = [super init]; 
     
    4247         
    4348        destination = [dest retain]; 
     49        requestList = [reqList retain]; 
    4450         
    4551        return self; 
    46 
     52         
     53
     54 
     55/*! 
     56* @brief Fire the delegate to start downloading 
     57 * 
     58 */ 
     59-(void)getCoverArt 
     60
     61        NSEnumerator *reqEnum= [requestList objectEnumerator] ; 
     62        NSURLRequest *req=nil ; 
     63        while((req=[reqEnum nextObject]) !=nil) 
     64        { 
     65                NSURLDownload *currentDownload=[[NSURLDownload alloc] initWithRequest:req delegate:self] ; 
     66                [currentDownload release] ; 
     67        //      if(currentDownload)break;/*The download is going, no need to try another URL */ 
     68        } 
     69         
     70
     71 
    4772 
    4873- (void)dealloc 
    4974{ 
    5075        [destination release]; 
     76        [requestList release]; 
    5177        [super dealloc]; 
    5278} 
     
    6187- (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename 
    6288{ 
    63         [download setDestination:destination allowOverwrite:YES]; 
    64 
     89 
     90        [download setDestination:destination allowOverwrite:NO]; 
     91         
     92
     93 
     94- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error 
     95
     96        [download release]; 
     97//      NSString *failed=[[error userInfo] objectForKey:NSErrorFailingURLStringKey] ; 
     98
     99 
    65100@end 
    66101 
     
    116151 * @return A cached dictionary of the movie info 
    117152 */ 
    118 - (NSMutableDictionary *)getMetaForMovie:(NSString *)movieName 
     153- (NSMutableDictionary *)getMetaForMovie:(NSString *)movieName withPath:(NSString*)moviePath 
    119154{ 
    120155        NSError *error = nil; 
     
    123158        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.IMDB.com%@",movieName]]; 
    124159        NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:url options:NSXMLDocumentTidyHTML error:&error]; 
    125  
    126         NSString *movieTitle= [[document objectsForXQuery:@"//div[@id='tn15title']/h1/replace(string(), '\n', '')" error:&error] objectAtIndex:0]; 
     160         
     161        /* Get the movie title */ 
     162        NSString *movieTitle= [[document objectsForXQuery:IMDB_RESULT_TITLE_YEAR_XPATH error:&error] objectAtIndex:0]; 
     163        int titleYear= 0 ; 
     164        NSString *shortenedMovieTitle=nil ; 
     165        NSString *coverArtLinkA=nil ; 
     166        NSString *coverArtLinkB=nil ; 
     167        NSString *coverArtSavePath=nil ; 
     168        NSCharacterSet *decimalSet = [NSCharacterSet decimalDigitCharacterSet]; 
     169        NSCharacterSet *skipSet = [NSCharacterSet characterSetWithCharactersInString:@"("]; 
     170        NSScanner *titleScan= [NSScanner scannerWithString:movieTitle] ; 
     171         
     172        /* Cover Art Processing */ 
     173        [titleScan scanUpToCharactersFromSet:skipSet intoString:&shortenedMovieTitle]; 
     174        [titleScan scanUpToCharactersFromSet:decimalSet intoString:nil]; 
     175        [titleScan scanInt:&titleYear]; 
     176         
     177        /* Remove punctuation */ 
     178        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@":" withString:@""]; 
     179        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"'" withString:@""]; 
     180        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"," withString:@""]; 
     181        shortenedMovieTitle=[[shortenedMovieTitle stringByReplacingAllOccurancesOf:@" " withString:@"_"] lowercaseString]; 
     182         
     183        /*Convert roman to verbage*/ 
     184        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_i_"        withString:@"_one_"] ; 
     185        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_ii_"       withString:@"_two_"] ; 
     186        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_iii_"      withString:@"_three_"] ; 
     187        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_iv_"       withString:@"_four_"] ; 
     188        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_v_"        withString:@"_five_"] ; 
     189        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_1_"        withString:@"_one_"] ; 
     190        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_2_"        withString:@"_two_"] ; 
     191        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_3_"        withString:@"_three_"] ; 
     192        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_4_"        withString:@"_four_"] ; 
     193        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"_5_"        withString:@"_five_"] ; 
     194         
     195        /* Symbol Replacements */ 
     196        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"&"  withString:@"_and_"] ; 
     197        shortenedMovieTitle=[shortenedMovieTitle stringByReplacingAllOccurancesOf:@"®"  withString:@"ae"] ; 
     198                 
     199        /* Remove leading 'the' and 'a' */ 
     200        if([shortenedMovieTitle hasPrefix:@"the_"])shortenedMovieTitle=[shortenedMovieTitle substringFromIndex:4]; 
     201        else if([shortenedMovieTitle hasPrefix:@"a_"])shortenedMovieTitle=[shortenedMovieTitle substringFromIndex:2]; 
     202        coverArtLinkA=[NSString stringWithFormat:@"http://www.impawards.com/%d/posters/%@ver1.jpg",titleYear,shortenedMovieTitle] ; 
     203        coverArtLinkB=[coverArtLinkA stringByReplacingAllOccurancesOf:@"_ver1" withString:@""]; 
     204        coverArtSavePath=[[[moviePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Cover Art"] stringByAppendingPathComponent:[[[moviePath lastPathComponent] stringByDeletingPathExtension] stringByAppendingPathExtension:@"jpg"]]; 
     205        error = nil; 
     206        BOOL isDir = NO; 
     207        BOOL imageExists = [[NSFileManager defaultManager] fileExistsAtPath:coverArtSavePath isDirectory:&isDir] && !isDir; 
     208        if(!imageExists)/*Get the screen cap*/ 
     209        { 
     210                NSArray *requestURLList=[[NSArray alloc]  initWithObjects: 
     211                        [NSURLRequest requestWithURL:[NSURL URLWithString:coverArtLinkA] 
     212                                                         cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0], 
     213                        [NSURLRequest requestWithURL:[NSURL URLWithString:coverArtLinkB] 
     214                                cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0], 
     215                        nil]; 
     216                 
     217 
     218//              SapphireMovieDataMenuDownloadDelegate *myDelegate= [[SapphireMovieDataMenuDownloadDelegate alloc] initWithRequest:requestURLList withDestination:coverArtSavePath];              
     219//              [[NSFileManager defaultManager] createDirectoryAtPath:[coverArtSavePath stringByDeletingLastPathComponent] attributes:nil]; 
     220//              [myDelegate getCoverArt]; 
     221//              [[NSURLDownload alloc] initWithRequest:[requestURLList objectAtIndex:0] delegate:myDelegate]; 
     222//              [myDelegate release]; 
     223        } 
     224                 
    127225        /* Dump XML document to disk (Dev Only) */ 
    128         //NSString *documentPath =[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/XML"]; 
    129         //[[document XMLDataWithOptions:NSXMLNodePrettyPrint] writeToFile:[NSString stringWithFormat:@"/%@/%@_title_result.xml",documentPath,movieTitle] atomically:YES] ; 
    130                  
    131  
    132          
    133         [ret setObject:movieTitle forKey:META_MOVIE_TITLE]; 
     226//      NSString *documentPath =[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Sapphire/XML"]; 
     227//      [[document XMLDataWithOptions:NSXMLNodePrettyPrint] writeToFile:[NSString stringWithFormat:@"/%@/%@_title_result.xml",documentPath,movieTitle] atomically:YES] ; 
     228         
     229         
     230         
     231        /* populate metadata to return */ 
     232        [ret setObject:movieTitle forKey:META_MOVIE_TITLE_KEY]; 
    134233        return ret; 
    135234} 
    136235 
    137 /*! 
    138 * @brief Fetches the screencap URL from a show's info URL 
    139  * 
    140  * @param epUrl The show's info URL 
    141  * @return The screencap URL if it exists, nil otherwise 
    142  */ 
    143 - (NSString *)getScreencapUrl:(NSString *)epUrl 
    144 
    145         /*Get the HTML document*/ 
    146 //      NSURL *url = [NSURL URLWithString:epUrl]; 
    147 //      NSError *error = nil; 
    148 //      NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:url options:NSXMLDocumentTidyHTML error:&error]; 
    149          
    150         /*Search for a screencap*/ 
    151 //      NSXMLElement *html = [document rootElement]; 
    152 //      NSArray *caps = [html objectsForXQuery:TVRAGE_SCREEN_CAP_XPATH error:&error]; 
    153 //      if([caps count]) 
    154                 /*Found one; return it*/ 
    155 //              return [[(NSXMLElement *)[caps objectAtIndex:0] attributeForName:@"src"] stringValue]; 
    156         /*None found*/ 
    157         return nil; 
    158 
     236 
    159237 
    160238/*! 
     
    295373        } 
    296374         
    297         /*Get The Release Date*/ 
    298  
    299  
    300          
    301          
    302  
     375        /*Import the info*/ 
    303376        NSMutableDictionary *info = nil; 
    304         info = [self getMetaForMovie:movie]; 
     377        info = [self getMetaForMovie:movie withPath:path]; 
    305378        if(!info) 
    306                 return NO; 
    307          
    308          
    309         /*Import the info*/ 
     379                return NO;       
    310380        [info removeObjectForKey:LINK_KEY]; 
    311381        [metaData importInfo:info fromSource:META_IMDB_IMPORT_KEY withTime:[[NSDate date] timeIntervalSince1970]]; 
  • trunk/SapphireTVShowImporter.m

    r218 r226  
    2020#define TVRAGE_SEARCH_XPATH @"//*[@class='b1']/a" 
    2121#define TVRAGE_UNKNOWN_XPATH @"//*[contains(text(), 'Unknown Page')]" 
    22   
    23 /* IMDB XPATHS */ 
    24 #define IMDB_SEARCH_XPATH @"//td[starts-with(a/@href,'/title')]" 
    25 #define IMDB_RESULT_LINK_XPATH @"a/@href" 
    26 #define IMDB_RESULT_NAME_XPATH @"normalize-space(string())" 
    2722 
    2823#define TRANSLATIONS_KEY                @"Translations"