View Issue Details

IDProjectCategoryView StatusLast Update
0006711MMW v4Framework: Scripts/Extensionspublic2011-02-12 23:39
Reporterzvezdan Assigned To 
PriorityhighSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version4.0 
Fixed in Version4.0 
Summary0006711: ISDBApplication::PlaylistByNode property needed
DescriptionAssuming that ISDBTreeNode is some node from Playlists branch, this property should return corresponding ISDBPlaylist object.
Additional Informationhttp://www.mediamonkey.com/forum/viewtopic.php?f=19&t=49442

I have several scripts where user could select some node from Playlists branch and choose some action from the menu which should be applied to the related Playlist object.

PlaylistByTitle property is almost useless because it cannot resolve problem with multiple playlists with same title. Worst of all, MM interface allows two or more playlists with same title on same node level within same parent. So, we want reliable scripts we need to use some complicated code to get the right playlist instead of PlaylistByTitle property, but it would be better if we have native property for that.

This is not duplicate of suggested PlaylistByID property which is something entirely different (honestly, I cannot see any use for such property).
TagsNo tags attached.
Fixed in build1346

Relationships

related to 0006405 closedpeke MMW Wishlist API to allow access to specific playlists 
related to 0006587 closedLudek MMW v4 Scripting: Implement ISDBApplication::PlaylistByID 
related to 0011299 closedLudek MMW v4 ISDBPlaylist::Delete doesn't remove node from the tree 

Activities

peke

2011-01-19 22:56

developer   ~0022468

Not sure that I completely Understand what you are asking for. Can you make small Pseudo example? Where you will show Difference from PlaylistByID

zvezdan

2011-01-19 23:45

updater   ~0022470

As I said, PlaylistByID is useless because you don't know playlist's ID for some specific node, but such situations are most needed, i.e. user has selected some node from the Playlists branch and choose some option from the script which should do something with the corresponding playlist of that node. So, here is a part of script which I am using to find Playlist object for the selected node:

        Set oCurNode = SDB.MainTree.CurrentNode
        Select Case oCurNode.NodeType
        Case 6
            Set oPlaylist = SDB.PlaylistByTitle("")
        Case 61, 71
            Set oSrcNode = oCurNode
            Do
                i = i + 1
                Set oChildNode = oSrcNode
                j = -1
                Do
                    Set oChildNode = SDB.MainTree.PreviousSiblingNode(oChildNode)
                    j = j + 1
                Loop Until oChildNode Is Nothing
                Redim Preserve aPlsIdx(i)
                aPlsIdx(i) = j
                Set oSrcNode = SDB.MainTree.ParentNode(oSrcNode)
            Loop Until oSrcNode.NodeType = 6
            Set oPlaylist = SDB.PlaylistByTitle("")
            For j = i To 0 Step -1
                Set oPlaylist = oPlaylist .ChildPlaylists.Item(aPlsIdx(j))
            Next
            If oPlaylist.Title <> oCurNode.Caption Then
                Set oPlaylist = Nothing
            End If
        Case Else
            Set oPlaylist = Nothing
        End Select

I want to replace these lines with the single one:
Set oPlaylist = SDB.PlaylistByNode(SDB.MainTree.CurrentNode)

Could you give me some example how/when PlaylistByID could be used at all?

peke

2011-01-20 02:28

developer   ~0022472

Last edited: 2011-01-20 03:04

I see your point and you are right, There is hole in scripting on how to get correct Object from Currently Selected Tree Node and I would not limit this just to Playlist Node but on any MM tree node (Please correct me if I missed something):
------
  Dim playlst
  Select Case SDB.MainTree.CurrentNode.NodeType
  Case 61, 71 ' http://www.mediamonkey.com/wiki/index.php/MediaMonkey_Tree_structure
    playlst = SDB.MainTree.CurrentNode.CustomObject
    'http://www.mediamonkey.com/wiki/index.php/ISDBTreeNode::CustomNodeId and
    'http://www.mediamonkey.com/wiki/index.php/ISDBTreeNode::CustomDataId are -1 and
    'according to NodeType ligically http://www.mediamonkey.com/wiki/index.php/ISDBTreeNode::CustomObject should
    'return http://www.mediamonkey.com/wiki/index.php/SDBPlaylist so that
    'http://www.mediamonkey.com/wiki/index.php/ISDBPlaylist::Title == SDB.MainTree.CurrentNode.Caption
    'for other nodes it should return correct Object (eg. Artist -> http://www.mediamonkey.com/wiki/index.php/SDBArtist)
    
  Case Else
    res = SDB.MessageBox( SDB.Localize("You must select Playlist!"), mtError, Array(mbOk))
  End Select
--------
Another example of same usage but to get Artist Name:
SDB.MainTree.Node_Artist_InCollection(1).CustomObject.Item(1).Name 'http://www.mediamonkey.com/wiki/index.php/SDBArtist::Name

--------
Re PlaylistByID Example of adding random track from chosen Playlist into NowPlaying:
Set pid = SDB.IniFile.intValue("TempPlaylist", "PlaylistID")
Set playlst = SDB.PlaylistByID(pid)
Randomize
Call SDB.Player.PlaylistAddTrack(playlst.tracks.item(Int((playlst.Tracks.Count+1) * Rnd)))

jiri

2011-01-20 09:08

administrator   ~0022480

Wouldn't it be better then to add a node property that would return ID of the related object (in this case Playlist, but could be others as well)?

zvezdan

2011-01-20 09:19

updater   ~0022483

RE Peke: I prefer a solution with the PlaylistByNode method which should return just playlist object, not any other object. If you take a look at my code, you would see that I have Case Else which covers all other nodes, not only those from Playlist branch, and for such nodes the returned object should be = Nothing. If I want to get the corresponding object of any node, e.g. SDBArtist when I have selected node from the Artist branch, such proposed method could not be called PlaylistByNode anymore, right? Even if you add some new method which could return the corresponding object depending of the node, let say it is called ObjectByNode, what about nodes which are not from Playlist/Artist/Album and similar tree branches? What object this method should return for nodes from the Location branch? Or some custom node, e.g. Magic Node? Also, I think that such solution could unnecessary complicate scripts: if all I want is to get the Playlist object, with your suggestion I need something like this:
        Set oCurNode = SDB.MainTree.CurrentNode
        Select Case oCurNode.NodeType
        Case 6, 61, 71
            Set oPlaylist = SDB.ObjectByNode(SDB.MainTree.CurrentNode)
        Case Else
            Set oPlaylist = Nothing
        End Select

It would be better if you implement both methods, and maybe some more, like ArtistByBranch, AlbumByNode, at least for those nodes for which we have the corresponding objects. For now we have only SDBPlaylist, SDBArtist, SDBAlbum and nothing more. Hm, maybe SDBDevice as well.

I have implemented the mentioned solution of yours with CustomObject in some of my scripts, but this solution could conflict with some another scripts and it is not elegant at all - whenever you add some playlist or even when you collapse/expand Playlists node (if I remember correctly) you need to update values for that property. I am using CustomNodeId and CustomDataId for another purposes anyway, so my solution for finding playlist object for specific node is more reliable.

RE PlaylistByID, you are right. From your example I could see that this method could be really useful. Maybe in that case you could add one more new method, say NodeByPlaylist, so we could programmatically select the corresponding node of playlist stored in ini file by its ID using something like this:
Set SDB.MainTree.CurrentNode = SDB.NodeByPlaylist(SDB.PlaylistByID(pid))

zvezdan

2011-01-20 09:23

updater   ~0022484

RE Jiri: Such solution would be great!

peke

2011-01-23 00:48

developer   ~0022537

@Zvezdan
1. You are right, it could complicate things rather than fix.

@Jiri
That would be best, but like Zvezdan pointed this should be bidirectional and scripted should be capable to possition MM tree to node according to its ID.
Although I think that there was script that will pos current Node on MM startup.

jiri

2011-01-25 09:35

administrator   ~0022601

Ludek, please make a property that would expose ID of the given object (i.e. Artist ID for artist nodes, Playlist ID for playlist nodes, ...).

Ludek

2011-01-27 22:13

developer   ~0022679

Fixed in build 1346:
http://www.mediamonkey.com/wiki/index.php/ISDBTreeNode::RelatedObjectID

peke

2011-02-12 23:39

developer   ~0023033

Verified 1348

Added Example Code To WIKI