Metadata-Version: 2.4
Name: music-rename
Version: 0.2.0
Summary: Rename katakana artist names (and Japanese song/album titles) of non-Japanese artists in the macOS Music app to their original English names.
Keywords: apple-music,macos,music,metadata,katakana,itunes
Author: yoshioyamazoe
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Environment :: MacOS X
Classifier: Intended Audience :: End Users/Desktop
Classifier: Natural Language :: Japanese
Classifier: Natural Language :: English
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Multimedia :: Sound/Audio
Requires-Dist: pyjwt[crypto]>=2.8 ; extra == 'musickit'
Requires-Python: >=3.11
Project-URL: Homepage, https://github.com/yoshio-yzoe/music-rename
Project-URL: Issues, https://github.com/yoshio-yzoe/music-rename/issues
Provides-Extra: musickit
Description-Content-Type: text/markdown

# music-rename

[日本語](README.ja.md)

Rename **katakana artist names of non-Japanese artists** in the macOS Music app
(e.g. `マドンナ` → `Madonna`, `エルトン・ジョン & キキ・ディー` → `Elton John & Kiki Dee`)
while leaving Japanese artists (`スピッツ`, `ヨルシカ`, ...) untouched.
Japanese **song and album titles** of non-Japanese artists are put back to the catalog's
English titles as well (e.g. Tom Waits `地獄に落ちた男の歌` → `Down, Down, Down`).

- Works without any account: English names come from the public **iTunes Search API**.
- Optional **Apple Music API (MusicKit)** support if you are in the Apple Developer Program.
- You review every change in a **CSV** first (can be turned off).
- Every write is recorded first, and **`undo`** puts everything back.

## Requirements

- macOS with the Music app (tested on macOS 26)
- Python 3.11+
- On first run macOS asks whether your terminal may control **Music**. Allow it
  (System Settings → Privacy & Security → Automation).

## Install

```sh
uv tool install music-rename          # or: pipx install music-rename
uv tool install 'music-rename[musickit]'   # with Apple Music API support
```

## Usage

Keep the Music app open.

```sh
music-rename scan                     # list katakana names (no network)

music-rename plan -o plan.csv         # look up English names, write a CSV
#   edit plan.csv: set action to apply/skip, fix "proposed" if needed
music-rename apply plan.csv --dry-run # show what would change
music-rename apply plan.csv           # rename

music-rename undo ~/Library/Application\ Support/music-rename/backups/<file>.jsonl
```

### Review on / off

| | review on (default) | review off |
|---|---|---|
| Command | `plan` → edit CSV → `apply` | `run --no-review` (or `review = false`) |
| Foreign, high confidence | apply | apply |
| Foreign, medium / low confidence | skip (decide in the CSV) | **apply** |
| Looks Japanese | skip | skip |

Even with review off a CSV record and a backup are written, so `undo` always works.
**Try review on first**: the Japanese/foreign guess is only a guess.

### CSV columns

| column | meaning |
|---|---|
| `action` | `apply` or `skip` — edit this |
| `original` | current value in the library (do not edit) |
| `proposed` | new value — edit if you prefer another spelling |
| `confidence` | `high` / `medium` / `low` / `none`: how well the catalog artist's albums and songs match your library. A `medium` name is raised to `high` when one of your songs is credited to exactly the proposed English name in the catalog (iTunes source only; adds about 6 seconds per song checked) |
| `origin` | `jp` / `foreign` / `unknown` and `origin_reason`: why |
| `fields` | `artist;album_artist` for artist rows, `name` (song title) or `album` for title rows |
| `artist` | title rows only: the artist (after this apply) whose tracks are changed |
| `track_count`, `sample_albums`, `catalog_url`, `note` | context for your review |

## How it decides

1. **Candidates**: the katakana name is searched in the Japanese storefront with English
   localization (`lang=en_us`). Collaborations (`A & B`, `A feat. B`) are tried as a
   whole first (so `サイモン&ガーファンクル` → `Simon & Garfunkel`), then part by part.
2. **Confidence**: album and song titles of the candidate are compared with what is in
   your library. `high` = at least 1 album or 2 songs match.
3. **Japanese or not**: names with kanji/hiragana are Japanese. Otherwise MusicBrainz
   (country `JP`) and Japanese genres (J-Pop, Anime, ...) are used. Apple's catalog has
   no "country" field, so MusicKit does not improve this part.
4. **Song and album titles**: only for artists that MusicBrainz places outside Japan
   (no Japanese genre, not in `[exclude]`), so English-named Japanese acts keep their
   Japanese titles. The album is looked up in the Japanese and the English (`verify_country`)
   storefronts and each track is matched by its catalog ID, so translated titles that look
   nothing alike still match. Nothing is guessed: albums missing from the English store are
   left as they are. Needs the iTunes source; about 9 seconds per album the first time.

## Configuration

See [`config.example.toml`](config.example.toml). Copy it to
`~/.config/music-rename/config.toml`. Useful settings:

- `[exclude] artists`: names you never want renamed
- `[overrides]`: your own `"カタカナ" = "English"` dictionary (used before the APIs)

### Apple Music API (optional)

1. Create a MusicKit key in your Apple Developer account and download the `.p8` file.
2. Set `[musickit] key_path`, `key_id`, `team_id` (or the `MUSIC_RENAME_MUSICKIT_*`
   environment variables) and run with `--source musickit`.

The key stays on your machine; the developer token is generated in memory.

## Notes and limits

- **Speed**: the iTunes Search API allows about 20 calls per minute, so the first run
  takes about 6 seconds per name. Results are cached for 30 days.
- **iCloud Music Library**: renamed Apple Music tracks kept their new names on the Mac
  and synced to iPhone in our tests, but Apple may change this behaviour.
- Smart playlists that filter on an artist name will need to be updated by hand.
- Sent to the APIs: artist names; album names of non-Japanese artists whose titles are Japanese (drop `name` and `album` from `fields` to turn that off); up to two song titles per `medium` name when confirming it by song (`verify_titles = 0` turns that off). Nothing else from your library leaves your Mac.

## Development

```sh
uv sync
uv run ruff check && uv run ruff format --check && uv run mypy && uv run pytest
MUSIC_RENAME_TEST_PID=<persistent id> uv run pytest -m music   # touches one real track
uv run python scripts/smoke_live.py                            # checks the live APIs
```

## Releasing

Bump `version` in `pyproject.toml`, commit, then push a matching tag (`git tag v0.1.0 && git push origin v0.1.0`). The Release workflow tests, builds and publishes to PyPI via Trusted Publishing.

## License

MIT
