Skip to main content

Identify music files using Shazam, write ID3 tags, rename and organize

Project description

๐ŸŽต Music Recognition

License: MIT Python PyPI Tests Downloads Stars

Bulk music identification and tagging tool โ€” bring order to your chaotic music collection.

Automatically identify unknown music files using Shazam, write ID3 tags, rename files, and organize into Artist/Album folders.

โœจ Features

  • ๐Ÿ” Identify tracks via Shazam API
  • ๐Ÿ“ Write ID3 tags โ€” title, artist, album, year, genre
  • ๐Ÿ“ Rename files โ€” customizable templates like {artist} - {title}.mp3
  • ๐Ÿ—‚๏ธ Organize โ€” automatic Artist/Album folder structure
  • โšก Async processing โ€” concurrent requests with rate limiting
  • ๐Ÿ”„ Format conversion โ€” WAV, FLAC, M4A, OGG โ†’ MP3
  • ๐Ÿ“Š Export reports โ€” JSON/CSV for processed files
  • ๐Ÿ›ก๏ธ Safe โ€” dry-run mode to preview changes

๐Ÿš€ Quick Start

Installation

# From source
git clone https://github.com/formeo/music_recognition.git
cd music_recognition
pip install -e .

# Or install dependencies only
pip install -r requirements.txt

Requirements

  • Python 3.9+
  • FFmpeg (for audio conversion)
# Ubuntu/Debian
sudo apt install ffmpeg

# macOS
brew install ffmpeg

# Windows
winget install ffmpeg

Basic Usage

# Recognize and tag all files in a directory
music-recognize /path/to/music

# Also rename files to "Artist - Title.mp3"
music-recognize /path/to/music --rename

# Organize into Artist/Album folders
music-recognize /path/to/music --organize --output /sorted

# Preview changes without modifying files
music-recognize /path/to/music --rename --dry-run

๐Ÿ“– Usage Examples

Command Line

# Process single file
music-recognize song.mp3

# Process directory with custom template
music-recognize /music --rename --template "{artist}/{album}/{title}.mp3"

# Export results to JSON
music-recognize /music --output report.json

# Force re-recognition of already tagged files
music-recognize /music --force --overwrite

# Quiet mode (minimal output)
music-recognize /music -q

# Verbose mode (detailed logging)
music-recognize /music -v

Python API

import asyncio
from music_recognition import MusicRecognizer, recognize_and_tag

# Simple one-liner
asyncio.run(recognize_and_tag("/music", rename=True))

# Full control
async def process_collection():
    recognizer = MusicRecognizer(
        max_concurrent=5,
        delay_between_requests=0.5,
    )
    
    stats = await recognizer.process_directory(
        source_dir="/music",
        output_dir="/sorted",
        write_tags=True,
        rename=True,
        rename_template="{artist} - {title}.mp3",
        organize=True,
        skip_recognized=True,
        dry_run=False,
    )
    
    print(f"Recognized: {stats.recognized}/{stats.processed}")
    print(f"Success rate: {stats.success_rate:.1f}%")

asyncio.run(process_collection())

โš™๏ธ CLI Options

usage: music-recognize [-h] [-o PATH] [--rename] [--template TPL] [--organize]
                       [--overwrite] [-f] [-c N] [--delay SEC] [-n] [-v] [-q]
                       path

Arguments:
  path                    File or directory to process

Options:
  -o, --output PATH       Output directory or report file (.json/.csv)
  --rename                Rename files based on metadata
  --template TPL          Filename template (default: "{artist} - {title}.mp3")
  --organize              Organize files into Artist/Album folders
  --overwrite             Overwrite existing ID3 tags
  -f, --force             Process files even if they have valid tags
  -c, --concurrent N      Max concurrent requests (default: 5)
  --delay SEC             Delay between requests (default: 0.5)
  -n, --dry-run           Preview changes without modifying files
  -v, --verbose           Verbose output
  -q, --quiet             Minimal output

Template Placeholders

Placeholder Description Example
{artist} Artist name Queen
{title} Track title Bohemian Rhapsody
{album} Album name A Night at the Opera
{year} Release year 1975
{genre} Genre Rock
{track} Track number 01

๐Ÿ“Š Output Example

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘  ๐ŸŽต Music Recognition v1.0.0                                 โ•‘
โ•‘  Identify โ€ข Tag โ€ข Rename โ€ข Organize                          โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

Processing: /music/old_collection
Actions: tag, rename

[150/150] 100.0% โœ“ Unknown Track.mp3

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  SUMMARY
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  Total files:    150
  Processed:      150
  Recognized:     142
  Failed:         5
  Skipped:        3
  Success rate:   94.7%
  Duration:       125.3s
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

๐ŸŽฏ Use Cases

  • Digital hoarders: 50GB folder of Track01.mp3 from 2005
  • DJs: Tracks from old mixtapes without metadata
  • Media server admins: Plex/Jellyfin shows "Unknown Artist"
  • Music collectors: Vinyl rips without proper tags

๐Ÿ”ง Supported Formats

Format Read Convert to MP3
MP3 โœ… โ€”
WAV โœ… โœ…
FLAC โœ… โœ…
M4A โœ… โœ…
OGG โœ… โœ…
OPUS โœ… โœ…

๐Ÿงช Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest -v

# Run tests with coverage
pytest --cov=music_recognition --cov-report=html

# Format code
black src/
isort src/

๐Ÿ“„ License

MIT License โ€” use freely.

๐Ÿ™ Credits

  • ShazamIO โ€” Python Shazam API wrapper
  • Mutagen โ€” Audio metadata library
  • PyDub โ€” Audio format conversion

Like this project? Give it a โญ on GitHub!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

music_recognition_tool-1.2.1.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

music_recognition_tool-1.2.1-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file music_recognition_tool-1.2.1.tar.gz.

File metadata

  • Download URL: music_recognition_tool-1.2.1.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for music_recognition_tool-1.2.1.tar.gz
Algorithm Hash digest
SHA256 09ba4a6d56a3bcd8199f10fd8efbc8f8b6e16bc9da7d923e378dc4414476d6d1
MD5 3dfa3b8597da0071079d3546d4ead132
BLAKE2b-256 bfdf1c9a7471eea7d32d346700c9471f539da804bae1722cc20d8d08d439135c

See more details on using hashes here.

File details

Details for the file music_recognition_tool-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for music_recognition_tool-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e432db5d4ddc54b8f35e8d2970f2231ed5c919fc14f11e3c6001b30f809d7d5d
MD5 68b593d438097d996db6d2497245fde0
BLAKE2b-256 b147e602ec8283c58389e6f2142ec6e0df66b8e49144df7edadd78ef4ee5325a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page