Available COM interface

Post a reply

Visual Confirmation

To prevent automated access and spam, you are required to confirm that you are human. Please place a check mark next to all images of monkeys or apes. If you cannot see any images, please contact the Board Administrator.

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review
   

Expand view Topic review: Available COM interface

Re: Available COM interface

Post by Barry4679 » Fri Mar 30, 2018 10:09 pm

Thanks for the JSON string, and for the general advice re debugging COM calls.

I can now get going with some confidence.

PetrCBR wrote: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)


I would not have predicted that reading a value from an ini file would have been implemented as an async function ... nothing wrong with that of course, but in many cases one wouldn't want a program starting too much until the ini file had been validated.

Is there any way to predict, from the documentation, which calls have been implemented as async?

Re: Available COM interface

Post by PetrCBR » Fri Mar 30, 2018 5:13 am

Barry4679 wrote:While I am waiting would you mind posting an example JSON string from your List.asJSON callback in the above example code?

OK for example retrieve JSON string of short Now Playing list can look like:
Code: Select all
"{"_persistentID":"SharedList","objectType":"playlistentries", "data":[{"_persistentID":"153687","objectType":"playlistentry", {"_persistentID":"153686","objectType":"playlistentry"]}"


Barry4679 wrote:what type is SDB in that example? I don't see the runJSCode method documented here: http://www.mediamonkey.com/webhelp/MM5P ... s/App.html
I looked in App and DB, as I thought it may be there ..?


SDB is main COM object. Documentation you're pointing is MM5 API for JavaScript.

Barry4679 wrote:Which is the part that is not coming until 2089?

In 2090 we've introduced runJSCode_callback which is necessary when you need to return some value from async processing.

Barry4679 wrote:
Code: Select all
SDB.runJSCode("(function() { app.getIniFile().then(function(iniFileAccess) { iniFileAccess.getStringValue('System','DBName')   }); }); ()", True)

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)


Barry4679 wrote:I followed the advice from the sticky thread, and opened the Chromium Developer Tools console. ... It doesn't look like this is going to me much help when debugging something via COM ... ie. I see that I have an unexpected token, but I can't see inside any of the source modules, to see what token, and where. .. should I be able to see inside them? How do you recommend testing a COM called runJSCode function?

DevTools can help you when you need to debug code in JavaScript. When i need to run any JS code from COM, first create JS code and make it work and then move it to runJSCode method. In case i don't use any asynchronous operations i can use simply:
Code: Select all
SDB.runJSCode("(function() { ... anything NON async i need to do .... return result; })()", True)

When i need to do some async operations, return result using runJSCode_callback.

Re: Available COM interface

Post by Barry4679 » Fri Mar 30, 2018 4:32 am

Thanks for your assistance.

I sorry that I didn't read your posts carefully enough before. They were clear enough. It wasn't the answer that I was looking for, but now that I have slowed down, I now see that it seems a good solution to the COM facilties which will not be migrated to MM5.

Thanks for your patience with me.

A couple of questions while I wait for 2089

Code: Select all
Dim SDB : Set SDB = CreateObject("SongsDB5.SDBApplication")
Dim SLText : SLText = SDB.runJSCode("(function() { app.playlists.getByIDAsync(3).then(function(playlist) { playlist.getTracklist().whenLoaded().then(function (list) { runJSCode_callback(list.asJSON); }); }); })()", True)
Dim SL : Set SL = SDB.fromJSON(SLText)


While I am waiting would you mind posting an example JSON string from your List.asJSON callback in the above example code?

what type is SDB in that example? I don't see the runJSCode method documented here: http://www.mediamonkey.com/webhelp/MM5P ... s/App.html
I looked in App and DB, as I thought it may be there ..?

Which is the part that is not coming until 2089? .. is the callback facility? ... or the facility to string commands together (eg like you have playlist.getTracklist().whenLoaded() working on the output of app.playlists.getByIDAsync(3)) ? .... or is it both facilities that are coming with 2089?

I tried giving things a bit of a prod while I am waiting, to see how things work, and to sort out how I would debug it.

ie. I tried blindly following your example to see if I could get passed back a simple string

Code: Select all
SDB.runJSCode("(function() { app.getIniFile().then(function(iniFileAccess) { iniFileAccess.getStringValue('System','DBName')   }); }); ()", True)


It broke MM5, and returned just a blank unicode string.

I followed the advice from the sticky thread, and opened the Chromium Developer Tools console. ... It doesn't look like this is going to me much help when debugging something via COM ... ie. I see that I have an unexpected token, but I can't see inside any of the source modules, to see what token, and where. .. should I be able to see inside them?

How do you recommend testing a COM called runJSCode function?

If I coded the above fragment correctly, should I expect that a simple string, as output by getStringValue of type IniFileAccess, would be passed back through COM from my call to SDB.runJSCode? ... or do I need to do as you have done, and use JSON?

I seem to have generated a couple of dump files which got emailed back to MM ... do you want me to try and stop these being sent while i am testing my things?

Re: Available COM interface

Post by Barry4679 » Thu Mar 29, 2018 7:39 am

PetrCBR wrote:My code require 2090 or later and it was tested (it's using async result using runJSCode_callback and it was implemented in 2090).

OK. I will wait until 2090 is released.

Thanks for quick response.

Re: Available COM interface

Post by PetrCBR » Thu Mar 29, 2018 6:37 am

My code require 2090 or later and it was tested (it's using async result using runJSCode_callback and it was implemented in 2090).

Re: Available COM interface

Post by Barry4679 » Thu Mar 29, 2018 6:24 am

PetrCBR wrote:It was just example how to get tracks using COM as you've requested (example is in VBS as i'm not using python). I'm using PrimalScript for VBS, but it's paid application so try to look for any free app with ability to run VBS.


OK ... I see what you are saying now (I think)

Should the VBS sample snippet that you supplied execute without error?

I tried running it from Python, and I get an error.
I am wanting to make sure that I have the environment setup OK before trying to figure out javascript, and what I need there.

Code: Select all
    import win32com.client
    import pythoncom   
    SDB = win32com.client.Dispatch("SongsDB5.SDBApplication")
    x = SDB.runJScode("(function() { app.playlists.getByIDAsync(3).then(function(playlist) { playlist.getTracklist().whenLoaded().then(function (list) { runJSCode_callback(list.asJSON); }); }); })()", True)
 


I attach OK to "SongsDB5.SDBApplication", but the call to runJScode with your sample code causes MMV to crash.

see image https://www.dropbox.com/s/o36jk31l9wioarc/MMV%20js.png?dl=0

I am running 5.0.0.2089

Re: Available COM interface

Post by PetrCBR » Thu Mar 29, 2018 3:03 am

It was just example how to get tracks using COM as you've requested (example is in VBS as i'm not using python). I'm using PrimalScript for VBS, but it's paid application so try to look for any free app with ability to run VBS.

Re: Available COM interface

Post by Barry4679 » Thu Mar 29, 2018 2:22 am

PetrCBR wrote:Using that method you can run any JS code and as you can see from my example you can receive data as JSON string you can handle later in code. For new release (2090) i've added method runJSCode_callback so user can run more complex code and call this method to return value to COM model. For example i have playlist with ID 3 (predefined 'Accesible tracks' playlist) and i want to retrive his tracklist:
Code: Select all
Dim SDB : Set SDB = CreateObject("SongsDB5.SDBApplication")
Dim SLText : SLText = SDB.runJSCode("(function() { app.playlists.getByIDAsync(3).then(function(playlist) { playlist.getTracklist().whenLoaded().then(function (list) { runJSCode_callback(list.asJSON); }); }); })()", True)
Dim SL : Set SL = SDB.fromJSON(SLText)


I have just noticed your response to my query. Thanks.

I am struggling to see how to get started

recap: I am trying to get the list of tracks currently returned from an autoplaylist
recap: I asked in December if MM5 was going to support some COM members from SDBPlayList
recap: I work in Python ... you said that these new JS command could return a JSON string which I could parse

I can probably work out how to use JS ... but I don't know to run|test it

I read viewtopic.php?f=27&t=81285

I scanned MM5 directories for the string "runJSCode" but see nothing ... I can't even find anything with "CreateObject("SongsDB5.SDBApplication")"

I can't scan the contents of MediaMonkey 5\SampleScripts because the compile or encrypted to .mmip format (I double clicked one to see if it could be installed on one and got "Invalid Product Installation Package")

Can you, or someone, explain how|where i install the sample code that you posted, so that I can get started.

Thanks

Re: Available COM interface

Post by PetrCBR » Thu Feb 22, 2018 10:34 am

Barry4679 wrote:? "SDB.fromJSON (currently just SongList is supported)" ... I am not sure what this means? .. I will be able to get the tracklist of an autoplaylist?

SDB.fromJSON method currently can convert from JSON string to objects just SongList and SongListData (other objects like Album is not supported).
Barry4679 wrote:? what language was his code example? ... I guessed Visual Basic ... or was it JS? ... I was meaing did he have a code sample (in that language) which obtained the contents of a specific autoplaylist

Yes it was Visual Basic with JS running using runJSCode method. Using that method you can run any JS code and as you can see from my example you can receive data as JSON string you can handle later in code. For new release (2090) i've added method runJSCode_callback so user can run more complex code and call this method to return value to COM model. For example i have playlist with ID 3 (predefined 'Accesible tracks' playlist) and i want to retrive his tracklist:
Code: Select all
Dim SDB : Set SDB = CreateObject("SongsDB5.SDBApplication")
Dim SLText : SLText = SDB.runJSCode("(function() { app.playlists.getByIDAsync(3).then(function(playlist) { playlist.getTracklist().whenLoaded().then(function (list) { runJSCode_callback(list.asJSON); }); }); })()", True)
Dim SL : Set SL = SDB.fromJSON(SLText)

Barry4679 wrote:? the new method is available in 2088, or the next build?

It should be available in current beta (2089), but runJSCode_callback will be introduced in 2090.

Re: Available COM interface

Post by Barry4679 » Wed Jan 17, 2018 9:00 pm

Thanks for responses.

To clarify. I have no trouble using Mediamonkey|COM|Python.

I was requesting that you add (at least part of) SDBPlayList to your COM implementation plans for MM5.

Use Case: The contents of a static playlist may be obtained by a simple ExecSQL, but a autoplaylist would require reverse engineering in MM5 to get exactly the same track inclusion criteria and sort sequence.

I made several suggestions:
* implement the readonly members from SDBPlayList, and PlayListByTitle & PlayListByID from SDBApplication
* or provide a COM method to populate a named static playlist with the current contents of a named autoplaylist
* or a COM method to return the sql criteria for a named static playlist
* or anything that you may suggest

PetrCBR responded with a comment about a new method SDB.fromJSON

? "SDB.fromJSON (currently just SongList is supported)" ... I am not sure what this means? .. I will be able to get the tracklist of an autoplaylist?
? what language was his code example? ... I guessed Visual Basic ... or was it JS? ... I was meaing did he have a code sample (in that language) which obtained the contents of a specific autoplaylist
? the new method is available in 2088, or the next build?

Apologies if my question was worded poorly and caused confusion.

Re: Available COM interface

Post by jiri » Wed Jan 17, 2018 4:30 am

Hi Barry,

I also haven't tried to work with MM COM from Python, but I suppose that it shouldn't be much different than the sample code above, i.e. if you already have the SDBApplication object, you only need to get the tracklist through the generic runJSCode() function and then convert it to a MM COM API object using fromJSON().

Jiri

Re: Available COM interface

Post by PetrCBR » Mon Jan 15, 2018 2:28 am

Sorry, but i''ve used python in linux only (just for basic things).

Re: Available COM interface

Post by Barry4679 » Sun Jan 14, 2018 7:11 pm

PetrCBR wrote:Using code i've sent you can receive any tracklist to your COM.


Sorry, I thought it was a general announcement, and not something in response to my request. ... thanks.

I am programming using Python. ... I don't know Javascript, nor VB ... but I can investigate ... you do expect that this facility will be available to me from Python?

PetrCBR wrote:In next build new method will be implemented


Still a future build? ... or is available in the now current build?

PetrCBR wrote:SDB.fromJSON (currently just SongList is supported). In JS we have asJSON property implemented for all of our classes so using SDB.runJSCode you can run any JS code from COM model and return object(s) exported as JSON string.


I can get the contents of an autoplaylist somehow via SongList? ... or do you plan to add SDBPlayList later?

PetrCBR wrote:Simple example of getting current now playing tracklist using runJSCode and convert it to SongList object:
Code: Select all
...


You wouldn't happen to have a "simple example" initiating this from Python? ... and maybe also getting the contents from an autoplaylist? :roll:

I have an app which does some things with MM static playlists ... I have requests to also extend support to MM autoplaylists ... I can do so with MM4, but don't really want to offer this if it will be broken by MM5, and I have no way to fix it.

Re: Available COM interface

Post by PetrCBR » Sun Jan 14, 2018 5:37 am

Using code i've sent you can receive any tracklist to your COM.

Re: Available COM interface

Post by Barry4679 » Sat Jan 13, 2018 10:50 pm

Ludek wrote: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.


Has there been any decision on this request?

I see the following post by PetrCBR. That post doesn't relate to this request does it?

Top

cron