Crates.io | librmo |
lib.rs | librmo |
version | 0.4.0 |
source | src |
created_at | 2024-04-13 15:50:57.002055 |
updated_at | 2024-09-30 17:16:00.214744 |
description | A library to manage media files and play them |
homepage | https://github.com/samuelshiels/rmo |
repository | https://github.com/samuelshiels/rmo |
max_upload_size | |
id | 1207674 |
size | 1,112,810 |
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.
[dependencies]
# Add to dependencies
librmo = "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
use librmo::migration;
migration::run().await;
Now the backend is ready, we can then provide a library directory to start collection from:
use librmo::media_manager::MusicManager as MM;
let lib_name = "MyMusic";
let lib_path = "/path/to/music";
MM::insert_library(lib_name, lib_path).await?;
We can confirm this library exists:
use librmo::media_manager::MusicManager as MM;
use librmo::entity::library::Model as LibraryModel
let libraries: Vec<LibraryModel> = MM::get_library().await?;
println!("{:?}", libraries);
// [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 librmo::media_manager::MusicManager as MM;
let mm = MM::new(None);
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 librmo::media_checker::MusicChecker as MC;
MC::execute().await?;
So a full process can be
migration::run().await?;
let lib_name = "MyMusic";
let lib_path = "/home/samuel/Music";
MM::insert_library(lib_name, lib_path).await?;
MM::execute().await?;
MC::execute().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 librmo::media_validator as MV;
let reports = MV::get_reports().await?;
println!("{} Reports - {:?}", reports.len(), reports);
//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 = MC::get_tracks().await?;
//or
let albums = MC::get_albums().await?;
// Use your favourite method of selecting a record
let release_id = tracks[albums.len() - 1].mb_release_id.clone();
MC::generate_album_art_by_release_id(release_id)
MC::generate_album_art_full_by_release_id(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
Fedora
sudo dnf install gcc pkg-config perl-FindBin openssl-devel alsa-lib-devel
music
records and compare there rather than 1 by 1report
tablereport
entry if too small