From b1d056e227fc8e805f4a2e71d3f07f0252b928f7 Mon Sep 17 00:00:00 2001 From: shc Date: Wed, 30 Jul 2014 16:39:41 +0200 Subject: [PATCH] ASIWebPageRequest excluded more multimedia formats from fetching ( for now: ogg,ogg,webm,mp4,avi,mpg,mpeg,mkv ) [ASIWebPageRequest addURLToFetch:] now doing percent escaping URLs strings [ASIWebPageRequest contentForExternalURL:] now doing the same URL strings transforms matching these in [ASIWebPageRequest addURLToFetch:] --- Classes/ASIWebPageRequest/ASIWebPageRequest.m | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Classes/ASIWebPageRequest/ASIWebPageRequest.m b/Classes/ASIWebPageRequest/ASIWebPageRequest.m index eccac6a8..12c4da18 100644 --- a/Classes/ASIWebPageRequest/ASIWebPageRequest.m +++ b/Classes/ASIWebPageRequest/ASIWebPageRequest.m @@ -471,10 +471,25 @@ - (void)readResourceURLs } // Parse the content of tags (HTML 5 audio + video) - // We explictly disable the download of files with .webm, .ogv and .ogg extensions, since it's highly likely they won't be useful to us - } else if ([[parentName lowercaseString] isEqualToString:@"source"] || [[parentName lowercaseString] isEqualToString:@"audio"]) { + // We explictly disable the download of files with extensions .webm,.ogv,.ogg,.mp4,.avi,.mpg,.mpeg and .mkv extensions, since it's highly likely they won't be useful to us + } else if ([[parentName lowercaseString] isEqualToString:@"source"] || [[parentName lowercaseString] isEqualToString:@"audio"] || [[parentName lowercaseString] isEqualToString:@"video"]) { + NSString *fileExtension = [[value pathExtension] lowercaseString]; - if (![fileExtension isEqualToString:@"ogg"] && ![fileExtension isEqualToString:@"ogv"] && ![fileExtension isEqualToString:@"webm"]) { + + static NSSet *exludedExtensions = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + exludedExtensions = [[NSSet setWithArray:@[ @"ogg" + , @"ogv" + , @"webm" + , @"mp4" + , @"avi" + , @"mpg" + , @"mpeg" + , @"mkv" ]] retain]; + }); + + if ( ![exludedExtensions containsObject:fileExtension] ) { [self addURLToFetch:value]; } @@ -495,6 +510,9 @@ - (void)addURLToFetch:(NSString *)newURL { // Get rid of any surrounding whitespace newURL = [newURL stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + // percent escape characters + newURL = [newURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + // Don't attempt to fetch data URIs if ([newURL length] > 4) { if (![[[newURL substringToIndex:5] lowercaseString] isEqualToString:@"data:"]) { @@ -676,6 +694,11 @@ - (NSString *)relativePathTo:(NSString *)destinationPath fromPath:(NSString *)so - (NSString *)contentForExternalURL:(NSString *)theURL { + // Get rid of any surrounding whitespace + theURL = [theURL stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + // percent escape characters + theURL = [theURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + if ([self urlReplacementMode] == ASIReplaceExternalResourcesWithLocalURLs) { NSString *resourcePath = [[resourceList objectForKey:theURL] objectForKey:@"DataPath"]; return [self relativePathTo:resourcePath fromPath:[self downloadDestinationPath]];