-
-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathmedias-download.php
42 lines (33 loc) · 1.18 KB
/
medias-download.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
use Instagram\Api;
use Instagram\Exception\InstagramException;
use Instagram\Model\Media;
use Instagram\Utils\MediaDownloadHelper;
use Psr\Cache\CacheException;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
require realpath(dirname(__FILE__)) . '/../vendor/autoload.php';
$credentials = include_once realpath(dirname(__FILE__)) . '/credentials.php';
$cachePool = new FilesystemAdapter('Instagram', 0, __DIR__ . '/../cache');
try {
$api = new Api($cachePool);
$api->login($credentials->getLogin(), $credentials->getPassword());
$profile = $api->getProfile('twhiddleston');
downloadMedias($profile->getMedias());
} catch (InstagramException $e) {
print_r($e->getMessage());
} catch (CacheException $e) {
print_r($e->getMessage());
}
function downloadMedias(array $medias)
{
/** @var Media $media */
foreach ($medias as $media) {
if ($media->isVideo()) {
$fileName = MediaDownloadHelper::downloadMedia($media->getVideoUrl());
} else {
$fileName = MediaDownloadHelper::downloadMedia($media->getDisplaySrc());
}
echo 'Media downloaded as : ' . $fileName . PHP_EOL;
}
}