BLOG
Find the Song Used in a YouTube Video (Automated Guide)
Learn how to find the song used in a YouTube video manually and how to automate it with a remote browser, Playwright, and CDP.

To find the song used in a YouTube video, you have three practical options: read the video description and credits, use a music-identification service that accepts a URL or audio clip, or automate the lookup so it runs at scale. The manual path takes a minute. The automated path is what this guide covers, because "which track is this?" is a recurring task for content teams, moderation pipelines, and agents that need structured metadata rather than a guess.
We'll walk through the reliable manual methods first, then show how to drive a hosted Chromium session with Playwright over CDP to resolve a song from a video URL and return structured output. The automation approach matters because music-identification sites are interactive, rate-limited, and often gated behind consent dialogs — exactly the kind of surface where a real browser beats a raw HTTP request.
Why finding a song is harder than it looks
A YouTube video's audio track is not exposed as structured metadata. The platform does not publish a "song" field. What you get is:
- Description text that may or may not list credits.
- Auto-generated chapters that sometimes name tracks.
- Content ID claims that are visible to the uploader, not the viewer.
- Comments where someone usually asks and someone else usually answers.
Music-identification services fill the gap by fingerprinting audio. The two common input modes are a short recorded clip and a URL. URL-based lookup is convenient but depends on the service being able to fetch and decode the audio, which is where automation gets fiddly: some services want a file upload, some want a link, and most present a cookie banner or a CAPTCHA before they'll answer.
That is the core trade-off. A pure API call is fast and cheap but brittle against interactive pages. A real browser session is slower per lookup but handles the consent dialogs, file inputs, and dynamic results that break naive scrapers.
Manual methods that actually work
Before automating anything, confirm the manual path so you know what "correct" looks like.
1. Check the description and pinned comment
Open the video, expand the description, and search for "Music," "Track," "Song," or "Licensed to." Many creators paste a full tracklist. The pinned comment often repeats it. This resolves a large share of cases with zero tooling.
2. Use YouTube's "Music in this video" panel
When a video has licensed music, YouTube sometimes shows a "Music in this video" section under the description with song title, artist, and license. It is not universal, but when present it is authoritative.
3. Run a music-identification service
Services like AHA Music, Shazam, and similar tools accept a URL or a recorded snippet and return a match with a confidence score. For a one-off lookup, this is the fastest route. For a batch of a thousand videos, it is not.
4. Cross-check with a lyrics or fingerprint search
If you have a lyric fragment, a lyrics search often identifies the track. If you have only audio, a fingerprint service is the right tool. Neither is scriptable without a browser in most cases.
When to automate the lookup
Automate when the volume is high, the output needs to be structured, or the lookup is one step inside a larger agent workflow — for example, tagging a media library, building a moderation queue, or enriching a content database. The criteria that matter:
| Criterion | Manual lookup | Scripted HTTP | Hosted browser automation |
|---|---|---|---|
| One-off video | Best | Overkill | Overkill |
| Large batches of videos | Painful | Fragile | Good fit |
| Handles consent/CAPTCHA dialogs | Yes (human) | No | Yes, with a real session |
| Structured JSON output | No | Yes, if API exists | Yes |
| Survives page redesigns | Yes | No | Mostly, with selectors you maintain |
| Cost per lookup | Human time | Lowest | Metered browser time |
The honest summary: if a service exposes a documented API, use it. If it doesn't, and you need volume, a hosted browser is the pragmatic middle ground.
Architecture: a remote browser for song lookup
The pattern is straightforward. You give an agent or script a YouTube URL. The script opens a hosted Chromium session, navigates to a music-identification service, submits the URL or a clip, waits for the result, and returns the matched title and artist.
Why a hosted browser rather than a local one:
- Session isolation. Each lookup runs in a clean browser context, so cookies and consent state from one job don't leak into the next.
- Persistent profiles. If a service requires a login or remembers preferences, a saved profile avoids re-authenticating on every run.
- Live viewer. When a lookup fails, you can watch the session and see exactly which dialog blocked it.
- Configurable browser settings. Proxy and locale settings can be adjusted per session, which matters when a service geo-restricts content.
For background on the runtime model, see Remote browsers for AI agents and Remote browser online.
Implementation: Playwright over CDP
The example below connects Playwright to a hosted Chromium session over the Chrome DevTools Protocol, navigates to a music-identification service, and submits a video URL. Selectors are illustrative — replace them with the ones your target service actually uses, and check that service's terms before automating it.
import { chromium } from "playwright";
// CDP endpoint for a hosted Chromium session.
// In production, create the session via the Remote Browser API and read the
// WebSocket URL from the response. See /documentation for the exact shape.
const CDP_ENDPOINT = process.env.REMOTE_BROWSER_CDP_URL!;
interface SongMatch {
title: string;
artist: string;
confidence: string | null;
}
async function findSong(videoUrl: string): Promise<SongMatch | null> {
const browser = await chromium.connectOverCDP(CDP_ENDPOINT);
const context = browser.contexts()[0] ?? (await browser.newContext());
const page = await context.newPage();
try {
await page.goto("https://example-music-id.service/", {
waitUntil: "domcontentloaded",
timeout: 30_000,
});
// Dismiss a consent banner if present. Use a role-based locator so the
// selector survives minor markup changes.
const consent = page.getByRole("button", { name: /accept|agree/i });
if (await consent.isVisible().catch(() => false)) {
await consent.click();
}
// Submit the video URL. Some services take a URL, others a file upload;
// adapt this step to the service you are targeting.
await page.getByPlaceholder(/paste.*url|video link/i).fill(videoUrl);
await page.getByRole("button", { name: /identify|search|find/i }).click();
// Wait for the result panel rather than a fixed sleep.
const result = page.locator("[data-testid='match-result']").first();
await result.waitFor({ state: "visible", timeout: 60_000 });
const title = (await result.locator("[data-testid='track-title']").innerText()).trim();
const artist = (await result.locator("[data-testid='track-artist']").innerText()).trim();
const confidence = await result
.locator("[data-testid='confidence']")
.innerText()
.catch(() => null);
return { title, artist, confidence: confidence?.trim() ?? null };
} finally {
await page.close();
// Keep the session alive if you are batching; otherwise close the browser.
await browser.close();
}
}
findSong("https://www.youtube.com/watch?v=VIDEO_ID")
.then((m) => console.log(m))
.catch((err) => console.error("lookup failed:", err));A few implementation notes that save time in practice:
- Wait on state, not on timers.
waitFor({ state: "visible" })on the result container is far more reliable thanpage.waitForTimeout(5000). - Use role and test-id locators. Text-based locators break when a service localizes its UI.
- Handle the "no match" branch explicitly. A service that returns nothing should not hang your pipeline; wrap the wait in a timeout and return
null. - Batch with one session. Creating a browser per lookup is wasteful. Reuse the context and open a new page per video, then close pages as you go.
For the CDP connection details, the Chrome DevTools Protocol documentation is the authoritative reference, and Playwright's connectOverCDP is documented in the Playwright API reference.
Handling the failure modes
Automated song lookup fails in predictable ways. Plan for each:
Consent and cookie walls
Most services show a banner on first visit. A persistent profile that has already accepted the banner removes this step for subsequent runs. If you can't persist, keep the role-based dismiss logic in the script.
CAPTCHA
Some services challenge automated traffic. A hosted browser with configurable settings can reduce false positives, but no runtime guarantees a CAPTCHA-free experience. If a service consistently challenges you, check its terms — it may prohibit automation, in which case the right answer is to use its API or find a different service.
Ambiguous matches
A short clip may match multiple tracks. Return the top result plus the confidence score, and let downstream logic decide whether to accept it. Do not silently pick the first row.
Geo-restricted content
If the service can't fetch the video because of regional restrictions, a proxy configured for the right region can help. This is a per-session setting, not a global one.
Rate limits
Batch jobs should pace themselves. Metered browser time is billed per session, so a runaway loop is both a correctness problem and a cost problem. See pricing for how usage is metered.
Production criteria before you ship
If song lookup is going into a real pipeline, evaluate against these:
- Deterministic output schema. Every result should have the same shape, including a
nullcase. Downstream consumers should never have to parse free text. - Retry policy. Transient failures (timeouts, 5xx from the service) should retry with backoff. Persistent failures should surface, not silently return empty.
- Observability. Log the video URL, the session ID, the matched title, and the confidence score. When a match is wrong, you need the session ID to replay it in the live viewer.
- Terms compliance. Confirm the target service permits automated access. This is not optional; it is the difference between a working pipeline and a blocked account.
- Cost ceiling. Set a per-job budget. Browser time is metered, and a stuck session is a slow leak.
For the runtime controls that support these — session isolation, profiles, live debugging — see Remote control browser and the documentation.
A note on accuracy
No automated method is perfect. Music fingerprinting produces false positives on similar-sounding tracks, and description-based credits are only as good as the uploader. Treat the output as a candidate with a confidence signal, not a fact. For high-stakes use — licensing, royalty reporting — verify against the rights holder or a licensed database.
The realistic goal for automation is not "always correct." It is "correct often enough, with a clear signal when it isn't, and a replayable session when you need to investigate." That is a much more achievable target, and it is the one that holds up in production.
Summary
Finding the song in a YouTube video starts with the description and YouTube's own music panel, moves to a fingerprinting service for the hard cases, and becomes a browser-automation problem when you need volume or structured output. A hosted Chromium session driven by Playwright over CDP handles the interactive parts — consent dialogs, URL submission, dynamic results — that break plain HTTP scrapers. Keep the output schema strict, handle the no-match case, respect the target service's terms, and watch your metered usage. For setup details, start with the documentation and pricing.