Project: Media Database Generator for MPD We need a utility that will generate a media database for mpd. mpd is able to generate it's own database, however there are a few issues related to modifications made by a fork that result in some issues in parsing media files. Not only will this utility take steps to solve these problems; but sometimes the first launch of mpd can take forever and cause systemd service timeouts trying to index very large collections. This should be a standalone utility that runs from command line/terminal. It can be written in the same language as mpd; as that will make it easier to grab the related code. It might even be easier to start with the mpd source and "strip it down" to just database creation functions. A copy of the mpd repository is in the mpdsrc/ directory. There are three main areas that need attention. The first is multichannel audio. We have multichannel content in our library; but we don't have multichannel playback hardware. Therefore we don't really need multi-channel stuff in our mpd database. Maybe someone else does. We need an argument that will let the user if they want stereo only, multichannel only, or maybe to keep both. The second area are with CUE files. By default if mpd finds a cue file; it seems to rely on only that cue file for media information; even if there are media files. However the non-standard CUE files often aren't parsed correctly; and there are legitimate reasons we want to parse the CUE file. This is explained in detail below. The last area is SACD content. We need to filter out multi-channel and stereo content according to the user's preference. We also need to clean up a pair of tags for each SACD entry to make it more human readable. This is also explained in detail below. Ideally, it should work like this: - A user runs `./mpddb -stereo /mnt/music /var/lib/mpd/mpddb` from the command line. - It generates a database scanning /mnt/music filtering out multi-channel content, ignoring .CUE files as required, and cleaning up all SACD entries. - It saves the database to the directory specified. If no output directory is specified; then just save to $PWD CUE Files and Playlists: We can safely ignore any .m3u, .pls, and other playlist files. They will not be of any use for database creation. However, we do need to pay very close attention to CUE files. There are a number of non-standard or broken CUE files that mpd cannot parse. This not only results in that album not fully working; but I'm guessing since mpd sees a .cue it ignores everything else. But we can't completely ignore .CUE files as some albums are stored in a manner that they're required.(FLAC/CUE, WAV/CUE, or sometimes each side of an LP/CUE) So CUE files should be handled in the following manner: count the number of media files (usually FLAC) in the directory, compare to the number of tracks listed in the CUE. If the number of files is less than the CUE track count, use the cue file. Else, ignore the CUE and index the raw media files. In the case we have a multi-channel FLAC, WAV, m4a, or other format that supports it; we should only include these files if the user Some background information on SACD: SACD (super audio compact disc) is a proprietary disc format that uses a delta-sigma modulated bitstream at 2.822MHz per channel; in a format called DSD (Direct Stream Digital). In addition to the change in audio storage; SACD also provides support for 5.1 audio at the same rates. To accomplish this, a lossless compression scheme known as Direct Stream Transport (DST) is used. SACD is able to provide two types of "areas" for storing albums; a stereo area and a multichannel area. Multichannel areas will always use DST compression. It's use on stereo is optional, but commonly used there due to space constraints of a 4.7GB layer with 5.1 content as well. By default, the sacd code provides all available areas to mpd, which adds them to the database. The SACD code however does identify them in both the Album and Title for each track using `2CH` to denote stereo and `MCH` to denote any multi-channel configuration. `Title: 2CH - 06 - In-A-Gadda-Da-Vida` `Album: In-A-Gadda-Da-Vida (2CH-DSD)` `Title: MCH - 01 - No Such Thing` `Album: Room For Squares (MCH-DST)` `Title: 2CH - 05 - Neon` `Album: Room For Squares (2CH-DST)` Notice how 2CH content can be either DSD or DST. Step 1: Stereo (2CH) or Multi Channel (MCH) filtering During database creation, the user should be able to specify if they want stereo, multichannel, or both. Keep only the desired format and ignore/discard the entries for the other. Step 2: Cleaning Up The Entries The `Title:` and `Album:` fields need to be modified. This is determined by which of the stereo or multichannel areas the user has opted to keep. The User Chose One Format: Remove (2CH-DSD), (2CH-DST), or (MCH-DST) from the album field. Remove the 2CH or MCH, along with the dashes and track number from the Title. Example: ` Album: Captain Fantastic And The Brown Dirt Cowboy (2CH-DST) Title: 2CH - 01 - Captain Fantastic And The Brown Dirt Cowboy ` Should become: ` Album: Captain Fantastic And The Brown Dirt Cowboy Title: Captain Fantastic And The Brown Dirt Cowboy ` If the user has opted to keep both; then strip the `Title:` field to just the title as explained above; however modify (2CH-DS?) to (Stereo) and (MCH-DST) to (Multichannel).