Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pieter/59972 to your computer and use it in GitHub Desktop.
Save pieter/59972 to your computer and use it in GitHub Desktop.
From 0de093d9c5b89ef24bd3b88453f0f77225ef9e29 Mon Sep 17 00:00:00 2001
From: Pieter de Bie <pdebie@ai.rug.nl>
Date: Sat, 7 Feb 2009 18:42:07 +0000
Subject: [PATCH] Load Youtube movies as MP4 files in quicktime
---
Plugin/Plugin.m | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/Plugin/Plugin.m b/Plugin/Plugin.m
index 2879d66..61a323c 100644
--- a/Plugin/Plugin.m
+++ b/Plugin/Plugin.m
@@ -44,6 +44,7 @@ static NSString *sCTFWhitelistAdditionMade = @"CTFWhitelistAdditionMade";
- (void) _removeHostFromWhitelist;
- (void) _askToAddCurrentSiteToWhitelist;
- (void) _whitelistAdditionMade: (NSNotification*) note;
+- (void) _replaceWithYouTubeID:(NSString *)videoID T:(NSString *)t Arguments:(NSDictionary *)args;
@end
@@ -75,6 +76,27 @@ static NSString *sCTFWhitelistAdditionMade = @"CTFWhitelistAdditionMade";
_isLoadingFromWhitelist = YES;
[self performSelector:@selector(_convertTypesForContainer) withObject:nil afterDelay:0];
}
+ if ([self.host isEqualToString:@"www.youtube.com"])
+ {
+ NSString *flashArgs = [[arguments objectForKey:WebPlugInAttributesKey] objectForKey:@"flashvars"];
+ NSUInteger index = [[base description] rangeOfString:@"?v="].location;
+
+ if (flashArgs && index != NSNotFound)
+ {
+
+ NSString *videoID = [[base description] substringFromIndex:index + 3];
+ NSArray *args = [flashArgs componentsSeparatedByString:@"&"];
+ NSString *t;
+
+ for (NSString *arg in args)
+ {
+ if ([arg hasPrefix:@"t="])
+ t = [arg substringFromIndex:2];
+ }
+ if (t)
+ [self _replaceWithYouTubeID:videoID T:t Arguments:[arguments objectForKey:WebPlugInAttributesKey]];
+ }
+ }
}
if (![NSBundle loadNibNamed:@"ContextualMenu" owner:self])
@@ -480,6 +502,28 @@ static NSString *sCTFWhitelistAdditionMade = @"CTFWhitelistAdditionMade";
self.container = nil;
}
+- (void) _replaceWithYouTubeID:(NSString *)videoID T:(NSString *)t Arguments:(NSDictionary *)args
+{
+ NSLog(@"container: %@", self.container);
+ id height = [args objectForKey:@"height"];
+ if (!height)
+ height = @"385";
+ id width = [args objectForKey:@"width"];
+ if (!width)
+ width = @"480";
+
+ NSString *url = [NSString stringWithFormat:@"http://www.youtube.com/get_video?fmt=18&video_id=%@&t=%@", videoID, t];
+
+ NSString *embedText = [NSString stringWithFormat:@"<embed type='video/quicktime' src='%@', pluginspage='http://www.apple.com/quicktime/download/'"
+ "scale='aspect' cache='False' width='%@' height='%@' autoplay='True' />", url, width, height];
+
+ // Just to be safe, since we are about to replace our containing element
+ [[self.container retain] autorelease];
+
+ // This is dirty but easy
+ [self.container.parentNode setInnerHTML: embedText];
+ self.container = nil;
+}
@synthesize container = _container;
@synthesize host = _host;
--
1.6.1.2.458.g9de76+GitX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment