# YouTube Music Downloader (`thenetaji/youtube-music-downloader`) Actor

Download public YouTube and YouTube Music tracks as MP3, M4A, or WebM. Optionally add an available subtitle or timed transcript and receive compact metadata with a ready-to-use audio file URL.

- **URL**: https://apify.com/thenetaji/youtube-music-downloader.md
- **Developed by:** [The Netaji](https://apify.com/thenetaji) (community)
- **Categories:** Social media, Videos, For creators
- **Features:** Limited permissions
- **Stats:** 220 total users, 12 monthly users, 98.4% runs succeeded, 7 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

from $3.50 / 1,000 tracks

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/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 Music Downloader

The Actor saves public YouTube and YouTube Music audio as MP3, M4A, or WebM and returns one compact track record with a retained file URL.

Audio saving is always enabled for this Actor. Each URL is resolved to its video ID, the best compatible audio stream is selected, and the completed file is stored in the run's key-value store. Optional transcript and subtitle data can be attached without turning the result into a full video-format record.

### Accepted YouTube Music links

`urls` accepts regular YouTube watch URLs, YouTube Music watch URLs, shortened `youtu.be` links, Shorts, embed and live URLs, and bare 11-character video IDs.

YouTube Music links copied from an album or playlist are supported. For example:

```text
https://music.youtube.com/watch?v=Gef1KePPRoI&list=OLAK5uy_nq81InQBifozkEJvDr7L9K3kURX7BfMlo
```

The Actor extracts `Gef1KePPRoI` and downloads that track. The `list` parameter supplies browsing context only; it does not cause the whole album or playlist to be downloaded.

### Input fields

| Field | Type | Default | Behaviour |
|---|---|---|---|
| `urls` | array | required | Public YouTube Music or YouTube URLs, or bare video IDs. Duplicate entries are removed. |
| `region` | string | `US` | Required two-letter country code used to retrieve the audio, such as `US`, `IN`, or `DE`. |
| `audioFormat` | enum | `mp3` | Saved format: `mp3`, `m4a`, or `webm`. |
| `includeTranscript` | boolean | `false` | Adds timed transcript segments and combined text when available. This is not guaranteed song lyrics. |
| `subtitleLanguage` | string | empty | Adds one available VTT caption track matching the supplied language code. |

```json
{
  "urls": [
    {
      "url": "https://music.youtube.com/watch?v=Gef1KePPRoI&list=OLAK5uy_nq81InQBifozkEJvDr7L9K3kURX7BfMlo"
    },
    { "url": "https://www.youtube.com/watch?v=arj7oStGLkU" }
  ],
  "region": "US",
  "audioFormat": "mp3",
  "includeTranscript": false
}
```

### Audio format behaviour

`mp3` converts the strongest compatible source audio to 192 kbps MP3 and writes the video title and channel title as file metadata when present.

`m4a` preserves the best available MP4/AAC audio stream without re-encoding. `webm` preserves the best available WebM/Opus audio stream without re-encoding. Source-preserving formats avoid conversion, but availability depends on the streams returned for the track.

### Track records

Each successful audio file produces one dataset row.

| Field | Contents |
|---|---|
| `id`, `url` | Video ID and canonical YouTube watch URL. |
| `title`, `description` | Public track or video text. |
| `accessCountry` | Country used to retrieve the audio. |
| `durationSeconds`, `viewCount`, `isLive` | Duration, reported views, and live-content state. |
| `channel` | Channel ID, title, and canonical channel URL. |
| `savedFile` | Retained audio file identity, format, codecs, bitrate, size, billing size, and public URL. |
| `transcript` | Optional combined text and timed segments. |
| `subtitle` | Optional language metadata and VTT content. |

```json
{
  "id": "Gef1KePPRoI",
  "url": "https://www.youtube.com/watch?v=Gef1KePPRoI",
  "accessCountry": "US",
  "isLive": false,
  "savedFile": {
    "key": "Gef1KePPRoI-audio.mp3",
    "url": "https://api.apify.com/v2/key-value-stores/...",
    "contentType": "audio/mpeg",
    "container": "mp3",
    "codecs": ["mp3"],
    "bitrate": 192000,
    "bytes": 4194304,
    "sizeMb": 4,
    "billedMb": 4
  }
}
```

The dataset deliberately omits thumbnail collections, expiring direct formats, and video-only streams. Those fields are not needed after the audio file has been retained.

### Failure handling and billing

An input for which no public track is returned is skipped, and processing continues with the remaining URLs.

If no compatible audio stream can be saved, the track is omitted from the dataset. Failed audio saves are not billed. Billing follows successful work:

- one track result event after a completed track is added to the dataset;
- one saved-audio event per billed MB, rounded up to the next whole MB, only after storage succeeds;
- one transcript-or-subtitle event when a transcript, a subtitle, or both are successfully attached.

Transcript and subtitle lookups are optional. An unavailable transcript or a missing subtitle language leaves that field absent without preventing the saved audio result.

### Choosing the related YouTube Actor

- [YouTube Video Downloader](https://apify.com/thenetaji/youtube-video-downloader) returns normalized direct formats or saves a playable video with audio.
- [YouTube Transcript Scraper](https://apify.com/thenetaji/youtube-transcript-scraper) returns transcript text and optional subtitle files without downloading audio.
- [YouTube Video Scraper](https://apify.com/thenetaji/youtube-video-scraper) returns broader public video metadata and optional enrichments.
- [YouTube Playlist Scraper](https://apify.com/thenetaji/youtube-playlist-scraper) expands a playlist into separate video records before selected tracks are downloaded.

Only public media that may lawfully be downloaded should be processed.

# Actor input Schema

## `urls` (type: `array`):

One or more public YouTube Music or YouTube video URLs. Bare 11-character video IDs are also accepted in JSON input.

## `region` (type: `string`):

Two-letter ISO country code used to retrieve the source audio, such as US, IN, or DE.

## `saveMedia` (type: `boolean`):

Create one playable audio file per track and return its download URL. Saved files are billed per MB only after a successful transfer. Turn this off to receive the direct audio stream URLs instead, with nothing billed per MB. Paid Apify plan only.

## `audioFormat` (type: `string`):

File format for saved audio. MP3 is broadly compatible; M4A and WebM preserve the source audio without re-encoding when available.

## `includeTranscript` (type: `boolean`):

Add timed transcript segments and combined text when YouTube provides them. This is a transcript or caption, not guaranteed song lyrics.

## `subtitleLanguage` (type: `string`):

Optional language code for one available caption track, such as en, es, or pt-BR. Missing captions do not prevent the audio download.

## Actor input object example

```json
{
  "urls": [
    {
      "url": "https://music.youtube.com/watch?v=arj7oStGLkU"
    }
  ],
  "region": "US",
  "saveMedia": true,
  "audioFormat": "mp3",
  "includeTranscript": false,
  "subtitleLanguage": "en"
}
```

# Actor output Schema

## `dataset` (type: `string`):

All records scraped by this run

## `files` (type: `string`):

Files generated by this run

# 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 = {
    "urls": [
        {
            "url": "https://music.youtube.com/watch?v=arj7oStGLkU"
        }
    ],
    "region": "US"
};

// Run the Actor and wait for it to finish
const run = await client.actor("thenetaji/youtube-music-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 = {
    "urls": [{ "url": "https://music.youtube.com/watch?v=arj7oStGLkU" }],
    "region": "US",
}

# Run the Actor and wait for it to finish
run = client.actor("thenetaji/youtube-music-downloader").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 '{
  "urls": [
    {
      "url": "https://music.youtube.com/watch?v=arj7oStGLkU"
    }
  ],
  "region": "US"
}' |
apify call thenetaji/youtube-music-downloader --silent --output-dataset

```

## MCP server setup

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

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/09xObdTUSZVYoV9nw/builds/pRDCoxmD6nf2rhJLs/openapi.json
