Skip to content

Commit

Permalink
Merge pull request #2 from wrinkleydog/imageurl_fix
Browse files Browse the repository at this point in the history
Imageurl fix
  • Loading branch information
raiym committed May 13, 2016
2 parents df4dfcf + cbc7c83 commit bdb3f91
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/InstagramScraper/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -63,10 +77,14 @@ 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);
$instance->caption = $mediaArray['caption'];
$images = self::getImageUrls($mediaArray['display_src']);
$instance->imageStandardResolutionUrl = $images['standard'];
$instance->imageLowResolutionUrl = $images['low'];
$instance->imageHighResolutionUrl = $images['high'];
$instance->imageThumbnailUrl = $images['thumbnail'];
if (isset($mediaArray['caption'])) {
$instance->caption = $mediaArray['caption'];
}
$instance->owner = Account::fromMediaPage($mediaArray['owner']);
return $instance;
}
Expand Down

0 comments on commit bdb3f91

Please sign in to comment.