Author Topic: Direct read/write access to .mbl library?  (Read 2448 times)

c-Row

  • Jr. Member
  • **
  • Posts: 47
Is there any way to directly interact with the MusicBee library from a standalone application? Following another forum topic I was under the impression that it was a SQLite database, but the DB Browser app does not recognize it as such.

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
No there isn't...not exactly.

Why do you want to directly read/write to that file?
It won't be long before you corrupt it.

The additional tagging and reporting tools plugin has a library reports command that'll allow you to draw library stats.
Perhaps that will suffice for your requirements?

Edit: typo
Last Edit: September 18, 2024, 08:04:42 PM by Mayibongwe
Strength and Honour (2025)

c-Row

  • Jr. Member
  • **
  • Posts: 47
I would like to extract information from Discogs based on the release ID I am storing in a custom tag and apply that information to entries in the library, like label and cat# (for which I have set up custom tags as well), and the combined credits of both the overall release and the individual tracks.

I am coming from an application/database driven coding background so working with databases is an approach I am already familiar with. Getting data from Discogs was surprisingly straightforward as well, but the MusicBee API just does not click with me yet - I would rather create a small standalone app rather than a plugin as this is the environment I am used to.

boroda

  • Hero Member
  • *****
  • Posts: 5207
.mbl file is not SQLite database, and most likely is not some database at all. i vaguely recall that Steven has said some time ago that .mbl file is just MB RAM state saved to file. also, notice that .mbl format can be suddenly changed without any warnings.

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
...but the MusicBee API just does not click with me yet - I would rather create a small standalone app rather than a plugin as this is the environment I am used to.
I understand, but why not take a deep dive into this new environment for learning purposes?
I didn't know jack about APIs till I arrived at this forum, and the wealth of knowledge I've picked here has been useful even outside of the internet.

Getting tag info from MusicBee should be less than 2 lines of code.
Writing to a MusicBee tag should also be less than 2 lines of code.
The rest of it will just be your code on the discogs side which will have to happen anyway with or without the MusicBee API.

So if you're interested in those <4 lines of code you have to go through, we can definitely work on it.
There are existing threads here on these lines that we can point you to if you're interested.

What say you?
Strength and Honour (2025)

c-Row

  • Jr. Member
  • **
  • Posts: 47
I am certainly willing to look into it. The documentation has not been of much help but a forum thread might be easier to follow.

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
First, you'll want to grab the latest MB interface file from here: https://getmusicbee.com/forum/index.php?topic=1972
I use C#, but regardless of whichever you choose, the syntax shouldn't be far off.

To initialize the plugin, you'll need to have the following which you'll find in TestCSharpDll.cs
Code
using System;
using System.Runtime.InteropServices;

namespace MusicBeePlugin
{
    public partial class Plugin
    {
        private MusicBeeApiInterface mbApiInterface;
        private PluginInfo about = new PluginInfo();

        public PluginInfo Initialise(IntPtr apiInterfacePtr)
        {
            mbApiInterface = new MusicBeeApiInterface();
            mbApiInterface.Initialise(apiInterfacePtr);
            about.PluginInfoVersion = PluginInfoVersion;
            about.Name = "Plugin Name";
            about.Description = "A brief description of what this plugin does";
            about.Author = "Author";
            about.TargetApplication = "";
            about.Type = PluginType.General;
            about.VersionMajor = 1;
            about.VersionMinor = 0;
            about.Revision = 1;
            about.MinInterfaceVersion = MinInterfaceVersion;
            about.MinApiRevision = MinApiRevision;
            about.ReceiveNotifications = (ReceiveNotificationFlags.PlayerEvents | ReceiveNotificationFlags.TagEvents);
            about.ConfigurationPanelHeight = 0;
            return about;
        }

        public bool Configure(IntPtr panelHandle)
        {
            return false;
        }

        public void ReceiveNotification(string sourceFileUrl, NotificationType type)
        {
        }
   }
}

Tag Retrieval:
Code
mbApiInterface.Library_GetFileTag(string sourceFileUrl, MetaDataType field);
Quote
e.g How to retrieve the title tag of the playing track

string title;
string playingTrackUrl = mbApiInterface.NowPlaying_GetFileUrl();

title = mbApiInterface.Library_GetFileTag(playingTrackUrl, MetaDataType.TrackTitle);

Tag Setting:
Code
mbApiInterface.Library_SetFileTag(string sourceFileUrl, MetaDataType field, string value)
Quote
e.g How to change the album title of the playing track

mbApiInterface.Library_SetFileTag(playingTrackUrl, MetaDataType.Album, "Greatest c-Row Hits");
mbApiInterface.Library_CommitTagsToFile(playingTrackUrl)
mbApiInterface.MB_RefreshPanels()

Edit:
This is one of the few MusicBee questions I'm more than happy to help someone with on the step-by-step. So feel free to ask everything.
A list of open_source plugins: https://getmusicbee.com/addons/s/?q=open_source&type=2
Last Edit: September 21, 2024, 01:18:35 PM by Mayibongwe
Strength and Honour (2025)

c-Row

  • Jr. Member
  • **
  • Posts: 47
Please excuse my silence on this matter, it's just that I could not invest the time needed to check out your instructions in full until earlier today.

I downloaded the interface file and followed the instructions found in the tutorial. Unfortunately it seems to miss some bits in the "Give The Button Something To Do" chapter but it nevertheless got me up and running (or at least walking). What my plugin does so far is fetching the currently selected tracks and applying some text to the comment tag - it's not much but it's already pieces of what it needs to do later so we are definitely off to a good start.  :D

Off to the next task then - show the form and have the user enter the Discogs release ID, then return that to the plugin to use it to fetch the Discogs info.

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
I'd forgotten about the tutorial on the MusicBee wiki which certainly covers the very first steps before one can even look at the API - thanks for linking that here.

Unfortunately it seems to miss some bits in the "Give The Button Something To Do (pause and play MusicBee depending on it's state)" chapter ...
It doesn't look like it to me - what in particular would you say needs to be added there?
There's a description of all the functions one would require to make the button functional:

1. Defining the event that's called when the button is clicked     --    button1_OnClick()
2. Within the event scope, getting the current play_state of MB   --   Player_GetPlayState()
3. Depending on the state, making MB resume or pause playback  --  Player_PlayPause()

I wouldn't expect the introductory tutorial to delve much into things like what parameter(s) button1_onClick supports as that is now Windows territory.
So that's what the dotNet documentation and stackOverFlow would be for: https://learn.microsoft.com/en-us/dotnet/api

...but it nevertheless got me up and running (or at least walking).
What my plugin does so far is fetching the currently selected tracks and applying some text to the comment tag
...it's not much but it's already pieces of what it needs to do later so we are definitely off to a good start.  :D
But really glad to hear that you're up and walking ;-/ running by yourself so fast (already past the 'unfamiliar environment' which you were hesitant on taking on at first).
The bits now remaining are largely what you were going to have to do anyway - even with the standalone app.
Looking forward to the release when ready (if it's in your plans to share the final product with other users).
Last Edit: September 28, 2024, 07:50:41 AM by Mayibongwe
Strength and Honour (2025)

c-Row

  • Jr. Member
  • **
  • Posts: 47
But really glad to hear that you're up and walking ;-/ running by yourself so fast (already past the 'unfamiliar environment' which you were hesitant on taking on at first).
The bits now remaining are largely what you were going to have to do anyway - even with the standalone app.

Indeed, it turned out the deep end I had to jump in was not quite as deep as I had feared, not least to a little encouragement from your side. What gave me some trouble was that the library I had looked into to retrieve information from Discogs did not work with the frameworks supported by DLL but the second most popular package was up to the task just as well, and I already got the basics up and running now - the form is asking for the release ID, retrieves all data and applies it to the currently selected tracks both globally (publisher, release date, label, catno) and on a per-track basis (track title so far but with more hopefully being added over the weekend).

Looking forward to the release when ready (if it's in your plans to share the final product with other users).

I would love to as it would certainly be useful to a lot of people, but considering a lot of the data I process is then stored in custom tags it would require a way to configure which piece of information should go into which tag in what specific format rather than have it all hardcoded to my preferences. Not saying it's completely off the table, though.  ;)