Profile

MusicDirStat: Visualizing my FLAC Library with Python

Published on 2026.05.05

Introduction

My music library is constantly growing, especially since I started collecting high-resolution FLAC files. I needed a way to quickly see which artists or albums were eating up the most space on my NAS. While tools like WinDirStat exist, I wanted something lightweight and cross-platform that I could run directly from my dev environment. So, I built MusicDirStat.

The Tech Stack

I chose CustomTkinter for the GUI because it provides a modern, macOS-like dark mode that fits the aesthetic of my other tools. The backend is pure Python, leveraging the os module for filesystem traversal and threading to keep the interface responsive during deep scans.

Core Engineering Challenges

1. Non-Blocking IO

Scanning thousands of audio files can take time. If I ran the scan on the main thread, the window would freeze. I implemented a threaded scanner that communicates with the UI via a thread-safe queue.

scan_thread = threading.Thread(
    target=self.scan_directory_thread, 
    args=(self.music_path, self.scan_queue)
)
scan_thread.daemon = True
scan_thread.start()

2. Recursive Size Attribution

One of the trickiest parts of building a "DirStat" clone is ensuring that the size of a folder accurately includes the size of everything inside it. I used a recursive walk that propagates file sizes up the directory tree during the initial scan.

Feature Highlights:

  • Hierarchical Tree View: An expandable list that lets me drill down from "Genre" to "Artist" to "Album."
  • Automatic Sorting: Folders are automatically sorted by size (largest first), instantly highlighting the "space hogs."
  • Dynamic Formatting: Raw bytes are converted to KB, MB, or GB on the fly for better readability.

Design Decisions

I went with a #2b2b2b field background and #1f6aa5 selection color to match my Neovim theme. The goal wasn't just utility; it was to build a tool that felt like a native part of my workstation.

Conclusion

MusicDirStat has already helped me identify several duplicate album versions I didn't know I had. It’s a testament to how a few hours of Python scripting can solve a specific, persistent problem. Next, I plan to add metadata parsing to show "Total Play Time" alongside file size.

Comments

← Back to Home