MyMP3Collection

MyMP3Collection / Technical description

MyMP3Collection

Architecture, Docker mounts, scanning, info and covers, playback, playlists, export, data model and HTTP interface in MyMP3Collection, the overview of the MP3 collection.

Version 1.0.0Revised 2026-11-18Flask · SQLite · Docker

1. Purpose

MyMP3Collection gives an overview of a collection of audio files kept in ordinary folders on the Mac or on external drives. The app reads the tags, groups tracks into albums, fetches info and covers, plays music and makes playlists.

The ground rule is that the audio files are never copied or changed. The database only stores the path to each file. The single exception is export, where you yourself ask for chosen albums to be copied to another drive.

2. Architecture

  Browser   ──HTTP:5070──▶ Docker-container «mymp3collection»
                            gunicorn (1 process, threads ) + Flask
                              │              │               │
                              ▼              ▼               ▼
                       data/music.db   data/covers/    data/backups/
                       SQLite (WAL)    cover images    zip files

  Mounted in the container
    /music          ◀── MUSIC_DIR from .env           read only
    /host/Users/…   ◀── home folder (~)               read only
    /host/Volumes   ◀── external drives               read-write (only Eksport_…)
    /export         ◀── ./eksport in project          read-write

  Background threads: scanning (mutagen) · fetch info (MusicBrainz, Discogs) · export

3. Folders and Docker mounts

On the MacIn the containerAccessUsed for

MUSIC_DIR (.env)

/music

read only

The main folder. Also used in LIBRARY_ROOTS to show Mac paths

~

/host/Users/…

read only

Extra music folders in the home folder

/Volumes

/host/Volumes

read-write

Music on external drives, and export. The app only writes to new Eksport_… folders

./eksport

/export

read-write

Export without a USB drive

./data

/data

read-write

Database, covers and backups

HOST_PREFIX=/host lets the app translate between container paths and Mac paths, so the paths shown and copied can be pasted straight into Finder. New root folders that overlap an existing one are refused.

The Apple Music folder has extra protection in macOS. Docker Desktop must have Full Disk Access, otherwise the mount fails with “operation not permitted” or the folder looks empty.

4. Scanning

  1. All root folders are walked. Folders the app cannot read, and other file types found, are reported, so you can see why something is missing.

  2. Files with the same size and modification time as last time are skipped. New and changed files are read with mutagen.

  3. Tracks are grouped on album_key: normalised album title and folder. CD1, Disc 2 and similar subfolders belong to the folder above.

  4. Covers are taken in the order embedded image, image file in the folder, and finally MusicBrainz or Discogs in the “Fetch info” step.

  5. Files that no longer exist are marked missing and removed with Clean up. Albums you have edited (locked) are not overwritten.

Supported file types: MP3, M4A, M4P, M4B, FLAC, OGG, Opus, WMA, AAC, AIFF and WAV. Protected M4P files from iTunes are registered but cannot be played in the browser.

5. Info and covers

  • MusicBrainz: at most one request per second, with a User-Agent containing the contact address from Settings. 503 responses are retried after 2, 4 and 8 seconds.

  • The match must be close enough to the album's artist and title. The original year comes from the release group, and the cover from the Cover Art Archive.

  • Discogs is used as a fallback when MusicBrainz cannot find the album, and requires a free personal token.

  • Covers are stored as copies in data/covers/. The tags in the audio files are never changed.

6. Playback and playlists

Audio is sent straight from the file with Flask's send_file and HTTP Range support, so seeking works without anything being copied. The player sits above the track list and plays on through the album or list.

A playlist can be exported as .m3u with Mac paths, or as JSON:

{
  "format": "MyMP3Collection-playlist",
  "version": 1,
  "name": "Bilturen til hytta",
  "description": "Lange strekninger, høy volum",
  "track_count": 11,
  "duration_seconds": 2853.0,
  "tracks": [
    {
      "position": 1,
      "title": "Take On Me",
      "artist": "a-ha",
      "album": "Hunting High and Low",
      "track_number": 1,
      "year": 1985,
      "duration_seconds": 225.0,
      "path": "/Users/ola/Music/a-ha/Hunting High and Low/01 Take On Me.mp3",
      "file": "01 Take On Me.mp3"
    }
  ]
}

On import each track is found again by its path, or by artist and title if the path does not exist on this computer. Tracks that cannot be found are skipped and counted.

7. Export

/Volumes/USB500/
└── Eksport_2026-11-18/
    ├── Innhold.txt
    ├── a-ha/
    │   └── Hunting High and Low (1985)/
    │       ├── cover.jpg
    │       ├── 01 Take On Me.mp3
    │       └── …
    └── Kaizers Orchestra/
        └── Ompa til du dør (2001)/
            └── …
  • Before copying, free space and write access are checked. Space for everything plus 1% and 50 MB is required.

  • Each file is copied to a .part file, checked for size and renamed at the end. The modification time is kept.

  • Characters FAT32 and exFAT do not accept are replaced. Multi-disc albums get CD1/CD2.

  • If the folder already exists, the new one becomes Eksport_2026-11-18_2. Existing files on the drive are not touched.

8. Data model

A single SQLite file, data/music.db, in WAL mode so pages can be read while the scan writes.

TableContent

albums

One album per album_key (normalised album title + folder). Artist, title, year, genre, label, cover and source, MusicBrainz and Discogs IDs, notes, locked for edited albums, and totals for tracks, playing time, size and missing files

tracks

One track per file, unique on path. Size and modification time (to skip unchanged files), the tags, playing time, bitrate and missing

playlists, playlist_tracks

Playlists and their tracks, with position. Deleting a track removes it from the lists

exports

Export history: destination, folder, number of albums and files, bytes, errors and status

settings

Key/value: collection name, owner, extra root folders, Discogs token and MusicBrainz contact address

9. Backup and moving

A backup is a zip with manifest.json, a consistent copy of music.db and covers/, but never the audio files. Before a restore a safety copy of the current data is made.

Tracks are stored with their container path (/music/…). When MUSIC_DIR on the new computer points to a folder with the same structure, every track is recognised at the next scan, with info, edits and playlists. pakk.sh includes pending WAL changes.

10. HTTP interface

RouteWhat it does

GET /

All albums. View, search, genre and sort as parameters

GET /album/<id>, GET/POST …/rediger

The album page and editing with MusicBrainz and Discogs search

GET /artister, GET /spor

Artists and all tracks

GET /spor/<id>/lyd

The audio file, sent straight from its path with Range support (seeking)

GET/POST /skann, …/status, …/stopp

Start, follow and stop the scan

GET /api/mapper, POST /skann/mapper/legg-til, …/fjern

The folder picker and the list of root folders

GET/POST /hent-info, …/status

Fetch info and covers for many albums

GET/POST /eksport, …/status, …/stopp

Export to a drive

/spillelister, /spilleliste/<id>, /api/spilleliste/<id>/…

Playlists: create, add, remove, reorder, import

GET /spilleliste/<id>/eksport.json, ….m3u

Export of a playlist

GET/POST /innstillinger, /backup/…

Settings, backup and restore

11. Source code

FileContent

app.py

The Flask app: routes, database, playlists, settings and backup

library.py

Scanning: tags with mutagen, album grouping, covers from file and folder

metadata.py, discogs.py

Lookups in MusicBrainz, Cover Art Archive and Discogs

exporter.py

Export: plan, space, safe file names and copying via .part files

templates/, static/

The pages, the stylesheets (style.css shared with MyRecordCollection, mp3.css) and the language files

scripts/

installer.sh and pakk.sh

Dependencies: Flask 3, gunicorn and mutagen. Language and theme work as in MyRecordCollection.

Screenshots, installation and how it works: Back to the front page