# YouTube Scraper — Shorts, Videos & Search (`leonguyen2808/youtube-shorts-scraper`) Actor

Shorts, channel videos and search results from YouTube — videoId, title, view count, publish date, duration, thumbnail — paginated through InnerTube, cached and paced.

- **URL**: https://apify.com/leonguyen2808/youtube-shorts-scraper.md
- **Developed by:** [Leo Nguyen](https://apify.com/leonguyen2808) (community)
- **Categories:** Videos, Social media, Open source
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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

## YouTube Scraper — Shorts, videos & search (cached)

Three listings from YouTube, one Actor: a channel's **Shorts** tab, a channel's **videos** tab, and
**search results**. videoId, title, view count, publish date, duration, thumbnail. No API key, no
browser, no quota.

| Ask for | Input |
|---|---|
| Shorts from a channel | `channels: ["@MrBeast"]` (default) |
| Regular videos from a channel | `channels: ["@MrBeast"]`, `channelTabs: ["videos"]` |
| Both tabs | `channelTabs: ["shorts", "videos"]` |
| Search results | `searchQueries: ["ai tools 2026"]` |

### What you get

One row per video (or one row per listing, your choice):

| Field | Example |
|---|---|
| `videoId` | `egvLKQe6I4I` |
| `url` | `https://www.youtube.com/shorts/egvLKQe6I4I` |
| `title` | `Don't Pop the Balloon` |
| `viewCount` | `102000000` — parsed to a number |
| `viewCountText` | `102M views` — YouTube's own wording |
| `thumbnail` | highest-resolution source YouTube offers |
| `publishedText` | `11 days ago` — videos and search rows only |
| `durationText` | `12:56` — search rows only |
| `channelName` | on search rows, the channel that posted the video |
| `channel`, `channelUrl`, `listing` | repeated on every row, so no join is needed |
| `fromCache` | whether this came from cache or a live fetch |

On a search job, `channel` holds the query you asked for and `listing` is `search`.

### How it behaves

Measured against live pages on 2026-08-06 from a plain datacenter IP:

- Every listing ships its data inline as `ytInitialData` — **48 rows per request** for Shorts, ~30
  for a channel's videos, ~20 for search — with nothing to render. That is why this Actor needs no
  browser and stays cheap.
- Pagination goes through YouTube's own InnerTube API. One test run pulled **174 Shorts across 2
  channels in 5 requests**. Verified per type on 2026-08-06: Shorts 48+48, videos 30+30, search
  20+16, with **zero overlap** between page 1 and page 2 in all three.
- Pagination stops when the listing runs out, not when a page counter says so. Asking for 96 from
  a channel with 78 returns 78 and spends nothing extra.
- The three types genuinely differ under the hood and are handled separately rather than assumed
  identical: channel videos arrive as `lockupViewModel`, search as `videoRenderer`, Shorts as
  `shortsLockupViewModel` — and a **search** continuation must be POSTed to `/youtubei/v1/search`,
  not `/browse`, which answers a bare HTTP 400 that looks like an expired token.

Deliberate choices you should know about:

- **A channel that fails does not fail the run.** It comes back as a row with `error`, so a
  20-channel job returns the other 19. Verified: a nonexistent handle produced one error row and
  the run still exited clean.
- **YouTube does not answer overload with a clean error.** It serves a consent or challenge page
  that is still HTTP 200. So a missing `ytInitialData` is treated as *"we were blocked"* — never as
  *"this channel has no Shorts"*. Those two are very different answers and conflating them is how
  scrapers quietly return empty results.
- **Requests are paced under ~1/s and results are cached.** A channel's Shorts list changes a few
  times a week, so a cached answer from an hour ago is the same answer — and it costs YouTube
  nothing, which is what keeps this Actor off the throttle.
- `viewCount` is `null`, never `0`, when YouTube's text cannot be parsed. A zero is a lie you
  could aggregate without noticing.

### Limits — read before buying

- **View counts are rounded by YouTube itself** (`102M views`), so `viewCount` is precise to about
  1%, not exact. `viewCountText` is preserved so you can see what was actually said.
- Shorts only. The `/videos` and `/streams` tabs use different structures and are out of scope.
- No like counts, comments or publish dates on the channel listing — YouTube does not put them
  there. Getting those means one request per video, which is a different (and far more expensive)
  Actor.
- YouTube's Terms of Service restrict automated access. You are responsible for how you use the
  output. Only public channel listing data is collected.

### Input

```json
{
  "channels": ["@MrBeast", "UCHnyfMqiRRG1u-2MsSQLbXA", "https://www.youtube.com/@veritasium"],
  "maxShortsPerChannel": 96,
  "cacheMaxAgeMinutes": 180
}
```

Handles, bare names, `UC…` ids and full URLs all work — with or without a `/shorts` or `/videos`
suffix already on the end.

### Development

```bash
pip install -r requirements.txt
mkdir -p storage/key_value_stores/default
echo '{"channels":["@MrBeast"],"useApifyProxy":false}' > storage/key_value_stores/default/INPUT.json
python -m src
```

`src/shorts.py` is plain standard library and runs without the Apify SDK — useful for checking
whether YouTube renamed something:

```bash
python -c "from src.shorts import ShortsClient; c=ShortsClient(); s,t,i=c.first_page('@MrBeast'); print(len(s), i)"
```

# Actor input Schema

## `channels` (type: `array`):

One per line. Accepts a handle (@MrBeast), a bare name (MrBeast), a channel id (UCX6OQ3DkcsbYNE6H8uQQuVA) or a full channel URL — any /shorts or /videos suffix is replaced by the tab you pick below.

## `channelTabs` (type: `array`):

Applies to every entry in Channels. `shorts` = the Shorts tab (48 rows/request). `videos` = the regular videos tab (30 rows/request, and each row carries a publish date). Pick both to get both, billed per row either way.

## `searchQueries` (type: `array`):

One per line. Returns YouTube search results newest-relevance-first — these rows additionally carry `channelName`, `durationText` and a description snippet, which channel listings do not. Can be used instead of, or alongside, Channels.

## `maxShortsPerChannel` (type: `integer`):

Per channel-tab and per search query. YouTube returns 48 rows/request for Shorts and ~20-30 for videos and search, so this rounds up to whole pages. Pagination stops early when the listing runs out — it never wastes requests padding to your number.

## `oneItemPerShort` (type: `boolean`):

On (default): one row per video with the channel or query repeated — ready for a spreadsheet or a database with no join. Off: one row per listing with a nested array.

## `cacheMaxAgeMinutes` (type: `integer`):

A channel's listing changes a few times a week, not a few times a minute, so a recent cached answer is the same answer — and serving it costs YouTube nothing, which is why this Actor rarely gets throttled. Set 0 to force a live fetch.

## `useApifyProxy` (type: `boolean`):

Recommended. YouTube does not answer overload with a clean error — it serves a consent or challenge page that still returns HTTP 200. Rotating IPs avoids reaching that point.

## `apifyProxyGroups` (type: `array`):

Leave empty for datacenter proxies (cheapest, and sufficient in testing). Use RESIDENTIAL only if datacenter IPs start getting consent pages.

## `apifyProxyCountry` (type: `string`):

Optional two-letter code. Affects which regional YouTube edge answers; leave empty unless you need a specific country's results.

## `minRequestGapSeconds` (type: `string`):

Default 1.0s. Lower it only with your own proxy pool.

## Actor input object example

```json
{
  "channels": [
    "@MrBeast"
  ],
  "channelTabs": [
    "shorts"
  ],
  "searchQueries": [],
  "maxShortsPerChannel": 96,
  "oneItemPerShort": true,
  "cacheMaxAgeMinutes": 180,
  "useApifyProxy": true,
  "apifyProxyGroups": [],
  "apifyProxyCountry": "",
  "minRequestGapSeconds": "1.0"
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `resultsCsv` (type: `string`):

No description

## `cache` (type: `string`):

No description

# 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 = {
    "channels": [
        "@MrBeast"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("leonguyen2808/youtube-shorts-scraper").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 = { "channels": ["@MrBeast"] }

# Run the Actor and wait for it to finish
run = client.actor("leonguyen2808/youtube-shorts-scraper").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 '{
  "channels": [
    "@MrBeast"
  ]
}' |
apify call leonguyen2808/youtube-shorts-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=leonguyen2808/youtube-shorts-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/dYdVV66XIr8cVGvTV/builds/UkfUXsSWJeL9a3TLm/openapi.json
