# Instagram Dataset Media Downloader (`vittuhy/instagram-media-downloader`) Actor

Automatically downloads expiring media (videos and images) from Instagram Reel Scraper and Post Scraper datasets. Stores files in a named key-value store with full traceability back to the original reel or post.

- **URL**: https://apify.com/vittuhy/instagram-media-downloader.md
- **Developed by:** [Vít Tuhý](https://apify.com/vittuhy) (community)
- **Categories:** Social media, Automation
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 media

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Instagram Reels and Posts Media Downloader

Downloads expiring media (videos and images) from [Instagram Reel Scraper](https://apify.com/apify/instagram-reel-scraper) and [Instagram Post Scraper](https://apify.com/apify/instagram-post-scraper) datasets before the URLs expire.

Instagram CDN links typically expire within **7 days**. This Actor grabs the media and stores it permanently in an Apify key-value store, with full traceability back to the original content.

### How it works

1. Reads a dataset by ID (from a Reel or Post Scraper run)
2. **Auto-detects** whether the dataset came from the Reel Scraper or Post Scraper
3. Downloads all media files (videos, images, carousel children)
4. Stores each file in a **named key-value store** linked to the source dataset
5. Creates a `_manifest` JSON with metadata for every downloaded file

#### Source detection

| Source | Detected by | Fields downloaded |
|--------|-------------|-------------------|
| Instagram Reel Scraper | `downloadedVideo` field present | `downloadedVideo` (video) |
| Instagram Post Scraper | `displayUrl` field present | `displayUrl` (image), `videoUrl` (video, when present), plus all `childPosts` media for carousel/sidecar posts |

#### File naming in the key-value store

Every file is keyed by the Instagram shortcode so you can trace it back to the original content:

| Source | Media | Key format | Example |
|--------|-------|------------|---------|
| Reel Scraper | Video | `reel-{shortCode}` | `reel-CxYz123` |
| Post Scraper | Image | `post-{shortCode}-image` | `post-AbCd456-image` |
| Post Scraper | Video | `post-{shortCode}-video` | `post-AbCd456-video` |
| Post Scraper | Carousel child image | `post-{childShortCode}-image` | `post-EfGh789-image` |
| Post Scraper | Carousel child video | `post-{childShortCode}-video` | `post-EfGh789-video` |

#### Manifest

A `_manifest` key is stored in the same key-value store. It contains a JSON array with metadata for every downloaded file:

```json
[
    {
        "shortCode": "CxYz123",
        "originalId": "3210987654321",
        "ownerUsername": "natgeo",
        "caption": "Amazing wildlife footage...",
        "timestamp": "2026-06-20T12:00:00.000Z",
        "postType": "Video",
        "kvsKey": "reel-CxYz123",
        "mediaType": "video",
        "sourceUrl": "https://...",
        "contentType": "video/mp4",
        "sizeBytes": 5242880
    }
]
````

For carousel children, the manifest also includes `parentShortCode` and `childIndex`.

### Input

| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| `datasetId` | String | Yes | - | ID of the dataset to read media URLs from |
| `keyValueStoreName` | String | No | `media-{datasetId}` | Custom name for the output key-value store |
| `concurrency` | Integer | No | `5` | Number of parallel downloads (1-20) |

#### Example input

```json
{
    "datasetId": "aXgbg1XUeBakPyWpT",
    "concurrency": 10
}
```

### Output

The Actor pushes a summary object to its default dataset:

```json
{
    "source": "reel-scraper",
    "sourceDatasetId": "aXgbg1XUeBakPyWpT",
    "keyValueStoreName": "media-aXgbg1XUeBakPyWpT",
    "totalItems": 17,
    "totalFiles": 10,
    "downloaded": 10,
    "failed": 0
}
```

All downloaded files are in the named key-value store. You can access them via:

- **Apify Console**: Storage > Key-value stores > `media-{datasetId}`
- **API**: `https://api.apify.com/v2/key-value-stores/{storeId}/records/{key}`

### Integration setup

The primary use case is running this Actor automatically after a Reel or Post Scraper run finishes. Set this up using Apify's built-in integrations.

#### Step-by-step

1. Open your **Instagram Reel Scraper** or **Instagram Post Scraper** Actor (or Task) in Apify Console
2. Go to the **Integrations** tab
3. Click **Add integration** > **Run Actor**
4. Configure:
   - **When**: Run succeeded
   - **Actor**: Select `instagram-media-downloader` (this Actor)
   - **Input**:

```json
{
    "datasetId": "{{resource.defaultDatasetId}}"
}
```

5. Click **Save**

The `{{resource.defaultDatasetId}}` template variable is automatically replaced with the dataset ID from the scraper run that triggered the integration.

#### Setting up on a Task (recommended)

If you run the scraper via a saved **Task** (e.g., "Scrape NatGeo reels daily"):

1. Open the Task in Console
2. Go to **Integrations** tab
3. Follow the same steps above

This way, every scheduled or manual run of that Task will automatically trigger the media download.

#### Custom key-value store name

If you want a descriptive store name instead of the dataset ID:

```json
{
    "datasetId": "{{resource.defaultDatasetId}}",
    "keyValueStoreName": "natgeo-reels-{{resource.id}}"
}
```

`{{resource.id}}` is the run ID of the source scraper.

### Data retention

Downloaded media is stored in a **named key-value store**. Named stores in Apify are retained indefinitely (they don't expire with the run). However, storage counts toward your Apify plan limits.

To manage storage:

- Delete old key-value stores via Console or API when you no longer need the media
- Use the manifest (`_manifest` key) to audit what's stored before cleanup

### Limitations

- URLs that have already expired will fail to download (the Actor logs a warning and continues)
- Very large datasets (1000+ items) may need higher memory allocation
- The Actor does not re-upload to external storage (S3, GCS, etc.) - files stay in Apify KVS

# Actor input Schema

## `datasetId` (type: `string`):

ID of the dataset containing media URLs to download. Pass this from the source Actor's integration using {{resource.defaultDatasetId}}.

## `keyValueStoreName` (type: `string`):

Custom name for the KVS where media will be stored. If empty, defaults to 'media-{datasetId}'.

## `concurrency` (type: `integer`):

How many files to download in parallel.

## Actor input object example

```json
{
  "concurrency": 5
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("vittuhy/instagram-media-downloader").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("vittuhy/instagram-media-downloader").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call vittuhy/instagram-media-downloader --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=vittuhy/instagram-media-downloader",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Instagram Dataset Media Downloader",
        "description": "Automatically downloads expiring media (videos and images) from Instagram Reel Scraper and Post Scraper datasets. Stores files in a named key-value store with full traceability back to the original reel or post.",
        "version": "1.0",
        "x-build-id": "MDK8ewbQNtLGHuKHT"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/vittuhy~instagram-media-downloader/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-vittuhy-instagram-media-downloader",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/vittuhy~instagram-media-downloader/runs": {
            "post": {
                "operationId": "runs-sync-vittuhy-instagram-media-downloader",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/vittuhy~instagram-media-downloader/run-sync": {
            "post": {
                "operationId": "run-sync-vittuhy-instagram-media-downloader",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "datasetId"
                ],
                "properties": {
                    "datasetId": {
                        "title": "Dataset ID",
                        "type": "string",
                        "description": "ID of the dataset containing media URLs to download. Pass this from the source Actor's integration using {{resource.defaultDatasetId}}."
                    },
                    "keyValueStoreName": {
                        "title": "Key-value store name (optional)",
                        "type": "string",
                        "description": "Custom name for the KVS where media will be stored. If empty, defaults to 'media-{datasetId}'."
                    },
                    "concurrency": {
                        "title": "Download concurrency",
                        "minimum": 1,
                        "maximum": 20,
                        "type": "integer",
                        "description": "How many files to download in parallel.",
                        "default": 5
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
