Skip to content

Commit 880c17b

Browse files
authored
Merge pull request #12 from SDWebImage/feature_disable_video_resource
Add a option to disable video resource to fetch
2 parents 0ae46b8 + 2ac5bce commit 880c17b

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

SDWebImageLinkPlugin/Classes/SDImageLinkLoader.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
@property (class, readonly, nonnull) SDImageLinkLoader *sharedLoader;
2020

2121
/// The time interval after which the request automatically fails if it hasn’t already completed. Defaults to 30 seconds.
22-
@property(nonatomic) NSTimeInterval timeout;
22+
@property (nonatomic) NSTimeInterval timeout;
2323

2424
/// A Boolean value indicating whether to download subresources specified by the metadata. Defaults to YES.
25-
@property(nonatomic) BOOL shouldFetchSubresources;
25+
@property (nonatomic) BOOL shouldFetchSubresources;
26+
27+
/// A Boolean valud indicating whether to fetch any video resource (like `remoteVideoURL` or `videoProvider`). Defaults to YES. Change this to NO if you don't want video resource.
28+
@property (nonatomic) BOOL shouldfetchVideoResources;
2629

2730
@end

SDWebImageLinkPlugin/Classes/SDImageLinkLoader.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ - (instancetype)init {
5252
if (self) {
5353
self.timeout = 30;
5454
self.shouldFetchSubresources = YES;
55+
self.shouldfetchVideoResources = YES;
5556
}
5657
return self;
5758
}
@@ -155,7 +156,7 @@ - (void)fetchImageDataWithProvider:(NSItemProvider *)imageProvider metadata:(LPL
155156
error = [NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorBadImageData userInfo:nil];
156157
} else {
157158
// The original metadata contains image data and is large, we pick the metadata info only to avoid double cache of image
158-
LPLinkMetadata *strippedMetadata = [self.class strippedMetadata:metadata];
159+
LPLinkMetadata *strippedMetadata = [self strippedMetadata:metadata];
159160
// Save the metadata to extended data
160161
image.sd_extendedObject = strippedMetadata;
161162
}
@@ -198,7 +199,7 @@ - (void)fetchImageWithProvider:(NSItemProvider *)imageProvider metadata:(LPLinkM
198199
error = [NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorBadImageData userInfo:nil];
199200
} else {
200201
// The original metadata contains image data and is large, we pick the metadata info only to avoid double cache of image
201-
LPLinkMetadata *strippedMetadata = [self.class strippedMetadata:metadata];
202+
LPLinkMetadata *strippedMetadata = [self strippedMetadata:metadata];
202203
// Save the metadata to extended data
203204
image.sd_extendedObject = strippedMetadata;
204205
}
@@ -224,13 +225,15 @@ - (BOOL)shouldBlockFailedURLWithURL:(NSURL *)url error:(NSError *)error {
224225
}
225226

226227
#pragma mark - Util
227-
+ (LPLinkMetadata *)strippedMetadata:(LPLinkMetadata *)originalMetadata {
228+
- (LPLinkMetadata *)strippedMetadata:(LPLinkMetadata *)originalMetadata {
228229
NSCParameterAssert(originalMetadata);
229230
LPLinkMetadata *metadata = [LPLinkMetadata new];
230231
metadata.URL = originalMetadata.URL;
231232
metadata.originalURL = originalMetadata.originalURL;
232233
metadata.title = originalMetadata.title;
233-
metadata.remoteVideoURL = originalMetadata.remoteVideoURL;
234+
if (self.shouldfetchVideoResources) {
235+
metadata.remoteVideoURL = originalMetadata.remoteVideoURL;
236+
}
234237
return metadata;
235238
}
236239

0 commit comments

Comments
 (0)