libRMO - Rust Media ORM
Provides an ORM to structure referencing media files and metadata. Leveraging this information we can validate the metadata for presence.
From a single entry point of defining at least 1 root folder to start from, generate a full media library and run useful functions off them.
Usage
[]
# Add to dependencies
= "0.1.0"
Initialise the library, this generates the config %XDG_CONFIG_HOME/liborm and cache %XDG_CACHE_HOME/liborm folders, creates the sqlite DB and applies migrations
DB location can be changed via setting environment variable LIBRMO_DB_DIR to a folder path. Running the migration will create directories whether default or overriden.
use migration;
run.await;
Now the backend is ready, we can then provide a library directory to start collection from:
use MusicManager as MM;
let lib_name = "MyMusic";
let lib_path = "/path/to/music";
MMinsert_library.await?;
We can confirm this library exists:
use MusicManager as MM;
use Model as LibraryModel
let libraries: = MMget_library.await?;
println!;
// [Model { id: 1, name: "MyMusic", path: "/path/to/music", files: "" }]
Now we have a root directory to start from we set off the manager. This process is a simple walkdir for each file and we store them away in the database with their full path, modified time, and matching against an interal list of extension enums.
This should be a fast process, ~12s for ~16k files.
We create an instance of the Collector and can supply a Sender<String> to return progress messages
use MusicManager as MM;
let mm = MMnew;
mm.execute.await?;
Then taking each media file in the directory structure we need to work out which music fles we could care about
~20s for ~12k files
This is a much more demanding function, currently generates all the valid track and album records and the album art thumbnail. This is where we read all the tag metadata present on the music records
~30mins for ~12k valid tracks
(An update to lofty to exclude album art reading in the tag retrieval will speed this up to ~5mins)
use MusicChecker as MC;
MCexecute.await?;
So a full process can be
run.await?;
let lib_name = "MyMusic";
let lib_path = "/home/samuel/Music";
MMinsert_library.await?;
MMexecute.await?;
MCexecute.await?;
SeaORM handles repeated migration so its safe to have this function run at every startup of your implementation. Since the entity model library enforces uniqueness on the data an insert of the same library entry can be done without panicing. The checking also leverages the modified time of the files within the directory to only run the expensive tag retrieval on files that have changed since the last run.
We can then query the report table to find entries that do not have enough tag information
use media_validator as MV;
let reports = MVget_reports.await?;
println!;
//14 Reports - [ReportList { report_type: "ALBUMID", path: "/home/samuel/Music/sample_mp3.mp3" }, ... }
Here we see an entry is created for each tag the file is missing alongside the path to the file.
Album art can be generated from the Front Cover entry via the mb_release_id property on either a track or album
let tracks = MCget_tracks.await?;
//or
let albums = MCget_albums.await?;
// Use your favourite method of selecting a record
let release_id = tracks.mb_release_id.clone;
MCgenerate_album_art_by_release_id
MCgenerate_album_art_full_by_release_id
The resulting jpg images will be in %XDG_CACHE_HOME/librmo/album_art or %XDG_CACHE_HOME/librmo/album_art_full with the filename <mb_release_id>.jpg
Build
Fedora
Future features/improvements
Bugs and Performance
- check_media should first get all
musicrecords and compare there rather than 1 by 1 Seperate album art thumbnail generation out into async function, also allow it to be called on demand- Reset DB, currently slow if you delete the library record
Allow clearing down orreporttableDelete media records that are no longer present in the libraryDelete albums if no tracks remain after clearing deleted mediaSpeed up report insert operation- Better description of missing tags in report entries
Features
Allow override of where DB and cache storage is set- Allow choice of artwork thumbnail file format, currently locked at jpg
- Adjust resolution of output file, locked at 300x300
- Check size of artwork and add
reportentry if too small Logger settings and useful messages