Skip to content

Commit

Permalink
Merge pull request #266 from koninka/master
Browse files Browse the repository at this point in the history
Add sidecar images for 'sidecar' media type. Fixes #221
  • Loading branch information
raiym authored Feb 2, 2018
2 parents c91f34d + b98134e commit fd150a8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/getSidecarMediaByUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
require __DIR__ . '/../vendor/autoload.php';

function printMediaInfo(\InstagramScraper\Model\Media $media, $padding = '') {
echo "${padding}Id: {$media->getId()}\n";
echo "${padding}Shotrcode: {$media->getShortCode()}\n";
echo "${padding}Created at: {$media->getCreatedTime()}\n";
echo "${padding}Caption: {$media->getCaption()}\n";
echo "${padding}Number of comments: {$media->getCommentsCount()}\n";
echo "${padding}Number of likes: {$media->getLikesCount()}\n";
echo "${padding}Get link: {$media->getLink()}\n";
echo "${padding}High resolution image: {$media->getImageHighResolutionUrl()}\n";
echo "${padding}Media type (video/image/sidecar): {$media->getType()}\n";
}

// If account is public you can query Instagram without auth
$instagram = new \InstagramScraper\Instagram();

// If account is private and you subscribed to it firstly login
$instagram = \InstagramScraper\Instagram::withCredentials('username', 'password', '/path/to/cache/folder');
$instagram->login();

$media = $instagram->getMediaByUrl('https://www.instagram.com/p/BQ0lhTeAYo5');
echo "Media info:\n";
printMediaInfo($media);

$padding = ' ';
echo "Sidecar medias info:\n";
foreach ($media->getSidecarMedias() as $sidecarMedia) {
printMediaInfo($sidecarMedia, $padding);
echo "\n";
}

$account = $media->getOwner();
echo "Account info:\n";
echo "Id: {$account->getId()}\n";
echo "Username: {$account->getUsername()}\n";
echo "Full name: {$account->getFullName()}\n";
echo "Profile pic url: {$account->getProfilePicUrl()}\n";
26 changes: 26 additions & 0 deletions src/InstagramScraper/Model/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ class Media extends AbstractModel
*/
protected $commentsCount = 0;

/**
* @var Media[]|array
*/
protected $sidecarMedias = [];

/**
* @param string $code
*
Expand Down Expand Up @@ -366,6 +371,14 @@ public function getCommentsCount()
return $this->commentsCount;
}

/**
* @return Media[]|array
*/
public function getSidecarMedias()
{
return $this->sidecarMedias;
}

/**
* @param $value
* @param $prop
Expand Down Expand Up @@ -495,6 +508,19 @@ protected function initPropertiesCustom($value, $prop, $arr)
}
}
break;
case 'edge_sidecar_to_children':
if (!is_array($arr[$prop]['edges'])) {
break;
}

foreach ($arr[$prop]['edges'] as $edge) {
if (!isset($edge['node'])) {
continue;
}

$this->sidecarMedias[] = static::create($edge['node']);
}
break;
case 'owner':
$this->owner = Account::create($arr[$prop]);
break;
Expand Down

0 comments on commit fd150a8

Please sign in to comment.