# YouTube Search Scraper - Videos & Shorts by Keyword (`rourouk/youtube-search-scraper`) Actor

Search YouTube for videos and Shorts by keyword, list a channel's videos, or load a video by URL. Each row includes title, description, channel, publish time, duration, views, likes when the watch page provides them, thumbnail, and rank.

- **URL**: https://apify.com/rourouk/youtube-search-scraper.md
- **Developed by:** [Kathleen Luo](https://apify.com/rourouk) (community)
- **Categories:** Videos, SEO tools, Social media
- **Features:** Limited permissions
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.25 / 1,000 video results

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/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## YouTube Search Scraper - Videos & Shorts by Keyword

Structured records for YouTube videos and Shorts: keyword search, a channel’s video list, or a specific video URL. Every row is one video, with the same fields, ready for spreadsheets, dashboards, and models.

Use it to see what YouTube returns for a query, pull a channel’s recent uploads, or enrich a list of video ids with title, description, channel, timing, duration, views, and likes.

### Modes

| Mode | You provide | You receive |
| --- | --- | --- |
| `search` | One or more keywords, plus type, upload date, duration, and sort | Videos in YouTube’s order, up to `maxResults` per keyword. `keyword` and `rank` record which query found the row and where it sat. |
| `video` | Watch URL, Shorts URL, youtu.be link, or 11-character video id | The watch-page record: full description, channel, views, likes, calendar publish date, and duration. |
| `channel` | Channel URL, `@handle`, or channel id (`UC…`) | The videos tab. A URL that already ends in `/shorts` or `/streams` keeps that tab. |

Search filters follow the results page:

| Input | Values |
| --- | --- |
| `videoType` | `any`, `video`, `shorts` |
| `uploadDate` | `any`, `hour`, `today`, `week`, `month`, `year` |
| `duration` | `any`, `under3` (under 3 minutes), `min3to20` (3–20 minutes), `over20` |
| `sortBy` | `relevance`, `date` (recently uploaded), `views` |
| `country` | Two-letter location code. Default `US`. Relative times are in English. |

`enrichDetails` opens the watch page for each search or channel row and fills `likeCount`, `publishedAt`, and the full `description`. With it off, search and channel rows still include title, channel, duration, view count, thumbnail, and the description snippet YouTube shows in results. `mode: video` always loads the watch page.

`includeLlmText` adds `llmText`, Markdown assembled from the title, channel, timing, counts, and description.

### Fields

| Field | Type | What it holds |
| --- | --- | --- |
| `type` | string | Always `video`. |
| `source` | string | `search`, `video`, or `channel`. |
| `videoId` | string | 11-character YouTube id. |
| `url` | string | Watch URL, or a Shorts URL when `isShort` is true. |
| `title` | string | Video title. |
| `description` | string or empty | Results snippet, or the full description when the watch page was opened. |
| `channelName` | string or empty | Channel name on the video. |
| `channelId` | string or empty | Channel id (`UC…`). |
| `channelUrl` | string or empty | `https://www.youtube.com/channel/UC…` when the id is known. |
| `publishedAt` | string or empty | UTC time when the watch page shows a calendar date (`2024-08-20T00:00:00Z`). |
| `publishedText` | string or empty | Relative label YouTube showed, such as `2y ago` or `19 hours ago`. |
| `durationText` | string or empty | Length as displayed, such as `12:00:00` or `1:35`. |
| `durationSeconds` | integer or empty | Length in seconds. |
| `viewCount` | integer or empty | View count. A live row’s “watching” number is left empty and `isLive` is true. |
| `viewCountText` | string or empty | View label as shown, such as `13,384,635 views` or `23M views`. |
| `likeCount` | integer or empty | Like count from the watch page (`mode: video` or `enrichDetails`). |
| `thumbnailUrl` | string or empty | Thumbnail image URL. |
| `isShort` | boolean | True for a Short. |
| `isLive` | boolean | True for a live or streamed row. |
| `keyword` | string or empty | Search keyword for this row. Empty in video and channel modes. |
| `rank` | integer | Position among the rows kept for that keyword or channel, starting at 1. |
| `llmText` | string or empty | Markdown of the title, channel, timing, counts, and description. |
| `scrapedAt` | string | UTC time the row was written. |

The same video can appear once per keyword. Inside one keyword or one channel, a repeated id keeps its first rank.

### Input examples

Several keywords, default relevance order:

```json
{
  "mode": "search",
  "keywords": ["python tutorial", "人工智能"],
  "videoType": "any",
  "uploadDate": "any",
  "duration": "any",
  "sortBy": "relevance",
  "country": "US",
  "maxResults": 50,
  "enrichDetails": false,
  "includeLlmText": true
}
```

Shorts for one topic:

```json
{
  "mode": "search",
  "keywords": ["cooking"],
  "videoType": "shorts",
  "maxResults": 100
}
```

A channel’s videos tab:

```json
{
  "mode": "channel",
  "channelUrls": ["https://www.youtube.com/@NASA"],
  "maxResults": 30
}
```

Specific videos, including a Short:

```json
{
  "mode": "video",
  "videoUrls": [
    "https://www.youtube.com/watch?v=ix9cRaBkVe0",
    "https://www.youtube.com/shorts/WqNMhSTCBGE"
  ]
}
```

`maxResults` applies per keyword, per channel, or to the video list. The form default is 20. Further samples are in `examples/`.

### Output example

Search row for `python tutorial` (description snippet, likes filled only after a watch-page read):

```json
{
  "type": "video",
  "source": "search",
  "videoId": "ix9cRaBkVe0",
  "url": "https://www.youtube.com/watch?v=ix9cRaBkVe0",
  "title": "Python Full Course for free 🐍",
  "description": "python #tutorial #beginners Python tutorial for beginners' full course 2024 *Learn Python in 1 HOUR* ...",
  "channelName": "Bro Code",
  "channelId": "UC4SVo0Ue36XCfOyb5Lh1viQ",
  "channelUrl": "https://www.youtube.com/channel/UC4SVo0Ue36XCfOyb5Lh1viQ",
  "publishedAt": null,
  "publishedText": "2y ago",
  "durationText": "12:00:00",
  "durationSeconds": 43200,
  "viewCount": 13384635,
  "viewCountText": "13,384,635 views",
  "likeCount": null,
  "thumbnailUrl": "https://i.ytimg.com/vi/ix9cRaBkVe0/hq720.jpg",
  "isShort": false,
  "isLive": false,
  "keyword": "python tutorial",
  "rank": 1,
  "llmText": "# Python Full Course for free 🐍\n\nURL: https://www.youtube.com/watch?v=ix9cRaBkVe0\nChannel: Bro Code (id UC4SVo0Ue36XCfOyb5Lh1viQ)\nPublished: 2y ago\nDuration: 12:00:00\nKeyword: python tutorial\nRank: 1\nStats: 13,384,635 views · n/a likes\n\n## Description\n\npython #tutorial #beginners Python tutorial for beginners' full course 2024 *Learn Python in 1 HOUR* ...\n",
  "scrapedAt": "2026-11-08T18:00:00Z"
}
```

The same video opened in `mode: video` adds the calendar date, the like count, and the full description:

```json
{
  "source": "video",
  "videoId": "ix9cRaBkVe0",
  "publishedAt": "2024-08-20T00:00:00Z",
  "publishedText": "2y ago",
  "viewCount": 13384635,
  "likeCount": 377158,
  "durationText": "12:00:00",
  "durationSeconds": 43200,
  "description": "#python #tutorial #beginners\nPython tutorial for beginners' full course 2024\n…"
}
```

A Shorts search row uses a Shorts URL and `isShort: true`. A channel row sets `source` to `channel` and leaves `keyword` empty. Dataset views in the console are Overview, Stats, and LLM text.

### Use cases

- **SEO and content research.** Capture the videos YouTube ranks for a keyword, with title, channel, views, duration, and rank.
- **Trend monitoring.** Repeat the same keywords and compare `rank`, `viewCount`, and `publishedText` over time.
- **Influencer discovery.** Group rows by `channelId` to see which channels publish on a topic, including Shorts (`isShort`).
- **AI datasets.** Keep `llmText` and `description` as document fields for classification, clustering, or retrieval.

### Scheduling and integration

Save the input as a task and schedule it daily or weekly. A fixed `maxResults` keeps each run to a known number of rows per keyword or channel.

Start a run with the same JSON as the examples, through the Apify API, an Apify client, or an integration step. When the run succeeds, read the default dataset. The Actor output `videos` points at that dataset’s items. Export JSON, CSV, Excel, or XML from the dataset, or attach a webhook to the task so the next system picks up new rows.

For a model pipeline, map `llmText` to the document body and keep `videoId`, `url`, `keyword`, and `rank` as metadata. Join later runs on `videoId` plus `keyword` to track how a result moves.

### 中文简介

按关键词搜索 YouTube 视频和 Shorts，列出频道视频，或按视频链接读取详情。每条结果字段相同：视频 id、链接、标题、简介、频道名、频道 id、频道链接、发布时间、时长、播放量、点赞（打开视频页时）、封面、是否 Short、关键词和排名。可选 `llmText` 为标题、频道、数据和简介组成的 Markdown。

适合选题研究、趋势跟踪、按主题找频道，以及整理给模型使用的视频数据。输入示例见上文 JSON。

### Run locally

```bash
pip install -r requirements.txt
python -m src
```

With no input file, the run searches `python tutorial` and writes up to 20 videos to `storage/datasets/default/`. To pass input, write `storage/key_value_stores/default/INPUT.json` using a file from `examples/`.

Field notes for developers are in [DEVELOPMENT.md](DEVELOPMENT.md).

# Actor input Schema

## `mode` (type: `string`):

Keyword search, details for specific videos, or the videos tab of a channel.

## `keywords` (type: `array`):

One keyword or phrase per line. Used when mode is search. Each keyword is paged on its own, up to Maximum results.

## `videoType` (type: `string`):

All results, videos only, or Shorts only.

## `uploadDate` (type: `string`):

Filter by when the video was uploaded.

## `duration` (type: `string`):

Filter by length. These match the current YouTube filters: under 3 minutes, 3–20 minutes, and over 20 minutes.

## `sortBy` (type: `string`):

Relevance is the default search order. Views uses YouTube's Popularity filter. Date follows the Recently uploaded chip.

## `country` (type: `string`):

Two-letter country code for YouTube's location, such as US, GB, or JP. Relative times are requested in English.

## `videoUrls` (type: `array`):

Used when mode is video. Each entry can be a watch URL, a Shorts URL, a youtu.be link, or an 11-character video id.

## `channelUrls` (type: `array`):

Used when mode is channel. A channel URL, @handle, or UC id. /videos is used when you do not already point at /videos, /shorts, or /streams.

## `maxResults` (type: `integer`):

How many videos to return per keyword, per channel, or from the video list. Minimum 1, maximum 1000.

## `enrichDetails` (type: `boolean`):

For search and channel modes, also open each watch page to fill likes, the publish date, and the full description. Leave this off for a faster run. Search cards already include the title, channel, duration, and view count. Video mode always opens the watch page.

## `includeLlmText` (type: `boolean`):

Add llmText, a Markdown field with the title, public byline, stats, and description.

## `requestIntervalMillis` (type: `integer`):

Minimum pause between public requests. 400ms is the default. The floor is 200ms.

## `maxRetries` (type: `integer`):

Extra attempts after a request fails.

## `proxyConfiguration` (type: `object`):

Optional. Leave Apify Proxy off to connect directly.

## Actor input object example

```json
{
  "mode": "search",
  "keywords": [
    "python tutorial"
  ],
  "videoType": "any",
  "uploadDate": "any",
  "duration": "any",
  "sortBy": "relevance",
  "country": "US",
  "videoUrls": [
    "https://www.youtube.com/watch?v=Js05B8Z1ivE"
  ],
  "channelUrls": [
    "https://www.youtube.com/@NASA"
  ],
  "maxResults": 20,
  "enrichDetails": false,
  "includeLlmText": true,
  "requestIntervalMillis": 400,
  "maxRetries": 3,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

## `videos` (type: `string`):

All scraped videos in the default dataset.

# 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 = {
    "mode": "search",
    "keywords": [
        "python tutorial"
    ],
    "videoType": "any",
    "uploadDate": "any",
    "duration": "any",
    "sortBy": "relevance",
    "country": "US",
    "videoUrls": [
        "https://www.youtube.com/watch?v=Js05B8Z1ivE"
    ],
    "channelUrls": [
        "https://www.youtube.com/@NASA"
    ],
    "maxResults": 20,
    "enrichDetails": false,
    "includeLlmText": true,
    "requestIntervalMillis": 400,
    "maxRetries": 3
};

// Run the Actor and wait for it to finish
const run = await client.actor("rourouk/youtube-search-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 = {
    "mode": "search",
    "keywords": ["python tutorial"],
    "videoType": "any",
    "uploadDate": "any",
    "duration": "any",
    "sortBy": "relevance",
    "country": "US",
    "videoUrls": ["https://www.youtube.com/watch?v=Js05B8Z1ivE"],
    "channelUrls": ["https://www.youtube.com/@NASA"],
    "maxResults": 20,
    "enrichDetails": False,
    "includeLlmText": True,
    "requestIntervalMillis": 400,
    "maxRetries": 3,
}

# Run the Actor and wait for it to finish
run = client.actor("rourouk/youtube-search-scraper").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{
  "mode": "search",
  "keywords": [
    "python tutorial"
  ],
  "videoType": "any",
  "uploadDate": "any",
  "duration": "any",
  "sortBy": "relevance",
  "country": "US",
  "videoUrls": [
    "https://www.youtube.com/watch?v=Js05B8Z1ivE"
  ],
  "channelUrls": [
    "https://www.youtube.com/@NASA"
  ],
  "maxResults": 20,
  "enrichDetails": false,
  "includeLlmText": true,
  "requestIntervalMillis": 400,
  "maxRetries": 3
}' |
apify call rourouk/youtube-search-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,rourouk/youtube-search-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

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