Track exists in playlist - best method ?

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

Track exists in playlist - best method ?

Postby raybeau528 » Mon Feb 23, 2009 10:39 am

What would be the best method to determine, via a script, if a track exists in a playlist?

I certainly could loop through all tracks and check for matching song.id. Not heavy processing if I'm checking for 1 track in 1000. Checking for 1000 tracks in a 10,000 track playlist could result in a million cycles!

Does the AddTrackbyID(ID) method return any indication whether the track ID already exists in the playlist?

The Properties editor / Classification lists the playlists for which the selected song is a member. Is there a scripting property/method to access that?

Thanks!

Ray
raybeau528
 
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Track exists in playlist - best method ?

Postby ZvezdanD » Mon Feb 23, 2009 11:00 am

raybeau528 wrote:What would be the best method to determine, via a script, if a track exists in a playlist?

I haven't tried, but you could try something like this:
Code: Select all
If SDB.Database.OpenSQL("SELECT * FROM PlaylistSongs, Playlists WHERE PlaylistSongs.IDSong = " & iSongDataID & " AND PlaylistSongs.IDPlaylist = Playlists.IDPlaylist AND Playlists.PlaylistName = '" & sPlaylistName & "'").EOF Then
Magic Nodes 4.2 (2011-07-01) RegExp Find & Replace 4.3 (2011-07-06)  Invert Selection/Select None 1.5 (2012-02-04)  Export M3Us/Create Playlists for Child Nodes 3.6.1 (2012-01-09)  Expand Child Nodes/Expand All 1.1.1 (2012-02-13)  Event Logger 2.4.1 (2012-02-06)  Filtered Statistics Report 1.5.1 (2009-10-09)  Track Redirection & Synchronization 3.4 (2012-10-08)  Restore/Synchronize Database 3.1.1 (2012-05-31)  Find Currently Playing Track 1.2 (2012-02-14)  Queue List 1.2 (2012-02-06)  Add to Library on Play 1.0 (2010-10-20)  Tree Report for Child Nodes 1.1 (2010-11-04)  Update Location of Files in Database 1.3.3 (2012-06-12)  Inherit Child Playlists 1.0 (2012-01-16)
Add Currently Playing/Selected Track(s) to Playlist 1.1.1 (2012-02-06)
ZvezdanD
 
Posts: 2589
Joined: Thu Jun 08, 2006 7:40 pm

Re: Track exists in playlist - best method ?

Postby raybeau528 » Mon Feb 23, 2009 11:05 am

Thanks for the super quick response!!! I'll give it a try.

Ray
raybeau528
 
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Track exists in playlist - best method ?

Postby ZvezdanD » Mon Feb 23, 2009 11:19 am

It could be even shorter if you know playlist's ID:
Code: Select all
If SDB.Database.OpenSQL("SELECT * FROM PlaylistSongs WHERE PlaylistSongs.IDSong = " & iSongDataID & " AND PlaylistSongs.IDPlaylist = " & iPlaylistID).EOF Then
Magic Nodes 4.2 (2011-07-01) RegExp Find & Replace 4.3 (2011-07-06)  Invert Selection/Select None 1.5 (2012-02-04)  Export M3Us/Create Playlists for Child Nodes 3.6.1 (2012-01-09)  Expand Child Nodes/Expand All 1.1.1 (2012-02-13)  Event Logger 2.4.1 (2012-02-06)  Filtered Statistics Report 1.5.1 (2009-10-09)  Track Redirection & Synchronization 3.4 (2012-10-08)  Restore/Synchronize Database 3.1.1 (2012-05-31)  Find Currently Playing Track 1.2 (2012-02-14)  Queue List 1.2 (2012-02-06)  Add to Library on Play 1.0 (2010-10-20)  Tree Report for Child Nodes 1.1 (2010-11-04)  Update Location of Files in Database 1.3.3 (2012-06-12)  Inherit Child Playlists 1.0 (2012-01-16)
Add Currently Playing/Selected Track(s) to Playlist 1.1.1 (2012-02-06)
ZvezdanD
 
Posts: 2589
Joined: Thu Jun 08, 2006 7:40 pm

Re: Track exists in playlist - best method ?

Postby raybeau528 » Mon Feb 23, 2009 11:23 am

ZvezdanD,

I tried this:

Code: Select all
Sub TrackinPlaylist(arg)
   dim isongdataid : iSongDataID = 6431
   dim sPlaylistName : sPlaylistName = "Test"

   If SDB.Database.OpenSQL("SELECT * FROM PlaylistSongs, Playlists WHERE PlaylistSongs.IDSong = " & iSongDataID & " AND PlaylistSongs.IDPlaylist = Playlists.IDPlaylist AND Playlists.PlaylistName = '" & sPlaylistName & "'").EOF Then
      msgbox("In Playlist")
   else
      msgbox("Not in Playlist")
   End If

End Sub


I created a playlist named "Test". I copied the song.id's to custom1 so I could see them and verified that one track song.id was 6431. I hard coded them for a quick test. Result was NOT in playlist. I don't know sql but those look like the only variables.

Ray
raybeau528
 
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Track exists in playlist - best method ?

Postby raybeau528 » Mon Feb 23, 2009 11:24 am

I can get the playlist ID . I'll try that next but it will be later today. Thanks for your expert help!

Ray
raybeau528
 
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Track exists in playlist - best method ?

Postby ZvezdanD » Mon Feb 23, 2009 11:45 am

raybeau528 wrote:Result was NOT in playlist.

Well, if EOF is True that mean the recordset is empty, so you should switch MsgBox-es after Then and Else or put Not after If.
Magic Nodes 4.2 (2011-07-01) RegExp Find & Replace 4.3 (2011-07-06)  Invert Selection/Select None 1.5 (2012-02-04)  Export M3Us/Create Playlists for Child Nodes 3.6.1 (2012-01-09)  Expand Child Nodes/Expand All 1.1.1 (2012-02-13)  Event Logger 2.4.1 (2012-02-06)  Filtered Statistics Report 1.5.1 (2009-10-09)  Track Redirection & Synchronization 3.4 (2012-10-08)  Restore/Synchronize Database 3.1.1 (2012-05-31)  Find Currently Playing Track 1.2 (2012-02-14)  Queue List 1.2 (2012-02-06)  Add to Library on Play 1.0 (2010-10-20)  Tree Report for Child Nodes 1.1 (2010-11-04)  Update Location of Files in Database 1.3.3 (2012-06-12)  Inherit Child Playlists 1.0 (2012-01-16)
Add Currently Playing/Selected Track(s) to Playlist 1.1.1 (2012-02-06)
ZvezdanD
 
Posts: 2589
Joined: Thu Jun 08, 2006 7:40 pm

Re: Track exists in playlist - best method ?

Postby ZvezdanD » Mon Feb 23, 2009 12:02 pm

By the way, if you want to check if all 1000 tracks belong to same playlist, I suppose that it is faster to check this with a single SQL query, instead of one SQL query for each track. Here is an example:
Code: Select all
' sSongDataIDArray = "1234, 1235, ..., 9999"

If Not SDB.Database.OpenSQL("SELECT * FROM PlaylistSongs WHERE PlaylistSongs.IDSong IN (" & sSongDataIDArray & ") AND PlaylistSongs.IDPlaylist = " & iPlaylistID).EOF Then
Magic Nodes 4.2 (2011-07-01) RegExp Find & Replace 4.3 (2011-07-06)  Invert Selection/Select None 1.5 (2012-02-04)  Export M3Us/Create Playlists for Child Nodes 3.6.1 (2012-01-09)  Expand Child Nodes/Expand All 1.1.1 (2012-02-13)  Event Logger 2.4.1 (2012-02-06)  Filtered Statistics Report 1.5.1 (2009-10-09)  Track Redirection & Synchronization 3.4 (2012-10-08)  Restore/Synchronize Database 3.1.1 (2012-05-31)  Find Currently Playing Track 1.2 (2012-02-14)  Queue List 1.2 (2012-02-06)  Add to Library on Play 1.0 (2010-10-20)  Tree Report for Child Nodes 1.1 (2010-11-04)  Update Location of Files in Database 1.3.3 (2012-06-12)  Inherit Child Playlists 1.0 (2012-01-16)
Add Currently Playing/Selected Track(s) to Playlist 1.1.1 (2012-02-06)
ZvezdanD
 
Posts: 2589
Joined: Thu Jun 08, 2006 7:40 pm

Re: Track exists in playlist - best method ?

Postby raybeau528 » Mon Feb 23, 2009 8:22 pm

Thanks ZvezdanD ! All 3 methods worked perfectly!

Ray
raybeau528
 
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut


Return to Addons developer forum

Who is online

Users browsing this forum: No registered users and 0 guests