Skip to content

Commit

Permalink
Respect the use video preference.
Browse files Browse the repository at this point in the history
  • Loading branch information
ssp committed Oct 4, 2009
1 parent f61aabd commit 9efe8dd
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 38 deletions.
9 changes: 5 additions & 4 deletions Plugin/CTFKiller.m
Expand Up @@ -37,15 +37,15 @@ @implementation CTFKiller


// Class method returns an instantiated CTFKiller class for the URL/data/plugin passed to it. This is the call to use.
+ (CTFKiller*) killerForURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) attributes forPlugin:(CTFClickToFlashPlugin*) thePlugin {
+ (CTFKiller*) killerForURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) theAttributes forPlugin:(CTFClickToFlashPlugin*) thePlugin {
CTFKiller * theKiller = nil;

NSArray * killerArray = [NSArray arrayWithObjects: NSClassFromString(@"CTFKillerYouTube"), NSClassFromString(@"CTFKillerVimeo"), NSClassFromString(@"CTFKillerSIFR"),nil];
NSEnumerator * myEnum = [killerArray objectEnumerator];
Class killerClass;
while ((killerClass = [myEnum nextObject])) {
if ([killerClass canHandleFlashAtURL: theURL src: theSrc attributes: attributes forPlugin: thePlugin]) {
theKiller = [[(CTFKiller*)[killerClass alloc] initWithURL:theURL src: theSrc attributes: attributes forPlugin: thePlugin] autorelease];
if ([killerClass canHandleFlashAtURL: theURL src: theSrc attributes: theAttributes forPlugin: thePlugin]) {
theKiller = [[(CTFKiller*)[killerClass alloc] initWithURL:theURL src: theSrc attributes: theAttributes forPlugin: thePlugin] autorelease];
break;
}
}
Expand All @@ -54,6 +54,7 @@ + (CTFKiller*) killerForURL: (NSURL*) theURL src: (NSString*) theSrc attributes:
}



// Initialiser method doing the basic setup. There should be no need to use this. The +killerForULR:src:attributes:forPlugin class method should handle everything.
- (id) initWithURL: (NSURL*) theURL src:(NSString*) theSrc attributes: (NSDictionary*) theAttributes forPlugin:(CTFClickToFlashPlugin*) thePlugin {
self = [super init];
Expand Down Expand Up @@ -90,7 +91,7 @@ - (void) dealloc {
#pragma mark Subclass overrides

// Return whether this class can handle the Flash for the given URL and other data.
+ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) attributes forPlugin:(CTFClickToFlashPlugin*) thePlugin {
+ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) theAttributes forPlugin:(CTFClickToFlashPlugin*) thePlugin {
return NO;
}

Expand Down
9 changes: 4 additions & 5 deletions Plugin/CTFKillerVideo.h
Expand Up @@ -28,11 +28,6 @@
#import <Cocoa/Cocoa.h>
#import "CTFKiller.h"

static NSString *sUseYouTubeH264DefaultsKey = @"useYouTubeH264";
static NSString *sUseYouTubeHDH264DefaultsKey = @"useYouTubeHDH264";
static NSString *sYouTubeAutoPlay = @"enableYouTubeAutoPlay";


@class DOMElement;

enum CTFKVLookupStatus {
Expand Down Expand Up @@ -90,6 +85,10 @@ enum CTFKVLookupStatus {




// Helper
+ (BOOL) isActive;

// Actions
- (IBAction) loadVideo:(id)sender;
- (IBAction) loadVideoSD:(id)sender;
Expand Down
13 changes: 11 additions & 2 deletions Plugin/CTFKillerVideo.m
Expand Up @@ -33,6 +33,9 @@ of this software and associated documentation files (the "Software"), to deal

static NSString * divCSS = @"margin:auto;padding:0px;border:0px none;text-align:center;display:block;float:none;";
static NSString * sDisableVideoElement = @"disableVideoElement";
static NSString * sUseYouTubeH264DefaultsKey = @"useYouTubeH264";
static NSString * sUseYouTubeHDH264DefaultsKey = @"useYouTubeHDH264";
static NSString * sYouTubeAutoPlay = @"enableYouTubeAutoPlay";


@implementation CTFKillerVideo
Expand Down Expand Up @@ -126,6 +129,12 @@ - (NSString *) cleanURLString: (NSString*) URLString {
}


// Helper method used by subclasses to determine whether we want to handle video without Flash.
+ (BOOL) isActive {
BOOL result = [[CTFUserDefaultsController standardUserDefaults] boolForKey: sUseYouTubeH264DefaultsKey];
return result;
}




Expand Down Expand Up @@ -379,7 +388,7 @@ - (void) _convertElementForMP4: (DOMElement*) element atURL: (NSString*) URLStri
[ element setAttribute: @"src" value: URLString ];
[ element setAttribute: @"type" value: @"video/mp4" ];
[ element setAttribute: @"scale" value: @"aspect" ];
if (autoPlay) {
if ([self autoPlay]) {
[ element setAttribute: @"autoplay" value: @"true" ];
} else {
[ element setAttribute: @"autoplay" value: @"false" ];
Expand All @@ -395,7 +404,7 @@ - (void) _convertElementForVideoElement: (DOMElement*) element atURL: (NSString*
{
[ element setAttribute: @"src" value: URLString ];
[ element setAttribute: @"autobuffer" value:@"autobuffer"];
if (autoPlay) {
if ([self autoPlay]) {
[ element setAttribute: @"autoplay" value:@"autoplay" ];
} else {
if ( [element hasAttribute:@"autoplay"] )
Expand Down
15 changes: 9 additions & 6 deletions Plugin/CTFKillerVimeo.m
Expand Up @@ -36,14 +36,16 @@ @implementation CTFKillerVimeo

#pragma mark CTFKiller subclass overrides

+ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) attributes forPlugin:(CTFClickToFlashPlugin*) thePlugin {
+ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) theAttributes forPlugin:(CTFClickToFlashPlugin*) thePlugin {
BOOL result = NO;

result = result || ([theSrc rangeOfString:@"/moogaloop" options:NSAnchoredSearch].location != NSNotFound);

NSURL * srcURL = [NSURL URLWithString: theSrc];
if (srcURL != nil && [srcURL host] != nil) {
result = result || ([[srcURL host] rangeOfString:@"vimeo.com" options:NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound);
if ([CTFKillerVideo isActive]) {
result = ([theSrc rangeOfString:@"/moogaloop" options:NSAnchoredSearch].location != NSNotFound);

NSURL * srcURL = [NSURL URLWithString: theSrc];
if (srcURL != nil && [srcURL host] != nil) {
result = result || ([[srcURL host] rangeOfString:@"vimeo.com" options:NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound);
}
}

return result;
Expand Down Expand Up @@ -80,6 +82,7 @@ - (void) setup {
}



- (void) dealloc {
[self setClipID: nil];
[self setClipSignature: nil];
Expand Down
44 changes: 23 additions & 21 deletions Plugin/CTFKillerYouTube.m
Expand Up @@ -35,29 +35,31 @@ @implementation CTFKillerYouTube

#pragma mark CTFKiller subclassing overrides

+ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) attributes forPlugin:(CTFClickToFlashPlugin*) thePlugin {
+ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) theAttributes forPlugin:(CTFClickToFlashPlugin*) thePlugin {
BOOL result = NO;

if (theSrc != nil) {
NSURL * srcURL = [NSURL URLWithString: theSrc];
NSString * host = [srcURL host];
if (host != nil ) {
result = result
|| ( [host rangeOfString: @"youtube.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound )
|| ( [host rangeOfString: @"youtube-nocookie.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound )
|| ( [host rangeOfString: @"ytimg.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound );
}
}

if (!result) {
NSString* fV = [attributes objectForKey: @"flashvars" ];
if (fV != nil) {
NSDictionary * flashVars = [CTFClickToFlashPlugin flashVarDictionary:fV];
NSString * URLString = [flashVars objectForKey:@"rv.0.url"];
if (URLString != nil) {
result = result || ([URLString rangeOfString: @"youtube.com"].location != NSNotFound )
|| ([URLString rangeOfString: @"youtube-nocookie.com"].location != NSNotFound );
}
if ([CTFKillerVideo isActive]) {
if (theSrc != nil) {
NSURL * srcURL = [NSURL URLWithString: theSrc];
NSString * host = [srcURL host];
if (host != nil ) {
result = result
|| ( [host rangeOfString: @"youtube.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound )
|| ( [host rangeOfString: @"youtube-nocookie.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound )
|| ( [host rangeOfString: @"ytimg.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound );
}
}

if (!result) {
NSString* fV = [theAttributes objectForKey: @"flashvars" ];
if (fV != nil) {
NSDictionary * flashVars = [CTFClickToFlashPlugin flashVarDictionary:fV];
NSString * URLString = [flashVars objectForKey:@"rv.0.url"];
if (URLString != nil) {
result = result || ([URLString rangeOfString: @"youtube.com"].location != NSNotFound )
|| ([URLString rangeOfString: @"youtube-nocookie.com"].location != NSNotFound );
}
}
}
}

Expand Down

0 comments on commit 9efe8dd

Please sign in to comment.