# YouTube Scraper (`magicfingers/youtube-scraper`) Actor

Scrape YouTube videos, channels, comments, and playlists. Search by keyword, extract video details, comments, channel info, and playlist contents.

- **URL**: https://apify.com/magicfingers/youtube-scraper.md
- **Developed by:** [abdulrahman alrashid](https://apify.com/magicfingers) (community)
- **Categories:** Marketing
- **Stats:** 30 total users, 8 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

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

Apify Actor for scraping YouTube videos, channels, comments, and playlists. Uses YouTube's internal API (`youtubei/v1`) for fast, reliable data extraction with CheerioCrawler for page scraping and PlaywrightCrawler as fallback.

### Features

- **Search videos** by keyword with pagination and type filtering (video, channel, playlist)
- **Scrape video details**: title, description, view/like/comment counts, upload date, duration, channel info, tags, category, thumbnails, chapters
- **Scrape video comments** with pagination: author, text, likes, reply count, published date, creator reply flag
- **Scrape channel info**: name, subscribers, video count, total views, description, joined date, country, social links
- **Scrape channel video lists** with sort options (newest, popular, oldest)
- **Scrape playlist contents**: all video titles, URLs, durations, and playlist metadata

### Input

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `searchKeywords` | `string[]` | `[]` | Keywords to search YouTube for |
| `videoUrls` | `string[]` | `[]` | Direct video URLs to scrape details from |
| `channelUrls` | `string[]` | `[]` | Channel URLs to scrape info/videos from |
| `playlistUrls` | `string[]` | `[]` | Playlist URLs to scrape |
| `scrapeComments` | `boolean` | `false` | Scrape comments for each video |
| `maxComments` | `integer` | `100` | Max comments per video (0 = unlimited) |
| `maxSearchResults` | `integer` | `50` | Max results per search keyword (0 = unlimited) |
| `maxChannelVideos` | `integer` | `50` | Max videos per channel (0 = unlimited) |
| `channelVideoSort` | `string` | `"newest"` | Sort order: `newest`, `popular`, `oldest` |
| `scrapeChannelInfo` | `boolean` | `true` | Scrape channel metadata |
| `scrapeChannelVideos` | `boolean` | `true` | Scrape channel video list |
| `searchType` | `string` | `"video"` | Filter: `video`, `channel`, `playlist`, `any` |
| `proxyConfiguration` | `object` | `null` | Proxy settings |
| `maxRetries` | `integer` | `3` | Max retries for failed requests |

### Example Input

```json
{
    "searchKeywords": ["web scraping tutorial"],
    "videoUrls": ["https://www.youtube.com/watch?v=dQw4w9WgXcQ"],
    "channelUrls": ["https://www.youtube.com/@MrBeast"],
    "playlistUrls": ["https://www.youtube.com/playlist?list=PLrAXtmErZgOeiKm4sgNOknGvNjby9efdf"],
    "scrapeComments": true,
    "maxComments": 50,
    "maxSearchResults": 20,
    "maxChannelVideos": 30,
    "channelVideoSort": "popular",
    "searchType": "video"
}
```

### Output Examples

#### Search Result

```json
{
    "type": "video",
    "videoId": "abc123",
    "title": "How to Web Scrape in 2024",
    "url": "https://www.youtube.com/watch?v=abc123",
    "thumbnailUrl": "https://i.ytimg.com/vi/abc123/maxresdefault.jpg",
    "duration": "12:34",
    "durationSeconds": 754,
    "viewCount": 150000,
    "channelName": "TechChannel",
    "publishedTimeText": "3 months ago",
    "descriptionSnippet": "Learn web scraping with Python...",
    "searchKeyword": "web scraping tutorial"
}
```

#### Video Detail

```json
{
    "type": "videoDetail",
    "videoId": "abc123",
    "title": "How to Web Scrape in 2024",
    "description": "Full description text...",
    "viewCount": 150000,
    "likeCount": 5200,
    "commentCount": 340,
    "uploadDate": "2024-01-15",
    "duration": "12:34",
    "durationSeconds": 754,
    "channelName": "TechChannel",
    "channelId": "UCxxxxxxxx",
    "channelUrl": "https://www.youtube.com/channel/UCxxxxxxxx",
    "tags": ["web scraping", "python", "tutorial"],
    "category": "Science & Technology",
    "thumbnails": [],
    "chapters": [
        { "title": "Introduction", "startSeconds": 0 }
    ]
}
```

#### Comment

```json
{
    "type": "comment",
    "commentId": "xyz789",
    "author": "UserName",
    "authorChannelUrl": "https://www.youtube.com/@UserName",
    "text": "Great tutorial, very helpful!",
    "likeCount": 15,
    "replyCount": 3,
    "publishedTimeText": "2 months ago",
    "isCreatorReply": false,
    "videoId": "abc123"
}
```

#### Channel Info

```json
{
    "type": "channelInfo",
    "channelId": "UCxxxxxxxx",
    "channelName": "TechChannel",
    "channelUrl": "https://www.youtube.com/channel/UCxxxxxxxx",
    "description": "Channel description...",
    "subscriberCount": 1200000,
    "videoCount": 450,
    "totalViews": 250000000,
    "joinedDate": "Jan 15, 2018",
    "country": "United States",
    "socialLinks": [
        { "title": "Twitter", "url": "https://twitter.com/techchannel" }
    ]
}
```

#### Playlist Video

```json
{
    "type": "playlistVideo",
    "videoId": "abc123",
    "title": "Playlist Video Title",
    "url": "https://www.youtube.com/watch?v=abc123",
    "duration": "8:45",
    "durationSeconds": 525,
    "channelName": "TechChannel",
    "index": 1,
    "playlistId": "PLxxxxxxxx"
}
```

### Pricing

This Actor uses Pay-Per-Event pricing at **$0.35 per 1,000 results** ($0.00035 per result). Each scraped item (video, comment, channel info entry, playlist video) counts as one result.

### Technical Details

- Uses YouTube's internal `youtubei/v1` API for search, comments, channel browsing, and playlists
- Falls back to page scraping via CheerioCrawler for video detail extraction (extracts `ytInitialData` and `ytInitialPlayerResponse`)
- Uses PlaywrightCrawler as a secondary fallback when pages require JavaScript rendering
- Handles pagination via continuation tokens for all data types
- Built with Apify SDK v3 and Crawlee

### Legal Notice

This Actor is intended for personal use, research, and legitimate business purposes. Ensure your use complies with YouTube's Terms of Service and applicable laws. The Actor does not bypass any authentication or access restrictions.

# Actor input Schema

## `searchKeywords` (type: `array`):

List of keywords to search for on YouTube. Each keyword produces a separate search.

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

Direct YouTube video URLs to scrape details from.

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

YouTube channel URLs to scrape info and/or videos from.

## `playlistUrls` (type: `array`):

YouTube playlist URLs to scrape all video entries from.

## `scrapeComments` (type: `boolean`):

Whether to scrape comments for each video.

## `maxComments` (type: `integer`):

Maximum number of comments to scrape per video. Set 0 for unlimited.

## `maxSearchResults` (type: `integer`):

Maximum number of search results per keyword. Set 0 for unlimited.

## `maxChannelVideos` (type: `integer`):

Maximum number of videos to scrape from each channel. Set 0 for unlimited.

## `channelVideoSort` (type: `string`):

Sort order for channel videos.

## `scrapeChannelInfo` (type: `boolean`):

Whether to scrape channel metadata (subscriber count, description, etc.).

## `scrapeChannelVideos` (type: `boolean`):

Whether to scrape the list of videos from channels.

## `searchType` (type: `string`):

Filter search results by type.

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

Proxy configuration for the scraper.

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

Maximum number of retries for failed requests.

## Actor input object example

```json
{
  "searchKeywords": [
    "machine learning tutorial",
    "web scraping python"
  ],
  "videoUrls": [
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
  ],
  "channelUrls": [
    "https://www.youtube.com/@MrBeast"
  ],
  "playlistUrls": [
    "https://www.youtube.com/playlist?list=PLrAXtmErZgOeiKm4sgNOknGvNjby9efdf"
  ],
  "scrapeComments": false,
  "maxComments": 100,
  "maxSearchResults": 5,
  "maxChannelVideos": 50,
  "channelVideoSort": "newest",
  "scrapeChannelInfo": true,
  "scrapeChannelVideos": true,
  "searchType": "video",
  "proxyConfiguration": {
    "useApifyProxy": true
  },
  "maxRetries": 3
}
```

# 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 = {
    "searchKeywords": [
        "javascript tutorial"
    ],
    "maxSearchResults": 5,
    "proxyConfiguration": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("magicfingers/youtube-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 = {
    "searchKeywords": ["javascript tutorial"],
    "maxSearchResults": 5,
    "proxyConfiguration": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("magicfingers/youtube-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 '{
  "searchKeywords": [
    "javascript tutorial"
  ],
  "maxSearchResults": 5,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}' |
apify call magicfingers/youtube-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,magicfingers/youtube-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/7lTEIDevNPLjc8KhK/builds/GthB0eUjf2baPZthP/openapi.json
