Difference between revisions of "ISDBApplication::PlaylistByTitle"

From MediaMonkey Wiki
Jump to: navigation, search
 
(Added example for not returning root node when playlist is not found)
 
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  
 
{{MethodParameters  
 
{{MethodParameters  
  |Title |String |Name of the playlist to get (use "" to get root of all playlists)}}
+
  |Title |String |Name of the playlist to get (use empty string to get root of all playlists)}}
  
 
===Property description===
 
===Property description===
  
Retrieves [[SDBPlaylist]] object of the given playlist name. Probably most often used parameter is an empty string, the root (virtual) playlist node is returned then, you can use its ChildPlaylists property to get all the first level playlists.
+
Retrieves [[SDBPlaylist]] object of the given playlist name. If multiple playlists with the same name exist, ''PlaylistByTitle'' returns the first one it finds in the database.
  
===Example code===                   
+
Call method with empty string as the argument to get the (virtual) root playlist node. Then you can use its [[ISDBPlaylist::ChildPlaylists|ChildPlaylists]] property to get all the first-level playlists.
<source lang="vb">Set Playlist = SDB.PlaylistByTitle( "")
 
Set list = Playlist.ChildPlaylists
 
  
For i=0 To list.count-1
+
'''WARNING:''' Also if no playlist with the specified ''Title'' exists, the (virtual) root playlist will be returned. Be aware of this fact, especially if you are planning to remove a playlist. Making an error could remove the root, and so all playlists.
   Set itm = list.Item(i)
+
 
   fout.WriteLine itm.Title &amp; " (" &amp; CStr(itm.ChildPlaylists.Count) &amp; "/" &amp; CStr( itm.Tracks.Count) &amp; ")"
+
===Example code===   
Next</source>
+
<source lang="vb">
 +
' Safe PlaylistByTitle wrapper - returns Nothing when playlist with given Title is not found
 +
Sub SafePlaylistByTitle(Title)
 +
  Dim RootList : Set RootList = SDB.PlaylistByTitle("") ' Get root node
 +
  SafePlaylistByTitle = SDB.PlaylistByTitle(Title) ' Get playlist by Title
 +
  If SafePlaylistByTitle Is RootList Then
 +
    SafePlaylistByTitle = Nothing ' Do not return playlist when nothing was found
 +
  End If
 +
End Sub
 +
</source>
 +
           
 +
Example for playlist nodes iteration:
 +
             
 +
<source lang="vb">Dim Playlist : Set Playlist = SDB.PlaylistByTitle("")  ' Playlist represents the root (virtual) playlist
 +
Dim List : Set List = Playlist.ChildPlaylists          ' List represents a list of all first-level playlists
 +
 
 +
Dim i, itm
 +
 
 +
For i = 0 To List.Count - 1                             ' For all (first-level) playlists in List...
 +
   Set itm = List.Item(i)                               ' ... print out the number of child playlists and tracks
 +
   fout.WriteLine itm.Title & " (" & CStr(itm.ChildPlaylists.Count) & "/" & CStr(itm.Tracks.Count) & ")"
 +
Next
 +
 
 +
' in this case, fout represents a TextStream object (not shown here)</source>
 +
 
 +
===Related Topics===
 +
* [[ISDBApplication::PlaylistByID]]
  
 
[[Category:Scripting|{{PAGENAME}}]]
 
[[Category:Scripting|{{PAGENAME}}]]

Latest revision as of 20:14, 20 April 2013

CoClass SDBApplication, Interface ISDBApplication

Property Get PlaylistByTitle(Title As String) As ISDBPlaylist


Parameters

Name Type Description
Title String Name of the playlist to get (use empty string to get root of all playlists)


Property description

Retrieves SDBPlaylist object of the given playlist name. If multiple playlists with the same name exist, PlaylistByTitle returns the first one it finds in the database.

Call method with empty string as the argument to get the (virtual) root playlist node. Then you can use its ChildPlaylists property to get all the first-level playlists.

WARNING: Also if no playlist with the specified Title exists, the (virtual) root playlist will be returned. Be aware of this fact, especially if you are planning to remove a playlist. Making an error could remove the root, and so all playlists.

Example code

' Safe PlaylistByTitle wrapper - returns Nothing when playlist with given Title is not found
Sub SafePlaylistByTitle(Title)
  Dim RootList : Set RootList = SDB.PlaylistByTitle("") ' Get root node
  SafePlaylistByTitle = SDB.PlaylistByTitle(Title) ' Get playlist by Title
  If SafePlaylistByTitle Is RootList Then
    SafePlaylistByTitle = Nothing ' Do not return playlist when nothing was found
  End If
End Sub

Example for playlist nodes iteration:

Dim Playlist : Set Playlist = SDB.PlaylistByTitle("")   ' Playlist represents the root (virtual) playlist
Dim List : Set List = Playlist.ChildPlaylists           ' List represents a list of all first-level playlists

Dim i, itm

For i = 0 To List.Count - 1                             ' For all (first-level) playlists in List...
  Set itm = List.Item(i)                                ' ... print out the number of child playlists and tracks
  fout.WriteLine itm.Title & " (" & CStr(itm.ChildPlaylists.Count) & "/" & CStr(itm.Tracks.Count) & ")"
Next

' in this case, fout represents a TextStream object (not shown here)

Related Topics