Controlling MM5 from external applications

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

Barry4679
Posts: 2198
Joined: Fri Sep 11, 2009 1:07 pm
Location: Australia
Contact:

Controlling MM5 from external applications

Post by Barry4679 »

I have been wanting to control MM5 from an external (python) app, like I did with MM5, for a long time. I have asked here before, but at the time I was unable to understand the advice I was given. It all seemed broken, and there was zero documentation if one was not working with javascript.

The Developer page in the Wiki has just a fraction of the material that is available for MM4. It has said "More Coming soon (MediaMonkey)" since forever.

So I was very pleased to notice today that Drakinite has posted up something that was genuinely useful. It broke through for me, as prior snippets that I had been given caused MM5 to break.

So many thanks Drakinite. I wonder if I could contribute a sub-page to your effort, to contain a Python specific page to help anyone get started ? .... PM me through the forum if you like.

The sample that Drakinite used as illustration in his wiki page is close to what I had been asking about. If that is not a happy coincidence, thank you for that too Drakinite.

Some comments:
  1. . Why is MM5 so fragile when running code that it received via SDB.runJSCode calls?

    Example:
    PetrCBR wrote: Fri Mar 30, 2018 10:13 am Your example does not work because you didn't returned value from getStringValue. app.getIniFile is asynchronous operation so you want to return value using runJSCode_callback (since MM5 2090).

    Code: Select all

    SDB.runJSCode("(function() { app.getIniFile().then(function(iniFileAccess) { runJSCode_callback(iniFileAccess.getStringValue('System','DBName'))   }); })()", True)
    That call, and all my attempts to fix it, caused MM5 to break ... MM5 panel goes white .. all MM5 tasks need to be individually killed by the Windows Task Manager.

    Why does a syntax error crash MM5?

    And sometimes after it fails, and I have done the above housekeeping, connection is difficult to reestablish. .. (-2147023170, 'The remote procedure call failed.', None, None) ... and this where what was working before now fails

    Can that be improved?
  2. I also see your efforts on this page ... ie. The "supported in MM5?" column for the SDBApplication ActiveX class.
    I looks like you were starting something that you didn't finish.
    Is there any list of what was converted to MM5?
    It seems to me to be a waste of their effort if they don't make any of it discoverable.

    ie. did this happen?
    Ludek wrote: Sun Dec 10, 2017 10:55 am Anyhow looking into our code you seem to be right that SDBPlayList is not fully implemented, most of the code of the corresponding properties/methods is commented out.
    Seems to make sense to add them, going to discuss with other devs and look into it.
    I know that ActiveX is not cross platform, but it very useful for anybody not from a web programming background, ie doesn't know javascript .. which atm seems about as much fun as poking sharp sticks into my eyes
  3. What is the easiest way to test JS functions before sending them to to MM5?
    Example; the function that you ran to generate the playlist contents. what tool did you, when you were a pennyless student :) , use to test a function like that?

    Is testable from the Shift+Ctrl+Alt DevTools Console that opens in the browser? ... Else what do you recommend for casual use?
  4. The script that you used in your Wiki article gets me going, which is good.

    But I am using it against MM5 AutoPlaylists. I have no control over how large the generated playlist may be, and I potentially have many playlists to generate, and it all happens during the close down of my app, so is noticeable if there is a delay. That method sends 55 (!) attributes per track, including lyrics.

    My preference would be something that did something like this:
    1. either trigger SendTo, for the tracks generated by AutoPlaylist 'xxx', to Static Playlist 'yyy' ... ie. all done inside the mm5 db, without getting all the 55 columns, and converting up and down into json
    2. or return the SQL statement which generated the tracklist ... it should be available because I can see it logged into the MM5 debug log. Much of he time I only need the album ids, so I only really need the Where, ORDER and Limit clauses
    My application has attached the MM5.db database, so I could then read what I want from there, directly.
    I am likely to be able to achieve that?

    [UPDATE] re Q.2 ... the bit asking whether SDBPlayList was added to the MM5 COM implementation.

    I see the answer. I have found out how to browse your COM package, and see that it has been implemented. Thanks.
    It looks like I can pull down the tracklist from an AutoPlaylist, just using python and COM.
    So that would appear to address Q.4 also.

    It would help if the objects in your class were arranged in alphabetic order, ie not like this
Want a dark skin for MM5? This is the one that works best for me .. elegant, compact & clear.
drakinite
Posts: 909
Joined: Tue May 12, 2020 3:06 pm
Contact:

Re: Controlling MM5 from external applications

Post by drakinite »

Hi Barry,

I can currently respond to #2 and #3 easily:

2. Yeah, that "supported in MM5?" column was something I started back in 2020 but never finished. I think it's out of date anyways, after Ludek and Petr made some changes to COM to fix support for MonkeyMote. I might be able to go through that list more quickly now that I have access to the source code. (Beforehand, I was attempting to test each function manually, but now I can just browse the code and see which functions are empty & which are not.)

3. MM's integrated devtools (right click -> Inspect Element -> Console, or navigating to localhost:9222 in a web browser, or typing shift+alt+ctrl) is the easiest way to test JS functions. Syntax errors in code entered by hand in the JS console will not crash MM (but you still need to be careful about read/write locks in shared lists, those will still cause a crash)
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
drakinite
Posts: 909
Joined: Tue May 12, 2020 3:06 pm
Contact:

Re: Controlling MM5 from external applications

Post by drakinite »

Btw: If you're writing a new script, I'd recommend using HTTP requests instead of the COM API, because COM is only supported on Windows (which is the reason it's being deprecated, as we're working on a Mac port). There are two methods to do this: One is MM-specific (via a POST request to the Media Sharing port, see SampleScripts/remoteControl), and the other is through the MM devtools protocol: https://www.mediamonkey.com/forum/viewt ... 37#p447737 / https://www.mediamonkey.com/forum/viewt ... 55#p481255
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
Barry4679
Posts: 2198
Joined: Fri Sep 11, 2009 1:07 pm
Location: Australia
Contact:

Re: Controlling MM5 from external applications

Post by Barry4679 »

drakinite wrote: Mon Nov 21, 2022 11:06 pm I might be able to go through that list more quickly now that I have access to the source code. (Beforehand, I was attempting to test each function manually, but now I can just browse the code and see which functions are empty & which are not.)
They would do everybody a favour if they commented out "empty functions", ie. so that they were not visible in a COM browser ... especially since that is all we have got as documentation atm.
drakinite wrote: Mon Nov 21, 2022 11:06 pm 3. MM's integrated devtools (right click -> Inspect Element -> Console, or navigating to localhost:9222 in a web browser, or typing shift+alt+ctrl) is the easiest way to test JS functions. Syntax errors in code entered by hand in the JS console will not crash MM (but you still need to be careful about read/write locks in shared lists, those will still cause a crash)
OK, so if the call I want to test is
SDB.runJSCode("app.playlists.getByTitleAsync('Test Playlist').then(function(playlist) { if (!playlist) runJSCode_callback('Could not find playlist'); else playlist.getTracklist().whenLoaded().then(function (list) { runJSCode_callback(list.asJSON); }); });", True)
How do I test the vs component of that? ... Where does the vs component of start and end?
The following doesn't return your 'Could not find playlist string ... the return is "Promise {"_subscribers": Array(0)} ... meaning?
I get the same thing whether or not I provide a valid playlist name.
app.playlists.getByTitleAsync('xxxxx').then(function(playlist) { if (!playlist) runJSCode_callback('Could not find playlist'); else playlist.getTracklist().whenLoaded().then(function (list) { runJSCode_callback(list.asJSON); }); });
drakinite wrote: Mon Nov 21, 2022 11:31 pm Btw: If you're writing a new script, I'd recommend using HTTP requests instead of the COM API, because COM is only supported on Windows (which is the reason it's being deprecated, as we're working on a Mac port).
I don't know what "HTTP requests instead of the COM API" means.
You mean submitting js calls?

Thanks for the advice, but I don't know js, and am about overfilled with computer languages anyway.
I don't care too much about cross platform, and I don't have any Apple devices to test with.
I am running on Windows and Linux, and that is all that I can contend with.
Maybe I will regret some time around late 2028, when you are finished your Mac port :wink:

Re (my main) point #1 on my prior post, I will submit something for Mantis. MM5 should not hard crash due to what is probably just a syntax error in a submitted js call.
Barry4679 wrote: Sun Nov 20, 2022 9:59 am I wonder if I could contribute a sub-page to your effort, to contain a Python specific page to help anyone get started ? .... PM me through the forum if you like.

This is under consideration?
Want a dark skin for MM5? This is the one that works best for me .. elegant, compact & clear.
sonos
Posts: 140
Joined: Wed Aug 07, 2013 4:54 pm

Re: Controlling MM5 from external applications

Post by sonos »

drakenite wrote:
I think it's out of date anyways, after Ludek and Petr made some changes to COM to fix support for MonkeyMote.
I don't know any details about MonkeyMote. But after I installed MonkeyMote I noticed that the display in landscape mode on different iPad's differ.
So e.g. for iPad Air iOS 12.5.
Image
here are on the right side additional info (e.g. Artist, title) are displayed,
Now compare this with an iPadPro iOS 16
Image
here the additional info is missing.
I contacted the author of MonkeyMote, but even he has no real idea what the reason could be.

Could the changes draknite mentions be a reason?

Carsten
Barry4679
Posts: 2198
Joined: Fri Sep 11, 2009 1:07 pm
Location: Australia
Contact:

Re: Controlling MM5 from external applications

Post by Barry4679 »

This post has been moved.
It makes no sense here.
it belongs after this post in tts original thread.
sonos wrote: Sat Dec 03, 2022 5:25 pm
drakenite wrote:
I think it's out of date anyways, after Ludek and Petr made some changes to COM to fix support for MonkeyMote.
I don't know any details about MonkeyMote. But after I installed MonkeyMote I noticed that the display in landscape mode on different iPad's differ.
So e.g. for iPad Air iOS 12.5.
Image
here are on the right side additional info (e.g. Artist, title) are displayed,
Now compare this with an iPadPro iOS 16
Image
here the additional info is missing.
I contacted the author of MonkeyMote, but even he has no real idea what the reason could be.

Could the changes draknite mentions be a reason?

Carsten
Want a dark skin for MM5? This is the one that works best for me .. elegant, compact & clear.
Post Reply