Skip to content

Commit

Permalink
Merge pull request jaketmp#15 from chrisridd/master
Browse files Browse the repository at this point in the history
Bunch of fixes, support B&N DRM and expiring library books
  • Loading branch information
jaketmp committed Feb 18, 2012
2 parents c7a1589 + 38bf70d commit 5a8b2b7
Show file tree
Hide file tree
Showing 16 changed files with 281 additions and 97 deletions.
3 changes: 3 additions & 0 deletions EpubTests/EpubTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
@interface EpubTests : SenTestCase {
JTPepub *untitledFile;
JTPepub *metadataFile;
JTPepub *badcontributorFile;
JTPepub *adeptFile;
JTPepub *bnFile;
JTPepub *fairplayFile;
JTPepub *koboFile;
JTPepub *libraryFile;
}
@end
106 changes: 92 additions & 14 deletions EpubTests/EpubTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "EpubTests.h"
#import "JTPepub.h"
#import "NSDate+OPF.h"

@implementation EpubTests

Expand All @@ -18,21 +19,30 @@ - (void)setUp
NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
NSString *untitled = [thisBundle pathForResource:@"Untitled" ofType:@"epub"];
NSString *metadata = [thisBundle pathForResource:@"metadata" ofType:@"epub"];
NSString *badcontributor = [thisBundle pathForResource:@"badcontributor" ofType:@"epub"];
NSString *adept = [thisBundle pathForResource:@"fake-adept" ofType:@"epub"];
NSString *bn = [thisBundle pathForResource:@"fake-bn" ofType:@"epub"];
NSString *fairplay = [thisBundle pathForResource:@"fake-fairplay" ofType:@"epub"];
NSString *kobo = [thisBundle pathForResource:@"fake-kobo" ofType:@"epub"];
NSString *library = [thisBundle pathForResource:@"fake-library" ofType:@"epub"];
untitledFile = [[JTPepub alloc] initWithFile:untitled];
metadataFile = [[JTPepub alloc] initWithFile:metadata];
badcontributorFile = [[JTPepub alloc] initWithFile:badcontributor];
adeptFile = [[JTPepub alloc] initWithFile:adept];
bnFile = [[JTPepub alloc] initWithFile:bn];
fairplayFile = [[JTPepub alloc] initWithFile:fairplay];
koboFile = [[JTPepub alloc] initWithFile:kobo];
libraryFile = [[JTPepub alloc] initWithFile:library];
}

- (void)tearDown
{
[libraryFile release];
[koboFile release];
[fairplayFile release];
[bnFile release];
[adeptFile release];
[badcontributorFile release];
[metadataFile release];
[untitledFile release];

Expand All @@ -43,29 +53,29 @@ - (void)testTitle
{
NSString *actual = [untitledFile title];
NSString *expected = @"Test Document";
STAssertEqualObjects(actual, expected, @"Title should be %@ but is %@", actual, expected);
STAssertEqualObjects(actual, expected, @"title is wrong");
}

- (void)testTitleWithAmpersand
{
NSString *actual = [metadataFile title];
NSString *expected = @"This & That";
STAssertEqualObjects(actual, expected, @"Title should be %@ but is %@", actual, expected);
STAssertEqualObjects(actual, expected, @"title is wrong");
}

- (void)testAuthors
{
NSArray *actual = [untitledFile authors];
NSString *expected = @"Test Author";
STAssertTrue([actual count] == 1, @"1 author expected");
STAssertEqualObjects([actual lastObject], expected, @"Author should be %@ but is %@", [actual lastObject], expected);
STAssertEqualObjects([actual lastObject], expected, @"author is wrong");
}

- (void)testISBN
{
NSString *actual = [untitledFile isbn];
NSString *expected = @"123456789";
STAssertEqualObjects(actual, expected, @"ISBN should be %@ but is %@", actual, expected);
STAssertEqualObjects(actual, expected, @"ISBN is wrong");
}

- (void)testDate
Expand All @@ -74,23 +84,23 @@ - (void)testDate
timeZone:nil
locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]];
NSString *expected = @"2011";
STAssertEqualObjects(actual, expected, @"Date should be %@ but is %@", actual, expected);
STAssertEqualObjects(actual, expected, @"date is wrong");
}

- (void)testTranslator
{
NSArray *actual = [untitledFile translators];
NSString *expected = @"Test Translator";
STAssertTrue([actual count] == 1, @"1 translator expected");
STAssertEqualObjects([actual lastObject], expected, @"Translator should be %@ but is %@", [actual lastObject], expected);
STAssertEqualObjects([actual lastObject], expected, @"translator is wrong");
}

- (void)testIllustrator
{
NSArray *actual = [untitledFile illustrators];
NSString *expected = @"Test Illustrator";
STAssertTrue([actual count] == 1, @"1 illustrator expected");
STAssertEqualObjects([actual lastObject], expected, @"Illustrator should be %@ but is %@", [actual lastObject], expected);
STAssertEqualObjects([actual lastObject], expected, @"illustrator is wrong");
}

- (void)testThreeAuthors
Expand All @@ -100,36 +110,104 @@ - (void)testThreeAuthors
NSString *expected1 = @"Second Author";
NSString *expected2 = @"Third Author";
STAssertTrue([actual count] == 3, @"3 authors expected");
STAssertEqualObjects([actual objectAtIndex:0], expected0, @"First author should be %@ but is %@", [actual objectAtIndex:0], expected0);
STAssertEqualObjects([actual objectAtIndex:1], expected1, @"Second author should be %@ but is %@", [actual objectAtIndex:1], expected1);
STAssertEqualObjects([actual objectAtIndex:2], expected2, @"Third author should be %@ but is %@", [actual objectAtIndex:2], expected2);
STAssertEqualObjects([actual objectAtIndex:0], expected0, @"First author is wrong");
STAssertEqualObjects([actual objectAtIndex:1], expected1, @"Second author is wrong");
STAssertEqualObjects([actual objectAtIndex:2], expected2, @"Third author is wrong");
}

-(void)testNoDRM
#pragma mark Test date parsing
- (void)testDateParsing
{
NSDate *d;
NSArray *goodDates = [NSArray arrayWithObjects:
@"2012", @"2012-02", @"2012-02-13",
@"2012-02-13T19:49Z",
@"2012-02-13T19:49+0100",
nil];
for (id date in goodDates) {
d = [NSDate dateFromOPFString:date];
STAssertNotNil(d, @"%@ should parse", date);
}

}

#pragma mark Test lack of opf:role
- (void)testBadContributor
{
NSArray *actual = [badcontributorFile translators];
STAssertTrue([actual count] == 0, @"No translators expected");
}

- (void)testBadAuthor
{
NSArray *actual = [badcontributorFile authors];
STAssertTrue([actual count] == 1, @"1 author expected");
}

#pragma mark Test DRM
- (void)testNoDRM
{
NSString *actual = [untitledFile drm];
NSString *expected = @"";
STAssertEqualObjects(actual, expected, @"Untitled file has wrong DRM");
}

-(void)testAdobeDRM
- (void)testAdobeDRM
{
NSString *actual = [adeptFile drm];
NSString *expected = @"Adobe";
STAssertEqualObjects(actual, expected, @"fake-adept file has wrong DRM");
}

-(void)testAppleDRM
- (void)testBarnesAndNobleDRM
{
NSString *actual = [bnFile drm];
NSString *expected = @"Barnes & Noble";
STAssertEqualObjects(actual, expected, @"fake-bn file has wrong DRM");
}

- (void)testAppleDRM
{
NSString *actual = [fairplayFile drm];
NSString *expected = @"Apple";
STAssertEqualObjects(actual, expected, @"fake-fairplay file has wrong DRM");
}

-(void)testKoboDRM
- (void)testKoboDRM
{
NSString *actual = [koboFile drm];
NSString *expected = @"Kobo";
STAssertEqualObjects(actual, expected, @"fake-kobo file has wrong DRM");
}

- (void)testUnexpiringAdobe
{
NSDate *actual = [adeptFile expiryDate];
STAssertNil(actual, @"fake-adept should not expire");
}

- (void)testUnexpiringApple
{
NSDate *actual = [fairplayFile expiryDate];
STAssertNil(actual, @"fake-fairplay should not expire");
}

- (void)testExpiringAdobe
{
NSDate *actual = [libraryFile expiryDate];
STAssertNotNil(actual, @"fake-library does not expire");
}

#pragma mark Test covers
- (void)testUntitledCover
{
NSImage *actual = [untitledFile cover];
STAssertNotNil(actual, @"Cover not found");
}

- (void)testMissingCover
{
NSImage *actual = [metadataFile cover];
STAssertNil(actual, @"Cover not missing");
}
@end
File renamed without changes.
Binary file added EpubTests/badcontributor.epub
Binary file not shown.
Binary file added EpubTests/fake-bn.epub
Binary file not shown.
Binary file added EpubTests/fake-library.epub
Binary file not shown.
File renamed without changes.
6 changes: 3 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Designed to extract the cover images from ePub files to use as the file icon, an

This generator reads the various parameters directly from the ePub contents - so it will work on books that haven't been imported into iTunes.

**Note**: When used on DRM protected files (Adobe ADEPT or iBooks Fairplay), metadata will only be read from the unencrypted part of the ePub. Typically this means no cover image will be shown.
**Note**: When used on DRM protected files (Adobe, iBooks, Kobo, Barnes & Noble), metadata will only be read from the unencrypted part of the ePub. Typically this means no cover image will be shown.

## Installation

Place the ePub.quicklook generator file into `/Library/QuickLook` (for all users) or `~/Library/QuickLook` (for the current user only).
Place the ePub.qlgenerator file into `/Library/QuickLook` (for all users) or `~/Library/QuickLook` (for the current user only).

### Conflict with other quicklook generators

Under some circumstances, epub.quicklook can conflict with other quicklook generators (notably BetterZipQL under OS X 10.6 and earlier). To fix this, rename epub.quicklook to come before the conflicting plugin alphabetically (AA_epub.quicklook should work).
Under some circumstances, epub.qlgenerator can conflict with other quicklook generators (notably BetterZipQL under OS X 10.6 and earlier). To fix this, rename epub.qlgenerator to come before the conflicting plugin alphabetically (AA_epub.qlgenerator should work).
Loading

0 comments on commit 5a8b2b7

Please sign in to comment.