Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/InstagramHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
@end

@interface IGVideo : NSObject
- (id)sortedVideoURLsBySize;
- (id)sortedVideoURLsBySize; // Before Instagram v398
- (id)allVideoURLs; // After Instagram v398
@end

@interface IGPhoto : NSObject
Expand Down
19 changes: 12 additions & 7 deletions src/Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ + (NSURL *)getPhotoUrlForMedia:(IGMedia *)media {

return [SCIUtils getPhotoUrl:photo];
}

+ (NSURL *)getVideoUrl:(IGVideo *)video {
if (!video) return nil;

// Sort videos by quality
NSArray<NSDictionary *> *sortedVideoUrls = [video sortedVideoURLsBySize];
if ([sortedVideoUrls count] < 1 || sortedVideoUrls[0] == nil) return nil;
// The past (pre v398)
if ([video respondsToSelector:@selector(sortedVideoURLsBySize)]) {
NSArray<NSDictionary *> *sorted = [video sortedVideoURLsBySize];
NSString *urlString = sorted.firstObject[@"url"];
return urlString.length ? [NSURL URLWithString:urlString] : nil;
}

// First element in array is highest quality
NSURL *videoUrl = [NSURL URLWithString:[sortedVideoUrls[0] objectForKey:@"url"]];
// The present (post v398)
if ([video respondsToSelector:@selector(allVideoURLs)]) {
return [[video allVideoURLs] anyObject];
}

return videoUrl;
// The future
return nil;
}
+ (NSURL *)getVideoUrlForMedia:(IGMedia *)media {
if (!media) return nil;
Expand Down