Code: Select all
Dim SDB : Set SDB = CreateObject("SongsDB5.SDBApplication")
Dim SLText : SLText = SDB.runJSCode("(function() { return app.player.getSongList().getTracklist().asJSON; })()", True)
Dim SL : Set SL = SDB.fromJSON(SLText)
Moderators: jiri, drakinite, Addon Administrators
Code: Select all
Dim SDB : Set SDB = CreateObject("SongsDB5.SDBApplication")
Dim SLText : SLText = SDB.runJSCode("(function() { return app.player.getSongList().getTracklist().asJSON; })()", True)
Dim SL : Set SL = SDB.fromJSON(SLText)
Has there been any decision on this request?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.
Sorry, I thought it was a general announcement, and not something in response to my request. ... thanks.PetrCBR wrote:Using code i've sent you can receive any tracklist to your COM.
Still a future build? ... or is available in the now current build?PetrCBR wrote:In next build new method will be implemented
I can get the contents of an autoplaylist somehow via SongList? ... or do you plan to add SDBPlayList later?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.
You wouldn't happen to have a "simple example" initiating this from Python? ... and maybe also getting the contents from an autoplaylist?PetrCBR wrote:Simple example of getting current now playing tracklist using runJSCode and convert it to SongList object:Code: Select all
...
SDB.fromJSON method currently can convert from JSON string to objects just SongList and SongListData (other objects like Album is not supported).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?
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: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
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)
It should be available in current beta (2089), but runJSCode_callback will be introduced in 2090.Barry4679 wrote: ? the new method is available in 2088, or the next build?
I have just noticed your response to my query. Thanks.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)
OK ... I see what you are saying now (I think)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.
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)
OK. I will wait until 2090 is released.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).
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)
Code: Select all
SDB.runJSCode("(function() { app.getIniFile().then(function(iniFileAccess) { iniFileAccess.getStringValue('System','DBName') }); }); ()", True)
OK for example retrieve JSON string of short Now Playing list can look like:Barry4679 wrote:While I am waiting would you mind posting an example JSON string from your List.asJSON callback in the above example code?
Code: Select all
"{"_persistentID":"SharedList","objectType":"playlistentries", "data":[{"_persistentID":"153687","objectType":"playlistentry", {"_persistentID":"153686","objectType":"playlistentry"]}"
SDB is main COM object. Documentation you're pointing is MM5 API for JavaScript.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 ..?
In 2090 we've introduced runJSCode_callback which is necessary when you need to return some value from async processing.Barry4679 wrote:Which is the part that is not coming until 2089?
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).Barry4679 wrote:Code: Select all
SDB.runJSCode("(function() { app.getIniFile().then(function(iniFileAccess) { iniFileAccess.getStringValue('System','DBName') }); })()", True)
Code: Select all
SDB.runJSCode("(function() { app.getIniFile().then(function(iniFileAccess) { runJSCode_callback(iniFileAccess.getStringValue('System','DBName')) }); })()", True)
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: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?
Code: Select all
SDB.runJSCode("(function() { ... anything NON async i need to do .... return result; })()", True)