Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Last.fm Genre Tagger

Automatically tags your FLAC music library with genre data from Last.fm.

Requirements

Python 3.x and the following packages:

pip install mutagen requests python-dotenv

Setup

  1. Get a free Last.fm API key at https://www.last.fm/api/account/create

    • App name: anything (e.g. "Music Tagger")
    • App description: anything
  2. Create a .env file in the same folder as the script:

LASTFM_API_KEY=your_api_key_here
  1. Edit the MUSIC_DIR variable in the script to point to your music folder:
MUSIC_DIR = r"D:\Music\Songs"

Usage

python lastfm_genre_tagger.py

Configuration

Inside the script, you can adjust these settings:

Setting Default Description
MUSIC_DIR D:\Music\Songs Path to your music library
MAX_GENRES 3 Max number of genres to write per track
MIN_TAG_COUNT 10 Minimum Last.fm tag popularity (filters noise)
SKIP_IF_HAS_GENRE True Skip files that already have a genre tag
RATE_LIMIT_DELAY 0.25 Seconds between API calls (don't go below 0.25)

How It Works

  1. Scans all .flac files recursively in MUSIC_DIR
  2. For each file, reads the artist and title tags
  3. Queries Last.fm track.getTopTags for genre tags
  4. If no track tags found, falls back to artist.getTopTags
  5. Filters out noise tags (seen live, favorites, etc.)
  6. Writes genres back into the FLAC file's genre tag
  7. Skips files that already have genre tags (preserves already tagged files)

Runtime

~30-40 minutes for 3800 files at the default rate limit.

After Running

Once complete, use Mp3tag to export your library tags to CSV:

  1. Open Mp3tag, load your music folder
  2. File → Export
  3. Export with Title, Artist, Album, Genre columns

Then use the exported CSV to regenerate genre-based M3U playlists.

Notes

  • Obscure indie tracks may still have no genre if Last.fm has no data for them
  • The script is safe to re-run — it skips already-tagged files by default
  • Set SKIP_IF_HAS_GENRE = False to overwrite existing genre tags

About

CLI tool to batch-tag genre metadata on downloaded music files — pairs with music-genre-playlist-creator to build genre-sorted playlists for a DAP.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages