@@ -69,6 +69,7 @@ - (void) _loadContent: (NSNotification*) notification;
69
69
- (void ) _loadContentForWindow : (NSNotification *) notification ;
70
70
71
71
- (NSDictionary *) _flashVarDictionary : (NSString *) flashvarString ;
72
+ - (NSDictionary *) _flashVarDictionaryFromYouTubePageHTML : (NSString *) youTubePageHTML ;
72
73
- (NSString *) flashvarWithName : (NSString *) argName ;
73
74
- (BOOL ) _hasH264Version ;
74
75
- (BOOL ) _useH264Version ;
@@ -169,7 +170,9 @@ - (id) initWithArguments:(NSDictionary *)arguments
169
170
if (videoId != nil ) {
170
171
[self setVideoId: videoId];
171
172
} else {
172
- // scrub the URL to determine the video_id
173
+ // it's an embedded YouTube flash view; scrub the URL to
174
+ // determine the video_id, then get the source of the YouTube
175
+ // page to get the Flash vars
173
176
174
177
NSString *videoIdFromURL = nil ;
175
178
NSScanner *URLScanner = [[NSScanner alloc ] initWithString: [self src ]];
@@ -181,6 +184,16 @@ - (id) initWithArguments:(NSDictionary *)arguments
181
184
if (videoIdFromURL) [self setVideoId: videoIdFromURL];
182
185
}
183
186
[URLScanner release ];
187
+
188
+ if (videoIdFromURL) {
189
+ NSString *URLString = [NSString stringWithFormat: @" http://youtube.com/watch?v=%@ " ,videoIdFromURL];
190
+ NSURL *YouTubePageURL = [NSURL URLWithString: URLString];
191
+ NSError *pageSourceError = nil ;
192
+ NSString *pageSourceString = [NSString stringWithContentsOfURL: YouTubePageURL
193
+ usedEncoding: nil
194
+ error: &pageSourceError];
195
+ if (! pageSourceError) _flashVars = [[self _flashVarDictionaryFromYouTubePageHTML: pageSourceString] retain ];
196
+ }
184
197
}
185
198
}
186
199
@@ -925,6 +938,49 @@ - (NSDictionary*) _flashVarDictionary: (NSString*) flashvarString
925
938
return flashVarsDictionary;
926
939
}
927
940
941
+ - (NSDictionary *) _flashVarDictionaryFromYouTubePageHTML: (NSString *) youTubePageHTML
942
+ {
943
+ NSMutableDictionary * flashVarsDictionary = [ NSMutableDictionary dictionary ];
944
+ NSScanner *HTMLScanner = [[NSScanner alloc ] initWithString: youTubePageHTML];
945
+
946
+ [HTMLScanner scanUpToString: @" var swfArgs = {" intoString: nil ];
947
+ BOOL swfArgsFound = [HTMLScanner scanString: @" var swfArgs = {" intoString: nil ];
948
+
949
+ if (swfArgsFound) {
950
+ NSString *swfArgsString = nil ;
951
+ [HTMLScanner scanUpToString: @" }" intoString: &swfArgsString];
952
+ NSArray *arrayOfSWFArgs = [swfArgsString componentsSeparatedByString: @" , " ];
953
+ CTFForEachObject ( NSString , currentArgPairString, arrayOfSWFArgs ) {
954
+ NSRange sepRange = [ currentArgPairString rangeOfString: @" : " ];
955
+ if (sepRange.location != NSNotFound ) {
956
+ NSString *potentialKey = [currentArgPairString substringToIndex: sepRange.location];
957
+ NSString *potentialVal = [currentArgPairString substringFromIndex: NSMaxRange (sepRange)];
958
+
959
+ // we might need to strip the surrounding quotes from the keys and values
960
+ // (but not always)
961
+ NSString *key = nil ;
962
+ if ([[potentialKey substringToIndex: 1 ] isEqualToString: @" \" " ]) {
963
+ key = [potentialKey substringWithRange: NSMakeRange (1 ,[potentialKey length ] - 2 )];
964
+ } else {
965
+ key = potentialKey;
966
+ }
967
+
968
+ NSString *val = nil ;
969
+ if ([[potentialVal substringToIndex: 1 ] isEqualToString: @" \" " ]) {
970
+ val = [potentialVal substringWithRange: NSMakeRange (1 ,[potentialVal length ] - 2 )];
971
+ } else {
972
+ val = potentialVal;
973
+ }
974
+
975
+ [flashVarsDictionary setObject: val forKey: key];
976
+ }
977
+ }
978
+ }
979
+
980
+ [HTMLScanner release ];
981
+ return flashVarsDictionary;
982
+ }
983
+
928
984
- (NSString *) flashvarWithName: (NSString *) argName
929
985
{
930
986
return [ _flashVars objectForKey: argName ];
@@ -1073,7 +1129,6 @@ - (IBAction)openFullscreenInQTPlayer:(id)sender;
1073
1129
1074
1130
NSString *scriptSource = [NSString stringWithFormat:
1075
1131
@" tell application \" QuickTime Player\"\n activate\n getURL \" %@ \"\n repeat while (display state of front document is not presentation)\n delay 1\n present front document scale screen\n end repeat\n repeat while (playing of front document is false)\n delay 1\n play front document\n end repeat\n end tell" ,src];
1076
- NSLog (@" %@ " ,scriptSource);
1077
1132
NSAppleScript *openInQTPlayerScript = [[NSAppleScript alloc ] initWithSource: scriptSource];
1078
1133
[openInQTPlayerScript executeAndReturnError: nil ];
1079
1134
[openInQTPlayerScript release ];
0 commit comments