Playlist Duration Analyzer
Build a C++ command-line tool that reads a music playlist in the M3U format, the format used by VLC, Winamp and many music players, and reports on it: the total length (for example 3 h 42 min), the longest and shortest tracks, the average track length, and which artists appear most often. It reads the #EXTINF lines that store each track's length, artist and title, and warns about lines it can't understand. It's a solid beginner C++ project: you'll learn classes and structs, std::vector and std::map, reading files line by line, parsing text, using a Boost library for command-line options, and building with CMake.
- Estimate
- ~8h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
CMake · Boost
Project roadmap
- 01
Set up the project
~1hCreate a CMake project using C++17. Install Boost and link Boost.Program_options with find_package(Boost REQUIRED COMPONENTS program_options). Add samples/playlist.m3u with at least 20 tracks in the extended format, where each track has a line like #EXTINF:215,Queen - Bohemian Rhapsody followed by the file path, and include a few malformed lines. Done when: the project builds, and running it prints Hello.
- 02
Read the command-line options
~1hUse Boost.Program_options to accept a playlist file (as a positional argument), --top N (how many tracks and artists to show, default 5) and --help. Print the help text when --help is given or the file is missing. Done when: playlist --help prints the options, and a missing file gives a clear message.
- 03
Parse the playlist
~2hDefine a Track struct with duration in seconds, artist, title and path. Read the file line by line with std::getline, check that the first line is #EXTM3U, and parse each #EXTINF line: the number after the colon is the duration and the text after the comma is Artist - Title (use Unknown artist when there's no dash). The next non-comment line is the track's path. Warn with the line number about lines that don't fit. Done when: the sample playlist is read into a std::vector<Track>, and bad lines produce warnings.
- 04
Calculate the statistics
~1.5hWrite functions that compute the total duration, the average duration, the N longest and N shortest tracks (with std::sort or std::partial_sort) and the number of tracks per artist (with a std::map). Ignore tracks with an unknown duration (-1) in the duration calculations, but count them. Done when: the results for the sample playlist are correct.
- 05
Print a readable report
~1hWrite a helper that formats seconds as h:mm:ss or m:ss, and print a report with the number of tracks, the total and average length, the longest and shortest tracks, and the top artists sorted by track count, all aligned with std::setw. Done when: the report is clear and aligned.
- 06
Write tests
~1.5hAdd a test executable (registered with CTest) that checks parsing of valid and malformed lines, a title without an artist, the duration formatting (59 s, 61 s, 3,725 s), and the artist counts, using small playlists written as strings in the tests. Done when: ctest passes.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack