From a92d7009bc8b546f9553d320c7612e945c2140ea Mon Sep 17 00:00:00 2001 From: wrinkleydog Date: Thu, 12 May 2016 17:09:16 -0600 Subject: [PATCH 1/3] get proper imageurls in fromMediaPage function --- src/InstagramScraper/Media.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/InstagramScraper/Media.php b/src/InstagramScraper/Media.php index a42c5ac5..68bfca7a 100644 --- a/src/InstagramScraper/Media.php +++ b/src/InstagramScraper/Media.php @@ -51,6 +51,20 @@ private static function getCleanImageUrl($imageUrl) return strpos($imageUrl, '?ig_cache_key=') ? substr($imageUrl, 0, strpos($imageUrl, '?ig_cache_key=')) : $imageUrl; } + private static function getImageUrls($imageUrl) { + $imageUrl = self::getCleanImageUrl($imageUrl); + $parts = explode('/', parse_url($imageUrl)['path']); + $standard = 'https://scontent.cdninstagram.com/'.$parts[1].'/s640x640/'.$parts[2].'/'.$parts[3]; + $urls = [ + 'standard' => $standard, + 'low' => str_replace('640x640', '320x320', $standard), + 'high' => str_replace('640x640', '1080x1080', $standard), + 'thumbnail' => str_replace('640x640', '150x150', $standard) + ]; + return $urls; + } + + public static function fromMediaPage($mediaArray) { $instance = new self(); @@ -63,9 +77,11 @@ public static function fromMediaPage($mediaArray) $instance->createdTime = $mediaArray['date']; $instance->code = $mediaArray['code']; $instance->link = Instagram::INSTAGRAM_URL . 'p/' . $instance->code; - $instance->imageStandardResolutionUrl = self::getCleanImageUrl($mediaArray['display_src']); - $instance->imageLowResolutionUrl = str_replace('640x640', '320x320', $instance->imageStandardResolutionUrl); - $instance->imageHighResolutionUrl = str_replace('640x640', '1080x1080', $instance->imageStandardResolutionUrl); + $images = self::getImageUrls($mediaArray['display_src']); + $instance->imageStandardResolutionUrl = $images['standard']; + $instance->imageLowResolutionUrl = $images['low']; + $instance->imageHighResolutionUrl = $images['high']; + $instance->imageThumbnailUrl = $images['thumbnail']; $instance->caption = $mediaArray['caption']; $instance->owner = Account::fromMediaPage($mediaArray['owner']); return $instance; From 289b82aafa3117cf2d36244af996da49e39fbe85 Mon Sep 17 00:00:00 2001 From: wrinkleydog Date: Thu, 12 May 2016 17:09:54 -0600 Subject: [PATCH 2/3] Only set caption in the event it exists... --- src/InstagramScraper/Media.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/InstagramScraper/Media.php b/src/InstagramScraper/Media.php index 68bfca7a..e7706383 100644 --- a/src/InstagramScraper/Media.php +++ b/src/InstagramScraper/Media.php @@ -82,7 +82,9 @@ public static function fromMediaPage($mediaArray) $instance->imageLowResolutionUrl = $images['low']; $instance->imageHighResolutionUrl = $images['high']; $instance->imageThumbnailUrl = $images['thumbnail']; - $instance->caption = $mediaArray['caption']; + if (isset($mediaArray['caption'])) { + $instance->caption = $mediaArray['caption']['text']; + } $instance->owner = Account::fromMediaPage($mediaArray['owner']); return $instance; } From cbc7c83dbcf2282dbbf58c7d8bebbd6bc064d5d4 Mon Sep 17 00:00:00 2001 From: wrinkleydog Date: Thu, 12 May 2016 17:50:13 -0600 Subject: [PATCH 3/3] fix comment index --- src/InstagramScraper/Media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/InstagramScraper/Media.php b/src/InstagramScraper/Media.php index e7706383..b3b7662e 100644 --- a/src/InstagramScraper/Media.php +++ b/src/InstagramScraper/Media.php @@ -83,7 +83,7 @@ public static function fromMediaPage($mediaArray) $instance->imageHighResolutionUrl = $images['high']; $instance->imageThumbnailUrl = $images['thumbnail']; if (isset($mediaArray['caption'])) { - $instance->caption = $mediaArray['caption']['text']; + $instance->caption = $mediaArray['caption']; } $instance->owner = Account::fromMediaPage($mediaArray['owner']); return $instance;