yt-music-id
Identify music from any segment of a YouTube video. Point it at a URL and a time range — it'll pull the audio, slice the clip, and Shazam it.
Install
pip install yt-music-id
Prerequisites: ffmpeg must be installed and on your PATH.
Usage
CLI
# By start + end time
yt-music-id "https://youtube.com/watch?v=xyz" --start 1:23 --end 1:45
# By start + duration (seconds)
yt-music-id "https://youtube.com/watch?v=xyz" --start 0:30 --duration 15
# Just start time (defaults to 10s clip)
yt-music-id "https://youtube.com/watch?v=xyz" --start 2:00
# Auto-split long segments (recommended for anything >15s)
yt-music-id "https://youtube.com/watch?v=xyz" --start 7:00 --end 8:00 --multi
# Raw JSON output
yt-music-id "https://youtube.com/watch?v=xyz" --start 1:00 --end 1:20 --json
# Keep extracted audio files
yt-music-id "https://youtube.com/watch?v=xyz" --start 1:00 --keep-files
Python API
import asyncio
from yt_music_id import download_audio, extract_segment, identify_music, print_match
async def find_song():
# Download audio
path, title, duration = download_audio(
"https://youtube.com/watch?v=xyz", "/tmp/raw"
)
# Extract a segment (7:00 to 7:15)
extract_segment(path, "/tmp/clip.mp3", start=420, duration=15)
# Identify
result = await identify_music("/tmp/clip.mp3")
# Print result
if result.get("track"):
print_match(result["track"], video_title=title)
asyncio.run(find_song())
Options
| Flag | Description |
|---|---|
--start TIME |
Start time (required). Formats: 1:30, 90, 0:01:30 |
--end TIME |
End time. Mutually exclusive with --duration |
--duration SEC |
Duration in seconds. Default: 10 |
--multi |
Auto-split long segments into 10s overlapping chunks for better accuracy |
--json |
Output raw Shazam JSON instead of formatted text |
--keep-files |
Don't delete temp audio files after identification |
Tips
- 5-15 seconds is the sweet spot for Shazam recognition
- Use
--multifor anything over 15 seconds — it auto-chops into overlapping 10s slices - Works best when the music is prominent (less dialogue/SFX over it)
- Some montage videos use original/custom music that won't be in Shazam's database
- Requires
ffmpegon PATH — install viabrew install ffmpeg,apt install ffmpeg, or ffmpeg.org
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yt_music_id-1.0.0.tar.gz
(6.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yt_music_id-1.0.0.tar.gz.
File metadata
- Download URL: yt_music_id-1.0.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17a8bb8ffcafaa0fe8ec6d2660ba44c9154c6f829dea3a76f6b2ddc76dc73c07
|
|
| MD5 |
ab42d286132a8ed8e023b1e7d48722a7
|
|
| BLAKE2b-256 |
1e2d49d6dff35115b291ea071cf0fdae9d982bce84f1b2d6e1b87b3b5281e6ee
|
File details
Details for the file yt_music_id-1.0.0-py3-none-any.whl.
File metadata
- Download URL: yt_music_id-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fad3d2e76db695c71e5dd1eda5e6a0ccbe6ad55761f9117754fd49911f414d35
|
|
| MD5 |
320c5ab2dfabbad2ea76553c4f69f495
|
|
| BLAKE2b-256 |
0d48a6fd529c6b2c03354a2e40240d950de0545a0a518f0b46d56399fa2c3e97
|