From cc222c5eb484f77d494d8f9d5ea251eb2be85448 Mon Sep 17 00:00:00 2001 From: Theophile Ruzicka Date: Wed, 3 May 2017 10:45:28 +0200 Subject: [PATCH] Update key for thumbnail url Prevent crashing if parts[key] returns nil --- YoutubeParser/Classes/HCYoutubeParser.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/YoutubeParser/Classes/HCYoutubeParser.m b/YoutubeParser/Classes/HCYoutubeParser.m index 079e05b..ef74769 100644 --- a/YoutubeParser/Classes/HCYoutubeParser.m +++ b/YoutubeParser/Classes/HCYoutubeParser.m @@ -159,7 +159,7 @@ + (NSDictionary *)h264videosWithYoutubeID:(NSString *)youtubeID { NSMutableDictionary *optionsDict = [NSMutableDictionary dictionary]; NSArray *keys = @[//@"author", // youtube channel name //@"avg_rating", // average ratings on yt when downloaded - @"iurl", //@"iurlmaxres", @"iurlsd", // thumbnail urls + @"thumbnail_url", //@"iurl", //@"iurlmaxres", @"iurlsd", // thumbnail urls //@"keywords", // author defined keywords @"length_seconds", // total duration in seconds @"title", // video title @@ -168,7 +168,10 @@ + (NSDictionary *)h264videosWithYoutubeID:(NSString *)youtubeID { for (NSString *key in keys) { - [optionsDict setObject:parts[key][0] forKey:key]; // [0] because we want the object and not the array + NSArray* value = parts[key]; + if (value && value.count > 0) { + [optionsDict setObject:value[0] forKey:key]; // [0] because we want the object and not the array + } } [videoDictionary setObject:optionsDict forKey:@"moreInfo"];